我有一个通过64位以下的ASP.NET网站运行的313MB的Lucene索引。当我启动应用程序并在下面的CreateLuceneIndex()方法中使用IndexReader.Open(directory, true)
读入索引时,我看到IIS Express Worker Process膨胀超过4GB然后爆炸 - OutOfMemoryException!
任何人都可以解释为什么以及我需要做些什么才能解决问题?当实际索引大小仅为313MB时,为什么会发生这种情况?
注意:Container是DI容器(Funq)
private void CreateLuceneIndex(Container container)
{
var directory = CreateDirectory();
var indexWriter = CreateIndexWriter(container, directory);
//indexWriter.DeleteAll();
//var fieldDictionary = CreateIndexFieldDictionary();
//PopulateLuceneIndex(indexWriter, fieldDictionary);
indexWriter.Dispose();
container.Register(new IndexSearcher(IndexReader.Open(directory, true)));
}
private Directory CreateDirectory()
{
var useAzureBlob = _appSettings.Get("UseAzureBLOBStorage", false);
var blobStorageEndpoint = _appSettings.Get("blobStorage", string.Empty);
var directory = useAzureBlob
? (Directory)
new AzureDirectory(CloudStorageAccount.Parse(blobStorageEndpoint), "Catalogue")
: new MMapDirectory(new DirectoryInfo(Environment.CurrentDirectory));
return directory;
}
private IndexWriter CreateIndexWriter(Container container, Directory directory)
{
container.Register<Analyzer>(new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30));
var analyser = container.TryResolve<Analyzer>();
var indexWriter = new IndexWriter(directory, analyser, IndexWriter.MaxFieldLength.UNLIMITED);
indexWriter.SetRAMBufferSizeMB(10.0);
return indexWriter;
}
答案 0 :(得分:0)
我还没有解决原因,但我发现从MMapDirectory
更改为FSDirectory
可以解决我的问题。