mlockett42 / litedb-async

This library allows the use of asynchronous programming techniques with the LiteDb library
Apache License 2.0
104 stars 13 forks source link

Replace use of two ManualResetEvents by SemaphoreSlim and CancellationTokenSource #7

Closed mookid8000 closed 4 years ago

mookid8000 commented 4 years ago

This obviates the need for the _queueLock, as the semaphore both acts as a lock and a "there's more work to do" signal.

Use of CancellationTokenSource/CancellationToken to signal thread exit seems more contemporary, AND it has the added benefit that the semaphore's wait can be interrupted by the cancellation token.

To see if this change affected performance, I made the simple benchmark test (SimpleBenchmark). Here are the results of running the test

BEFORE:

Performed 1000 inserts and 1000 queries in 1260,2 ms on average

and AFTER:

Performed 1000 inserts and 1000 queries in 1193,7 ms on average

Conclusion: Doesn't seem to have made any significant impact on performance.

mlockett42 commented 4 years ago

Sorry this was auto-closed by Github a moment ago. I have restructed the repo to replace master and develop with release and incoming. I also commits https://github.com/mlockett42/litedb-async/pull/7/commits/0c945fe6ee1e9620297ea03ceb18bae7180a64a8 and https://github.com/mlockett42/litedb-async/pull/7/commits/9f69f77e96d7d6307a66419ef328d25db241eeae were cherry picked into the repo. I have an issue with the underlying database thing.

I hope github will correctly credit you for the commits in that situation see also https://github.com/mlockett42/litedb-async/issues/9