When using nhibernate, how do I determine the optimal batch size in the display code?

I am using nhibernate and I have code similar to this in the display area:

HasMany(x => x.People).AsBag().Inverse().Cascade.AllDeleteOrphan().Fetch.Select().BatchSize(80); HasMany(x => x.Clothes).AsBag().Inverse().Cascade.AllDeleteOrphan().Fetch.Select().BatchSize(150); 

My question is, how do I figure out what is the best value to use .BatchSize? Should I just put a large number. Is there a drawback to put a number too high?

+7
source share
3 answers

There is no answer to this question.

The only way to determine what works best is to profile the application in production , while real users do the real thing. This is time consuming, so you are likely to do something only if you find that the application is slow.

The risk of too many is that a query with many parameters that receive a range of records for each of them can be more complicated in the database than several smaller queries.

In addition, if you do not use all the collections that you referenced (for example, if you received a list of PostCategories, but you only show messages for one of them), you can load a lot of data without the need.

My advice is to start with something like 20 or 50 (*) and make it higher only if you often have more than twice as much as the number of collections being downloaded at the same time.

(*): yes, I took these numbers off my butt. 50 is what I use by default.

+5
source

Although it's quite old, there is a record in Ayende where it compares different lot sizes (believe 10, 25, 250). Check this. This may be helpful for you.

+2
source

I usually set batch-size to the same value as the page size in the GUI.

So, if my page size is 25, my batch size. I have no evidence that this is a good choice, but if only it feels right to me.

However, the only sure way is to follow what @Diego wrote, run the profiler on a real server for a week, and analyze the results. Change the batch run for one more week by analyzing both results. A lot of work I suspect!

I would not recommend a high level of value, as this can have a negative impact. Another way to look at this is if your package size is high, then you can return to many entries in the select clause first.

+1
source

All Articles