如何Hibernate的批量提取算法的工作? [英] How does Hibernate's batch-fetching algorithm work?

查看:139
本文介绍了如何Hibernate的批量提取算法的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,在批量提取算法的描述曼宁 - Java持久性与休眠:

I found this description of the batch-fetching algorithm in "Manning - Java Persistence with Hibernate":

什么是真正的批量抓取   算法? (......)想象的批量大小   20和119的总数量   这必须是未初始化的代理   批量加载。在启动时,   Hibernate的读取映射元数据   并创建11批次装载机   内部。每个装载机知道有多少   代理可以初始化:20,10,09   8,7,6,5,4,3,2,1的目标是   最大限度地减少内存消耗   装载机创作和创造足够的   装载机,每一个可能的批   取可以生产。另一个目标是   最小化的SQL的数   选用,效果显着。要初始化119   代理Hibernate的执行7   批(你可能预计六,   因为6×20> 119)。批处理   所应用的装载机五个   次20,一时间10,以及一个时间9,   由Hibernate自动选择。

What is the real batch-fetching algorithm? (...) Imagine a batch size of 20 and a total number of 119 uninitialized proxies that have to be loaded in batches. At startup time, Hibernate reads the mapping metadata and creates 11 batch loaders internally. Each loader knows how many proxies it can initialize: 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1. The goal is to minimize the memory consumption for loader creation and to create enough loaders that every possible batch fetch can be produced. Another goal is to minimize the number of SQL SELECTs, obviously. To initialize 119 proxies Hibernate executes seven batches (you probably expected six, because 6 x 20 > 119). The batch loaders that are applied are five times 20, one time 10, and one time 9, automatically selected by Hibernate.

但我还是不明白它是如何工作的。

but I still don't understand how it works.

  1. 为什么11批次装载机?
  2. 为什么批量装载机可以初始化:20,10,9,8,7,6,5,4,3,2,1代理

如果有人可以present一步步算法...:)

If anybody could present a step by step algorithm ... :)

推荐答案

我找不到有关如何休眠处理批量加载在网络上的任何信息,但是从你的信息来看,人们可以猜到如下:

I couldn't find any information on the web about how hibernate handles batch loading, but judging from your information, one could guess the following:

为什么11批次装载机?

随着20的批量大小,如果你想尽量减少所需的装载机数量任何代理相结合的,大致有两种选择:

With a batch size of 20, if you want to minimize the number of loaders required for any combination of proxies, there are basically two options:

  • 创建一个装载机1,2,3,4,5,6,7,...... 20,21,22,23,... N未初始化的代理(愚蠢!)或者
  • 创建一个装载机任意n 1..9之间,然后创建一个的batch_size / 2 详细装载机(递归)
  • create a loader for 1,2,3,4,5,6,7,...20,21,22,23,... N uninitialized proxies (stupid!) OR
  • create a loader for any N between 1..9 and then create more loaders for batch_size/2(recursively)

例如:对于批量大小40,你最终会与装载机40,20,10,9,8,7,6,5,4,3,2,1装载机

Example: for batch size 40, you would end up with loaders for 40,20,10,9,8,7,6,5,4,3,2,1 loaders.

  1. 如果您有33初始化代理,您可以使用以下装载机:20,10,3
  2. 如果你有119未初始化的代理,你可以使用下面的装载机,40(X2),20,10,9
  3. ...

为什么批量装载机可以初始化:20,10,9,8,7,6,5,4,3,2,1代理 我觉得休眠团队选择了这个要求加载未初始化的代理和内存消耗的共同数N装载机的数量之间的平衡。该会已经创建了一个装载机每N 0和的batch_size 之间,但我怀疑,装载机有相当大的内存占用的所以这是一个折衷 。该算法的可以是这样的(猜测):

Why batch loaders can initialize: 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 proxies ? I think the hibernate team chose this as a balance between the number of loaders required for loading a "common" number N of uninitialized proxies and memory consumption. The could have created a loader for every N between 0 and batch_size, but I suspect that the loaders have a considerable memory footprint so this is a tradeoff. The algorithm can be something like this (educated guess):

  1. N =的batch_size;而(N大于10)

1.1。 装载机(N); N = N / 2

对于n = 0..10创建装载机(N)

这篇关于如何Hibernate的批量提取算法的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆