amibar / SmartThreadPool

A .NET Thread Pool fully implemented in C# with many features
http://www.codeproject.com/Articles/7933/Smart-Thread-Pool
Microsoft Public License
507 stars 182 forks source link

Add MaxQueueLength property to support bounded queues #8

Closed robhruska closed 7 years ago

robhruska commented 10 years ago

Summary:

MaxQueueLength

Added a configuration property (MaxQueueLength) that can be used to enforce an upper-bound on the size of the _workItemsQueue.

If the property value is null (default), no upper bound is enforced.

If the property value is 0, items will be rejected instead of queued when the pool is at its maximum thread count and all threads are working on items.

The property may be changed after the pool has .Start()ed to adjust the maximum queue length.

Queue limits configured on a pool will be ignored by WorkItemsGroups that use that pool (i.e. limits are only applied to QueueWorkItem() calls directly on SmartThreadPool instances).

When checking the queue limit and the queue length == the configured limit, items won't be rejected if the pool is going to immediately scale up (i.e. it hasn't reached its max threads). This means the queue limit bends a little bit (and is essentially the configured limit + potential available threads).

If an item is disallowed because the queue is at its maximum, a QueueRejectedException is thrown.

CurrentWorkItemsCount

Exposes the total CurrentWorkItemsCount. Involved making the private _currentWorkItemsCount volatile for better read accuracy.

robhruska commented 10 years ago

Anything I can do to help get this merged and pushed up to a new nuget.org package?

I'm looking to use (this forked version of) STP as a dependency for a public project, but without these changes up on nuget.org I'll have to manually include my forked version of DLL in my nupkg, which would be jank.

amibar commented 7 years ago

Added