Comments (2)
First, a little history. In earlier versions of ObservableComputations 2.x, events were unsubscribed on the same thread as the computation. During load testing, it turned out that unsubscribing from events greatly reduces overall performance. Therefore, I made a mechanism for unsubscribing from events in a dedicated thread ("ObservableComputations events unsubscriber #0").
In general, it is required to ensure performance with frequent single unsubscribes (one event, one source, one subscriber). Of course, I could take a thread from the thread pool for each unsubscribe. But at peak loads, this can lead to a short-term exhaustion of the thread pool, which can lead to loss of responsiveness to input or output (lag). Creating a new thread to unsubscribe (without using a pool) is an even worse solution, since creating a thread is an expensive operation. A use case of the thread pool is the asynchronous execution of heterogeneous tasks, the parallel execution of which ensures that the application is responsive to input or output. In the case of unsubscribing from events, the task is one - unsubscribing from events, parallel execution of several unsubscribes will not give any advantages, and therefore we can save the pool of threads for its intended use.
The TaskCompletionSource you suggested is an abstraction over Task, which is an abstraction over the thread pool and threads. AsyncManualResetEvent is an abstraction over TaskCompletionSource.
A sleeping (idle) thread consumes few resources. ManualResetEventSlim is a low-level primitive and therefore gives good performance.
If 1 events unsubscriber thread can't cope, you can increase the number of such threads (OcConfiguration.EventUnsubscriberThreadsCount).
from observablecomputations.
Thanks for taking the time to explain in such detail! Makes a lot of sense.
In my particular use case, I know that I'm not unsubscribing often (or actually using ObservableComputations very heavily at all), so the separate thread is not of benefit to me and just adds "noise" to my performance-profiling session. I need to exclude this thread, because although it's not consuming resources, my sampling peformance profiler shows that the thread has an active stack trace.
It's not a major problem at all; I can just exclude that thread. But if there was a way that the library could only spin up the separate thread when it's needed (maybe after a threshold of unsubscribes per second?) that would be cool. Or, provide a way I can choose to switch off that thread and just to the unsubscribes in the same thread as the computation. I'm sure that's a low-priority request though!
Thanks for your work on this library.
from observablecomputations.
Related Issues (12)
- Joining System.ArgumentException: 'Property 'System.String Type' is not defined for type 'System.String' Arg_ParamName_Name' HOT 1
- Breaking change in version 2.0.0
- Create a failing unit test
- ArgumentOutOfRangeException because comparisonWithMiddleItem > 1 HOT 1
- Add support net6.0; net7.0
- Add support for ReadOnlyObservableCollection
- docs/readme: "FirstCalculating" doesn't exist (should be "FirstComputing"?) HOT 2
- Please add a change log or release notes document HOT 2
- How exactly do you build this? HOT 10
- Why can't I find the CollectionDispatch() method? HOT 4
- Consider using WeakEventManagers instead of explicit unsubscribe API 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 observablecomputations.