basho-labs/wterl — pull request #8 by gburd (2013-04-25 17:04:16+00:00)
Title: Reuse req and ErlNifEnv rather than re-alloc/use/free them for every request.

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.