public static void ExecuteActivity(LuceneIndexingActivity activity, bool waitForComplete, bool distribute) { if (distribute) { activity.Distribute(); } // If there are too many activities in the queue, we have to drop at least the inner // data of the activity to prevent memory overflow. We still have to wait for the // activity to finish, but the inner data can (and will) be loaded from the db when // the time comes for this activity to be executed. if (IndexingActivityQueue.IsOverloaded()) { SnTrace.Index.Write("IAQ OVERLOAD drop activity FromPopulator A:" + activity.Id); activity.IndexDocumentData = null; } // all activities must be executed through the activity queue's API IndexingActivityQueue.ExecuteActivity(activity); if (waitForComplete) { activity.WaitForComplete(); } }
private static void WaitIfOverloaded(bool startProcessing = false) { // We prevent memory overflow by limiting the number of activities that we // keep in memory. This method waits for the queue to be able to process // new activities. var logCount = 1; while (IndexingActivityQueue.IsOverloaded()) { // In case of startup, we have to start processing activities that are // already in the queue so that new ones can be added later. if (startProcessing) { DependencyManager.ActivityEnqueued(); } if (logCount++ % 10 == 1) { SnTrace.Index.Write("IAQ OVERLOAD waiting {0} milliseconds.", IndexingOverloadWaitingTime * 10); } Thread.Sleep(IndexingOverloadWaitingTime); } }