Comments (2)
The priority queues I have generally seen use separate channels for different priorities, all feeding the same pool of goroutines. The highest priority channel is serviced until empty before servicing the next lower priority channel, and so on... I assume you doing something similar and feeding tasks to this worker pool.
The problem is that this workerpool is designed to be a non-blocking pool that you throw as many tasks at as you like without ever having to wait, even if that task is not immediately runnable. What you probably need is a blocking workerpool. So that when there are no available workers, the pool will not accept another task, and your tasks will stack up in the appropriate queues or channels.
To respond to your suggestion above, I do not think checking the number of active workers will be very reliable as that may become completely different immediately after the check. If that is still needed, then have the functions that are called increment and decrement a counter on entry and exit (or create a generic wrapper that does that).
A blocking implementation would be much simpler since most of the complexity in this workerpool arises from needing to handle queuing tasks when all workers are busy.
from workerpool.
That is fair. I did eventually implement a custom worker pool with priority handling https://github.com/hashicorp/terraform-ls/blob/main/internal/terraform/module/module_loader.go
Your workerpool implementation did help us get things off the ground at the beginning, but it became clear later that we have a little more complex needs.
So with that in mind I'm going to close this issue.
from workerpool.
Related Issues (20)
- New release with `Pause` method HOT 3
- Race condition testing HOT 3
- Stop job while running HOT 20
- Pause a workerpool through keyboard HOT 16
- support to change maxWorkers dynamically HOT 2
- codecov in .travis.yml - security issue HOT 1
- Possible memory leak HOT 8
- Document how to handle errors, please HOT 2
- Why startWorker() and not worker()? HOT 2
- [feature request] naming workerpools
- Ability configure idle timeout. HOT 1
- Cannot work with deque 0.2.0 HOT 1
- What is the purpose of "r := r"? HOT 2
- Make Workers open and close a database connection HOT 3
- Bug - strange behavior HOT 1
- Wait on Submit until queue has HOT 1
- Is it possible for this pool to experience queue overflow? HOT 2
- required: update golang version
- run in background
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 workerpool.