This wallet is used for withdrawing, as the number of withdraws increases, the num_unspent_outputs decreases to 1 in the end. This will cause the wallet to lock its whole balance for each transfer, which is very much undesirable. Why is this? I suspect the wallet is spending outputs in ascending order, that is spend smaller outputs first, so in the end, it will group all the balance into one output. Is there any setting to change this?
The monero wallet will try to use two inputs to each transaction, in an attempt to have most transactions look like each other (two inputs, and two outputs). Since in a typical transaction you will get one output back as change, it means that you spend two outputs, and get one in return (the second output going to whoever you're paying). Thus, over time, you will coalesce your own outputs, which leads to the problem you're describing.
There are two settings in
monero-wallet-cli which can control this and avoid coalescing outputs down to too few:
min-outputs-value. They're viewable and settable using the
set command: just running
set will show all settings, including those.
Those settings control when a second output will be added onto your transactions when it is not necessary (ie, when it's just in an attempt to make your transaction look like a typical 2 -> 2 transaction).
monero-wallet-cli will only include such an output if it wouldn't cause the wallet to have less than
min-outputs-count outputs of value at least
min-outputs-value monero. Of course, if using two or more of your outputs if necessary to meet the payment+fee amount, this will be done regardless.
For example, you can run:
set min-outputs-count 5
set min-outputs-value 1
This will cause
monero-wallet-cli to try to use only one input for a transaction once you have only 5 outputs left over 1 monero.