前言
Elasticserach分析之前先了解一個(gè)配置:indices.fielddata.cache.size = 30%? 這個(gè)配置的作用是沮峡,如果對一個(gè)字段進(jìn)行排序或者做聚合操作逗抑,那么
就會將這個(gè)字段的所有數(shù)據(jù)都加載到內(nèi)存當(dāng)中羡洛,為了加快排序速度。如果配置過于大,會導(dǎo)致jvm內(nèi)存不夠使用而崩潰。所以ES又提供了兩個(gè)配置:
indices.breaker.fielddata.limit = 60% 和 indices.breaker.fielddata.overhead=1.03 來限制消痛,防止jvm內(nèi)存溢出。
indicesServices分析
1:dostart方法:啟動調(diào)度器都哭,定時(shí)清除和刷新緩存中的field數(shù)據(jù)秩伞。默認(rèn)調(diào)度時(shí)間為一分鐘,作用范圍為Node節(jié)點(diǎn)
@Override
protected void doStart() {
? ? // Start thread that will manage cleaning the field data cache periodically
? ? threadPool.schedule(this.cleanInterval, ThreadPool.Names.SAME, this.cacheCleaner);
}
cleanInterval是個(gè)TimeValue對象欺矫,通過構(gòu)造函數(shù)進(jìn)行初始化纱新,默認(rèn)清除周期為一分鐘。TimeValue是ES內(nèi)部基于java的TimeUnit實(shí)現(xiàn)的時(shí)間調(diào)度服務(wù)穆趴,有:納秒脸爱,微秒,毫秒未妹,秒簿废,分,時(shí)教寂,天
ThreadPool.Names.SAME是es內(nèi)部自己實(shí)現(xiàn)的調(diào)度器
cacheCleaner:是indicesService內(nèi)部實(shí)現(xiàn)的Runnable線程接口捏鱼,主要實(shí)現(xiàn)如下:
@Override
public void run() {
? ? long startTimeNS = System.nanoTime();
? ? if (logger.isTraceEnabled()) {
? ? ? ? logger.trace("running periodic field data cache cleanup");
? ? }
? ? try {
? ? ? ? this.cache.getCache().refresh();
? ? } catch (Exception e) {
? ? ? ? logger.warn("Exception during periodic field data cache cleanup:", e);
? ? }
? ? if (logger.isTraceEnabled()) {
? ? ? ? logger.trace("periodic field data cache cleanup finished in {} milliseconds", TimeValue.nsecToMSec(System.nanoTime() - startTimeNS));
? ? }
? ? try {
? ? ? ? this.requestCache.cleanCache();
? ? } catch (Exception e) {
? ? ? ? logger.warn("Exception during periodic request cache cleanup:", e);
? ? }
? ? // Reschedule itself to run again if not closed
? ? if (closed.get() == false) {
? ? ? ? threadPool.schedule(interval, ThreadPool.Names.SAME, this);
? ? }
主要方法是cache對象進(jìn)行緩存刷新,執(zhí)行refresh方法酪耕,requestCache對象進(jìn)行緩存清除調(diào)用cleanCache方法。