Reuse req and ErlNifEnv rather than re-alloc/use/free them for every request. #8
Loading…
Reference in a new issue
No description provided.
Delete branch "gsb-recycle-reqs"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This patch should a) bound overall memory allocated by async_nif and b) remove one enif_alloc and one enif_env_alloc and 2 free calls on each request, c) reduce memory fragmentation and overall it should (not measured) save us some overhead on the hottest code path.
With this patch async_nif will only allocate a fixed amount for control structures and then up to a limited number (default 1000 * MAX_WORKERS) of request/ErlNifEnv pairs. This bounds memory even in the worst case situation to a fixed amount.
Also in this patch, I've increased the number of worker threads from 128 to 1024 and I've made the queue selection process a bit more robust. With 1024 worker threads and generally about 8-20 cores there are plenty of worker threads per-queue. The queue selection wasn't updating a bit of global state and so requests were not as spread out as possible.