-
Notifications
You must be signed in to change notification settings - Fork 639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Investigate slow test: Lucene.Net.Tests.Index.TestAddIndexes::TestAddIndexesWithCloseNoWait() #308
Comments
Just adding some notes here for now, with the change here #312 this fixes a deadlocking scenario which i was encountering when trying to debug this. Now that there is no deadlock the tests will work as expected however using a custom nunit test runner attribute (FindFirstFailingSeed) I still see that the test runs slow. While debugging it and stepping through the code we no longer see deadlocks so I can actively step through the code but when using the Parallel Stacks view in VS or just the Threads window we can see there's always many threads waiting on a single lock. Some main things to note:
I think the above few things probably plays a role in the performance of this test so need to investigate this a little more. Since there is a recursive lock via indirect references that general means there can be deadlocks again but seeing as though there are so many locks trying to be taken anyways this will slow things down quite a lot. |
This goes to the heart of one of a few dozen issues that I have written down in a notebook that I haven't reported on GitHub yet. In Java, it is possible to turn on and off asserts in a production build, they aren't simply compiled out of the build. They are turned on during testing. What this effectively means is that there are a whole suite of tests (namely anything that is using I recently "fixed" a related issue (#299) by throwing I have been considering ways of reproducing the Java assertion behavior without producing negative performance impacts in production. But one of the main things to note is that What is needed is to come up with a solution that allows us to turn on asserts during testing in a way that doesn't hamper debug or runtime performance. One option I have been considering is to create a wrapper for internal static class Debugging
{
public static bool AssertsEnabled { get; set; } = SystemProperties.GetPropertyAsBoolean("assert", false);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Assert(Func<bool> conditionFactory, Func<string> messageFactory)
{
if (AssertsEnabled)
{
if (!conditionFactory())
throw new AssertionException(messageFactory());
}
else
{
Debug.Assert(conditionFactory(), messageFactory()); // Note this line is completely removed from Release builds
}
}
} Which can be used like: Debugging.Assert(() => !SlowFileExists(directory, newFileName), () => "file \"" + newFileName + "\" already exists; siFiles=" + string.Format(J2N.Text.StringFormatter.InvariantCulture, "{0}", siFiles)); I suspect to get optimal production performance, we will probably also have to duplicate the if (Debugging.AssertsEnabled)
Debugging.Assert(() => !SlowFileExists(directory, newFileName), () => "file \"" + newFileName + "\" already exists; siFiles=" + string.Format(J2N.Text.StringFormatter.InvariantCulture, "{0}", siFiles)); Do note that the |
The test
Lucene.Net.Tests.Index.TestAddIndexes::TestAddIndexesWithCloseNoWait()
(in Lucene.Net.Tests._E-I) is usually (around 90% of the time) correctly completing in about 2 seconds. However, occasionally it can take much longer. The test only checks for an invalid condition (adding index to a disposedIndexWriter
) and is supposed to exit early because of the exception. However, there seems to be contention between the threads that makes it extremely slow to exit on some runs (sometimes up to 5 minutes or more).No doubt, this is one of the primary contributors to the tests in the CI environment taking excessive time to complete.
The text was updated successfully, but these errors were encountered: