{"action":"created","issue":{"url":"https://api.github.com/repos/libuv/libuv/issues/1959","repository_url":"https://api.github.com/repos/libuv/libuv","labels_url":"https://api.github.com/repos/libuv/libuv/issues/1959/labels{/name}","comments_url":"https://api.github.com/repos/libuv/libuv/issues/1959/comments","events_url":"https://api.github.com/repos/libuv/libuv/issues/1959/events","html_url":"https://github.com/libuv/libuv/issues/1959","id":354400615,"node_id":"MDU6SXNzdWUzNTQ0MDA2MTU=","number":1959,"title":"Threadpool meta-issue","user":{"login":"davisjam","id":22822319,"node_id":"MDQ6VXNlcjIyODIyMzE5","avatar_url":"https://avatars0.githubusercontent.com/u/22822319?v=4","gravatar_id":"","url":"https://api.github.com/users/davisjam","html_url":"https://github.com/davisjam","followers_url":"https://api.github.com/users/davisjam/followers","following_url":"https://api.github.com/users/davisjam/following{/other_user}","gists_url":"https://api.github.com/users/davisjam/gists{/gist_id}","starred_url":"https://api.github.com/users/davisjam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davisjam/subscriptions","organizations_url":"https://api.github.com/users/davisjam/orgs","repos_url":"https://api.github.com/users/davisjam/repos","events_url":"https://api.github.com/users/davisjam/events{/privacy}","received_events_url":"https://api.github.com/users/davisjam/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2018-08-27T17:10:41Z","updated_at":"2018-09-02T20:28:55Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"# Summary\r\nThis is a meta-issue to describe the landscape of proposals around the libuv threadpool. \r\n\r\nAs has been observed [since ancient times](https://github.com/nodejs/node-v0.x-archive/issues/7256), using a single threadpool for file I/O, DNS, and user-defined tasks leads to performance problems, [Node refusing to die cleanly](https://github.com/nodejs/node-v0.x-archive/issues/25349), etc.\r\n\r\nWhere possible I have cited relevant issues, PRs, etc. Let me know if I missed anybody.\r\n\r\n# Proposed designs\r\n\r\n1. *BYO*. Use the libuv threadpool for I/O, but pretend `uv_queue_work` does not exist. Use an application-level threadpool for CPU-intensive tasks. I don't know if anyone has seriously proposed this, since it would require a lot of refactoring for embedders. One suggestion along these lines from @btrask [here](https://github.com/libuv/libuv/issues/267#issuecomment-126524725).\r\n2. *Giant TP*. As suggested by @bnoordhuis [here](https://github.com/joyent/libuv/issues/1181#issuecomment-36954098) and with a sketch in #382.\r\n    - May have performance issues. `uv_queue_work` calls with CPU-bound work will contend for a limited set of cores.\r\n3. *TP Throttling*. Use throttling policies to prevent certain kinds of work from dominating a shared threadpool. This is the current approach thanks to @addaleax's #1845, with the implementation throttling DNS requests in favor of FS and user-defined tasks. It was also suggested by @bminer [here](https://github.com/libuv/libuv/issues/28#issuecomment-65481026), by @zhaozg [here](https://github.com/libuv/libuv/issues/660#issue-123136498) (with a policy throttling user-defined tasks), and by @CurlyMoo [here](https://github.com/libuv/libuv/issues/267#issuecomment-274330648) (with a more general policy to balance between different classes of work).\r\n    - Could be used in conjunction with the *Giant TP* approach.\r\n4. *TP Handles*. Any API that registers work to be performed by a thread other than the event loop should indicate the threadpool in which this work should be performed. Also suggested by @bminer [here](https://github.com/libuv/libuv/issues/28#issuecomment-65481026) and with a rough draft by @saper in #319.\r\n    - As championed by @saghul in #7 ([LEP #4](https://github.com/libuv/leps/pull/4)). \r\n    - Not considered ABI compatible for v1.x.\r\n5. *Opaque/Pluggable TP*. Let the embedder determine how asynchronous work should be performed, by providing \"submit work\" and \"work done\" function pointers by which to communicate with the event loop. This enables maximum flexibility in threadpool design and permits experimentation by different embedders for what works best for them.\r\n    - As championed by @bnoordhuis in #267.  \r\n    - Should be ABI compatible for v1.x.\r\n\r\n# Desired features\r\n\r\n1. Ability to cancel running tasks. [joyent/libuv #1181](https://github.com/joyent/libuv/issues/1181), #7, #203, #364, Node.js [#795](https://github.com/nodejs/node/issues/795).\r\n2. Task prioritization. @bnoordhuis #7, @CurlyMoo #267.\r\n3. Good default behavior for folks who don't want to write their own TP. @beevik, #7.\r\n4. Scale TP on-demand. #382.\r\n5. Monitor-ability of queue, Workers: #1144, #1528, #1764.\r\n\r\n# Recommended approach\r\n\r\n@saghul said [here](https://github.com/libuv/leps/pull/4#issuecomment-248154867) that: \"The libuv core team...gathered...and decided to...focus on a pluggable API for threaded operations\".\r\n\r\nAs @bnoordhuis has argued, this approach should be able to support all of the desired features with the right API and structs.\r\n\r\n# Ongoing work\r\n\r\nI am working on an implementation of the *Pluggable TP* design in #1726."},"comment":{"url":"https://api.github.com/repos/libuv/libuv/issues/comments/417957617","html_url":"https://github.com/libuv/libuv/issues/1959#issuecomment-417957617","issue_url":"https://api.github.com/repos/libuv/libuv/issues/1959","id":417957617,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNzk1NzYxNw==","user":{"login":"CurlyMoo","id":2429105,"node_id":"MDQ6VXNlcjI0MjkxMDU=","avatar_url":"https://avatars1.githubusercontent.com/u/2429105?v=4","gravatar_id":"","url":"https://api.github.com/users/CurlyMoo","html_url":"https://github.com/CurlyMoo","followers_url":"https://api.github.com/users/CurlyMoo/followers","following_url":"https://api.github.com/users/CurlyMoo/following{/other_user}","gists_url":"https://api.github.com/users/CurlyMoo/gists{/gist_id}","starred_url":"https://api.github.com/users/CurlyMoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CurlyMoo/subscriptions","organizations_url":"https://api.github.com/users/CurlyMoo/orgs","repos_url":"https://api.github.com/users/CurlyMoo/repos","events_url":"https://api.github.com/users/CurlyMoo/events{/privacy}","received_events_url":"https://api.github.com/users/CurlyMoo/received_events","type":"User","site_admin":false},"created_at":"2018-09-02T20:28:55Z","updated_at":"2018-09-02T20:28:55Z","author_association":"CONTRIBUTOR","body":"Maybe i was mistaking about the file io part."}}
{"actor":{"display_login":"CurlyMoo"}}