Reuse req and ErlNifEnv rather than re-alloc/use/free them for every request. #8

Merged
gburd merged 1 commit from gsb-recycle-reqs into master 2013-04-25 17:26:16 +00:00
gburd commented 2013-04-25 17:04:16 +00:00 (Migrated from github.com)

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.

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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: greg/wterl#8
No description provided.