From 8a71ce76db366c0a97f065ef50bcb8d70cd84586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Thu, 27 Nov 2014 09:01:07 +0100 Subject: [PATCH] LEP-004: threadpool handle (REJECTED) --- 000-index.md | 3 ++- 004-threadpool-handle.md | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 004-threadpool-handle.md diff --git a/000-index.md b/000-index.md index 8a23d2e..430d12f 100644 --- a/000-index.md +++ b/000-index.md @@ -2,4 +2,5 @@ * [001-remove-unix-support](https://github.com/libuv/leps/blob/master/001-remove-unix-support.md) * [002-custom-uv-streams](https://github.com/libuv/leps/blob/master/002-custom-uv-streams.md) -* [003-create-sockets-early.md](https://github.com/libuv/leps/blob/master/003-create-sockets-early.md) +* [003-create-sockets-early](https://github.com/libuv/leps/blob/master/003-create-sockets-early.md) +* [004-threadpool-handle.md](https://github.com/libuv/leps/blob/master/004-threadpool-handle.md) diff --git a/004-threadpool-handle.md b/004-threadpool-handle.md new file mode 100644 index 0000000..5e5ef89 --- /dev/null +++ b/004-threadpool-handle.md @@ -0,0 +1,55 @@ +| Title | Threadpool handle | +|--------|----------------------| +| Author | @saghul | +| Status | REJECTED | +| Date | 2014-11-27 08:00:44 | + + +## Overview + +Every now and then we get questions / complaints regarding the thread pool. It’s too +small, doesn’t scale, and so on. Right now the following stuff is ran on the thread pool: + +- DNS requests (`uv_getaddrinfo`, `uv_getnameinfo`) +- File system operations (`uv_fs_*`) +- User code (through `uv_queue_work`) + +The thread pool is also global and has a fixed size of 4, which currently can only +be changed using an environment variable. + +This proposal explores the possibility of converting the thread pool to a handle, +with the following API: + +~~~~ +int uv_tpool_init(uv_loop_t* loop, uv_tpool_t* handle, int min_threads, int max_threads) +int uv_tpool_queue_work(uv_work_t*req, uv_tpool_t* handle, uv_work_cb work_cb, uv_after_work_cb after_work_cb) +~~~~ + +The thread pool would be created with a minimum number of threads, which could then +scale up tot he given max_threads. A resize API could be added in the future. Running +code on the threadpool is only safe from the event loop thread. + +`uv_queue_work` would effectively disappear. The user would have to create her own +thread pool and use `uv_tpool_queue_work` manually. + +DNS and file system APIs would change in order to accept a `uv_tpool_t` handle instead +of a loop. This gives the user the flexibility to create multiple pools of different +sizes and run DNS operations on one and file system operations in another one, for example. + +Example `uv_getaddrinfo`: + +~~~~ +int uv_getaddrinfo(uv_getaddrinfo_t* req, + uv_tpool_t* handle, + uv_getaddrinfo_cb getaddrinfo_cb, + const char* node, + const char* service, + const struct addrinfo* hints); +~~~~ + + +# Reasons for rejection + +The libuv core team (part of it) gathered together at Node Interactive Amsterdam 2016 and decided +to withdraw this course of action and focus on a pluggable API for threaded operations. A new +LEP will be written about it.