Comments (5)
So I decided to profile this repro to understand what leads to this performance degradation. Profiling for 5.0.19 gives the following results:
As we can see, CommitAndReleaseTransaction
takes 4x more time than upsert itself, and for some reason we're doing writing to disk in the same thread.
And here is how it looks for v5.0.17:
As we can see, in v5.0.17 CommitAndReleaseTransaction
takes little to no time, and all the writing is offloaded to a separate thread.
After some investigation, turns out that there is an issue in AsyncManualResetEvent
- when Set
is being called, execution continues in DiskWriterQueue.ExecuteQueue
after await _queueHasItems.WaitAsync()
. I would say, we don't need this separate class at all, as .NET provides a way to await any WaitHandle
using thread pool (see https://github.com/StephenCleary/AsyncEx/blob/v5.0.0/src/Nito.AsyncEx.Interop.WaitHandles/Interop/WaitHandleAsyncFactory.cs, DoFromWaitHandle
). So I changed that event to ManualResetEventSlim
in conjunction with this method.
Now repro runs in 42 seconds. 4x faster than 5.0.19 but still ~3x slower than 5.0.17. Further profiling results:
As we can see, for some reason we do call BasePage.ToString
a lot, as well as formatting strings. I'm 100% sure that this should not happen on the hot path. Here is the issue (BasePage.Get
):
ENSURE(this.IsValidPos(position), $"invalid segment position in index footer: {ToString()}/{index}");
ENSURE(this.IsValidLen(length), $"invalid segment length in index footer: {ToString()}/{index}");
So I just commented these 2 lines to check and 1 in IndexService, and it runs in 13 seconds, pretty close to v5.0.17.
from litedb.
Created PR to fix the first part - #2453
from litedb.
Created PR to fix the second part - #2454
from litedb.
@mbdavid Sorry but I believe this is a critical issue, in the current state v5.0.19 is not usable. I did all the research and fixes, please consider merging it.
from litedb.
I agree. This fix will help me too. thank you for your work @alexbereznikov . I hope it will be merged
from litedb.
Related Issues (20)
- [QUESTION] Generic searching on ILiteQueryable<T>
- [BUG] LiteFileStream SetReadStreamPosition causes incorrect seeking HOT 5
- Application crash at DropCollection HOT 2
- [BUG] Current transaction contains open cursors. Close cursors before run Commit() in 5.0.19 HOT 1
- Analogy Log Viewer For LiteDB
- [BUG] Use EnterTransaction() before EnterLock(name) when update item HOT 1
- [BUG] Program freezes when I insert and then update the LiteDB in version 5.0.18 and 5.0.19 HOT 2
- [BUG] CVE is fixed in v5 but v4, we are not able to migrate yet
- Exception when Using ToLowerInvariant() in Query Expression HOT 1
- The LiteFileStream doesn't suport enableRangeProcessing in MVC file result. HOT 1
- [BUG] LockRecursionException thrown in very simple use case HOT 2
- [BUG] Unable to Retrieve Values with Index
- [QUESTION] querying documents having a subdocument property that is in a list HOT 1
- [BUG] Any/All requires simple parameter on left side
- Is LiteDB still being maintained? HOT 8
- Why Include() is not loading all nested items
- [BUG] "ENSURE ... Clear() cache" error and DB corruption when modifying collection during its enumeration
- Stop ads[BUG]
- FirstOrDefault causes transactions to be not removed HOT 1
- [BUG] Use EnterTransaction() before EnterLock HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from litedb.