Comments (3)
What's the use case for this?
from epocxy.
My intended use case is a better model for managing active Cowboy requests. Our code is currently riddled with try / catch blocks attempting to prevent a Cowboy request process from ever failing. Instead I would rather the Cowboy process monitor a worker with a timeout so that it can respond Server Busy or other Server Error on failure, and not use try / catch.
I am not a proponent of worker pools for the following reasons:
- Failure of the worker pool causes a storm of requests to a single manager
- Stale workers have memory issues
- Fragmentation if the process memory isn't cleaned properly
- The processes themselves are real memory leaks especially if they accidentally hold on to binaries
- Can have process dictionary junk from previous executions which cause them to very occasionally fail (in ways that are hard to discover)
- This can be caused by using 3rd party libraries which unknowingly to you use the process dictionary
- Choosing a next worker in almost all cases ends up with a single process bottleneck
- Even random needs to know which workers are available or risk messaging a missing process
- Alternative worker choice algorithms can significantly impact CPU usage attempting to be independent
- Assigning work to a limited set of processes is a premature allocation of resources
- Standard approaches end up with large erlang mailboxes when processes are slow
- Timeouts cause by large erlang mailboxes ripple through the pool, eventually causing full failure
- Once allocated, the worker is expected to process, not return the work, so no reallocation occurs in most pools
- Reporting of pending tasks is difficult because it requires all workers to anticipate query messages
- Query messages go to the end of the mailbox, so aren't seen unless selective receive is used
- Worker pools provide no back pressure because all task assignments are silently queued
- Tasks can be lost when workers fail (all queued, and in transit tasks)
This proposed alternative to worker pools has the following benefits:
- No message queues, a worker only works on a single task
- No task loss that is unobserved - Workers can be more lightly managed with distributed monitors rather than a single manager process
- No storms of restart, caller gets 'DOWN' and decides whether to request a new worker - Workers are never reused, so no garbage collection, fragmentation, leaks and process dictionary issues
- If the process queue is ever empty because of resource limiting, the caller can decide what to do (back pressure)
- Reduced garbage collection pressure, process termination (normal or otherwise) is a complete reclaim
The following issues aren't solved:
- Reporting pending tasks, especially if the model accepts work that exceeds resources available
- This feature may end up with an in-progress ets table indexed on worker pid owning task
This approach has the following costs:
- Constant allocation pressure of spawning new processes, amortized by pre-spawn in tranches
- This results in CPU pressure and memory allocation pressure - Pre-allocated memory for all queued processes waiting for task assignment
- Partially offset by allowing 'hibernate' option for newly spawned processes - Will probably need all workers to be monitored by the Mth following process to enable resource limits
- Complicates the coordination logic and adds a slight messaging / monitoring overhead
- Can be avoided if resource limits are not imposed by configuration choice
I have another feature in mind (but have not created an issue yet because it isn't fully thought out) which involves "Active Tasks". It flips the worker pool concept, so that tasks are queued and processes arrive to grab them. This has the advantage of being able to report all the work pending, and potentially assigned as well, allowing concurrent reporting from central queues.
from epocxy.
Completed with v1.1.0. Didn't use queues, used a cxy_fount reservoir gen_fsm and a cxy_regulator gen_fsm, both of which are coordinated with a cxy_fount_sup supervisor.
from epocxy.
Related Issues (20)
- Do controlled shutdown when cxy_ctl:remove_task_types is called
- Add cxy_ctl_sup to properly own ets tables
- Add deferred option for cxy_ctl
- Calling cxy_cache_sup:start_cache/3 succeeds with bad param
- Add API for querying the age of an ets_buffer
- Generational caching should be generalized as a behaviour
- Concurrent 1 writer and 1 reader causes ets_buffer:read return {missing_ets_data, buffer_name, N} HOT 1
- ets_buffer:create overwrites metadata without warning
- Concurrency bug? HOT 1
- Concurrency bug? HOT 2
- Race condition in cxy_cache:create_new_value HOT 1
- No correct way to invalidate cache entries HOT 1
- Make tests fails : Test run failed! Reason: {'EXIT',{error,{enoent,"src/"}}} HOT 9
- make edoc fails HOT 1
- question about `make_sup_name` in cxy_foun_sup HOT 1
- cxy_fount behaviour requires init/1 but is called as init/* HOT 2
- cxy_fount: Trying to get more pids than slab_size + 1 always return list of empty lists HOT 3
- Suggestion : Add ability to flush data based on LRU HOT 1
- ring buffer bug 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 epocxy.