fix #341. Limit the amount of memory taken by query

Remove the setting for shard query buffer size and add logic for max
number of shards to query in parallel.
refactoring to make the code clear and simple