actix / actix-net

A collection of lower-level libraries for composable network services.

Home Page:https://actix.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use single atomic for tracking all workers availability.

fakeshadow opened this issue · comments

In actix-server every worker has a separate availability tracker as atomic boolean. This makes tracking the availability of all workers hard.

A single AtomicUsize can be used to track all worker availability with every worker take one bit. This would reduce the atomic cost of tracking worker state and enable cheap hint before accepting connections. (When all workers are down accept would be stopped).

This would also help to resolve bug like #329.

only supporting up to 64 workers would not be an acceptable limitation of using a single atomic

Yea. On a second thought usize could not be a good choice as on 32bit system this would limit one group to 32.
So we can group every 64 workers to one atomic u64 and append addition worker groups to a vector.

That said the atomic cost would grow linear with the worker group count if accept would read all groups before accepting.

There is another approach to this is we eat some delay and potential over accepting and use mio's waker to report worker un availbility state through the waker queue. This could eliminate atomic cost at happy path but would cause the worker state change delayed with at least one extra poll.

Close as #343 would resolve this issue.