休眠搜索索引速度降低

时间:2020-09-09 14:40:05

标签: java spring-boot lucene hibernate-search full-text-indexing

我的代码和数据库中有两个实体。一个实体拥有20万条记录,另一个实体具有260万条记录。 我正在使用MassIndexer StartandWait()方法和Start()方法。当我开始用较少的记录来索引我的实体时,即20万,它以恒定的“速度文档/秒”对它们进行索引相当快,但是当它开始以260万记录对另一个实体进行索引时,索引速度在数分钟内降低了英里,而CPU消耗我的窗口显示100%,内存也显示100%,速度下降2000个文档/秒到8个文档/秒,而且看起来永远不会完成。

这是我的代码

    try
    {
        logger.info("Indexing Started============================");
        SimpleIndexingProgressMonitor progressMonitor = new SimpleIndexingProgressMonitor();
        FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
        MassIndexer massIndexer = fullTextEntityManager.createIndexer()
        .purgeAllOnStart(purgeAllOnStart)
        .progressMonitor(progressMonitor)
        .typesToIndexInParallel(typesToIndexInParallel)
        .batchSizeToLoadObjects(batchSizeToLoadObjects)
        .threadsForSubsequentFetching(8)
        .idFetchSize(idFetchSize)
        .threadsToLoadObjects(threadsToLoadObjects)
        .cacheMode(CacheMode.IGNORE);

        try {
          if (!async) {
            massIndexer.startAndWait();
          } else {
            massIndexer.start();
          }
        } catch (InterruptedException e) {
          logger.error("mass reindexing interrupted: " + e.getMessage());
        } finally {
            fullTextEntityManager.flushToIndexes();
        }
       
        logger.info("Indexing completed============================");
    }       catch(Exception e) {
        logger.info(e.getMessage());
        e.printStackTrace();
        
    }

看看我是否能以固定的速度对此问题进行固定和索引,并且内存和CPU使用率超时是否存在任何问题,那么可能的解决方法是什么?

如何在不降低索引速度的情况下避免这种情况?

0 个答案:

没有答案