Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

lep: threadpool handle #4

Merged
merged 1 commit into from
Sep 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 000-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
55 changes: 55 additions & 0 deletions 004-threadpool-handle.md
Original file line number Diff line number Diff line change
@@ -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.