如何确定 OpenJPA 中 FetchBatchSize 的数量?
OpenJPA 在 FetchPlan 中提供了一些参数。 (http://openjpa.apache.org/builds/1.2.0/apidocs/org/apache/openjpa/persistence/FetchPlan.html) 我被困在其中之一,FetchBatchSize。 希望好心人能分享一下他们的经验。
这是场景,假设我要从数据库中选择最多 1000 条记录(MS-SQL) 1. 如果我将 FetchBatchSize 保留为其默认值 -1,则返回 1000 条记录将需要大约 20 秒;
如果我将 FetchBatchSize 设置为 100,时间成本会显着降低到不到 2 秒,这很好,但如果我尝试仅获取 50 条记录(小于 FetchBatchSize 100),则需要花费更长的时间(在我的测试中为 50 秒),这是不可接受的。
好吧,所以,我猜如果 FetchBatchSize 超过了用户想要的数量,就会花费更多的时间。我可以根据用户设置的计数在运行时更改 FetchBatchSize。你想要1000,我设置FetchBatchSize为1000,你想要100,我设置为50,但是如果用户只需要几条记录怎么办?我也将 FetchBatchSize 设置为 2 之类的?
所以我的问题是,当 maxResultCount 可变时如何选择合适的 FetchBatchSize? openJPA 文档中是否有适合大多数场景的默认值(例如 20)?或者建议在运行时更改它。
任何评论表示赞赏。谢谢!
OpenJPA provided some parameter in the FetchPlan.
(http://openjpa.apache.org/builds/1.2.0/apidocs/org/apache/openjpa/persistence/FetchPlan.html)
And I was stuck in one of them, the FetchBatchSize.
Hope someone can kindly share their experience.
Here is the scenario, say I was going select up to 1000 record from the database(MS-SQL)
1. if I left FetchBatchSize to its default value -1, it will take some 20 seconds to return the 1000 records;
if I set the FetchBatchSize to 100, the time cost was reduced, dramatically, to less than 2 seconds, that's good, but if I try to get only 50 records, which is less than the FetchBatchSize 100, it will take a much longer time (50 seconds in my test) which is not acceptable.
ok, so, I guess if the FetchBatchSize exceeds the number user wanted, it will take more time. I could change the FetchBatchSize in runtime, in accordance to the count set by user. you want 1000, I set FetchBatchSize to 1000, you want 100, I set it to 50, but what if the user only needs a few records? I too set the FetchBatchSize to some like 2?
So my question is, how to select a proper FetchBatchSize when the maxResultCount is variable? if there any DEFAULT value, like 20, in the openJPA document that will suitable for most scenario? Or it is recommended to change it at runtime.
Any comment is appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上更像是一个 MS-SQL 调优问题,而不是 OpenJPA 问题 —— FetchBatchSize 值被传递给驱动程序。
在运行时根据最大结果计数参数动态设置该值当然没有任何问题。另外,假设您在指定大于 limit 子句的数字时遇到的延迟不是由于某些模糊的配置引起的,那么向 OpenJPA SQLServerDictionary 添加一些内容以在最大结果值时限制批处理大小会很有趣。存在。在 OpenJPA 邮件列表中提出可能是一件好事。
This is actually more of a MS-SQL tuning question than an OpenJPA question -- the FetchBatchSize value is passed along to the driver.
There's certainly nothing wrong with setting the value dynamically at runtime based on the max result count parameter. Also, assuming that the delay that you experienced when specifying a number greater than the limit clause is not due to some obscure bit of configuration, it'd be interesting to add something to the OpenJPA SQLServerDictionary to cap the batch size when a max result value is present. Might be a good thing to bring up on the OpenJPA mailing list.