{"action":"created","comment":{"url":"https://api.github.com/repos/nodejs/nodejs.org/pulls/comments/152411855","pull_request_review_id":78271148,"id":152411855,"diff_hunk":"@@ -0,0 +1,435 @@\n+---\n+title: Don't Block the Event Loop (or the Worker Pool)\n+layout: docs.hbs\n+---\n+\n+# Don't Block the Event Loop (or the Worker Pool)\n+\n+## Should you read this guide?\n+If you're writing a server using Node, keep reading.\n+If you're writing command-line scripts with Node, this guide might still come in handy, but it isn't crucial.\n+\n+## TL; DR\n+Node.js runs JavaScript code in the Event Loop and handles I/O in a Worker Pool (the threadpool).\n+Node scales well, sometimes better than more heavyweight approaches like Apache.\n+The secret to Node's scalability is that it uses a small number of threads to handle many clients.\n+If Node can make do with fewer threads, then it can spend more of your system's time and memory working on clients rather than on paying overheads for threads.\n+\n+Here's a good rule of thumb for keeping your Node server speedy:\n+*Node is only fast when the work associated with each client at any given time is \"small\"*.\n+\n+This applies to work both on the Event Loop and on the Worker Pool.\n+\n+## Why should I avoid blocking the Event Loop and the Worker Pool?\n+Node uses a small number of threads to handle many clients.\n+While a thread is working on behalf of one client, it can't work for any other clients.\n+\n+This provides two motivations for blocking neither the Event Loop nor the Worker Pool.\n+Since both the Event Loop and the Workers respond to events, we will refer to these threads generally as *Event Handlers* or *Event-Handler Threads*.\n+All threads in Node are Event Handlers: one Event Loop and several Workers.\n+\n+1. Performance: If you regularly perform heavyweight tasks on an Event Handler, the *throughput* (requests/second) of your server will suffer.\n+2. Security: If it is possible that for certain input you might block an Event Handler, a malicious client might be able to figure out the \"evil input\", make your code block, and keep you from working on other clients. This would be a Denial of Service attack.\n+\n+## A quick review of Node's architecture\n+\n+Node uses the Event-Driven Architecture: it has an Event Loop for orchestration and a Worker Pool for expensive tasks.\n+\n+## Queues and Cooperative Multitasking\n+Both the Event Loop and the Worker Pool use *queues*, which are data structures with one or more producers who place items into the queue, and one or more consumers who remove items from the queue.\n+\n+The Event Loop's queue is full of pending events.\n+When the Event Loop sees a new event, it invokes its callback, which is JavaScript code that sees your Node application.\n+The Event Loop is the only consumer of this queue.\n+The Node runtime produces events for this queue.\n+Specifically, Node asks libuv to monitor file descriptors using [epoll](http://man7.org/linux/man-pages/man7/epoll.7.html)), and the Event Loop's queue consists of the ready descriptors.","path":"locale/en/docs/guides/dont-block-the-event-loop.md","position":45,"original_position":45,"commit_id":"1bc444afff79c4dfdeefce3ff35676c76387009b","original_commit_id":"1bc444afff79c4dfdeefce3ff35676c76387009b","user":{"login":"davisjam","id":22822319,"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},"body":"Yes, good catch.","created_at":"2017-11-21T21:52:04Z","updated_at":"2017-11-21T21:52:04Z","html_url":"https://github.com/nodejs/nodejs.org/pull/1478#discussion_r152411855","pull_request_url":"https://api.github.com/repos/nodejs/nodejs.org/pulls/1478","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/nodejs/nodejs.org/pulls/comments/152411855"},"html":{"href":"https://github.com/nodejs/nodejs.org/pull/1478#discussion_r152411855"},"pull_request":{"href":"https://api.github.com/repos/nodejs/nodejs.org/pulls/1478"}},"in_reply_to_id":152406896},"pull_request":{"url":"https://api.github.com/repos/nodejs/nodejs.org/pulls/1478","id":153480432,"html_url":"https://github.com/nodejs/nodejs.org/pull/1478","diff_url":"https://github.com/nodejs/nodejs.org/pull/1478.diff","patch_url":"https://github.com/nodejs/nodejs.org/pull/1478.patch","issue_url":"https://api.github.com/repos/nodejs/nodejs.org/issues/1478","number":1478,"state":"open","locked":false,"title":"Guide on \"Don't block the event loop\"","user":{"login":"davisjam","id":22822319,"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},"body":"Towards #1471.\r\n\r\nNot finished yet, hoping to get some initial feedback.","created_at":"2017-11-19T04:21:33Z","updated_at":"2017-11-21T21:52:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a35631660057c335b7d50e5e4644b8aafd0829f2","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/nodejs/nodejs.org/pulls/1478/commits","review_comments_url":"https://api.github.com/repos/nodejs/nodejs.org/pulls/1478/comments","review_comment_url":"https://api.github.com/repos/nodejs/nodejs.org/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nodejs/nodejs.org/issues/1478/comments","statuses_url":"https://api.github.com/repos/nodejs/nodejs.org/statuses/1bc444afff79c4dfdeefce3ff35676c76387009b","head":{"label":"davisjam:DontBlockTheEventLoop","ref":"DontBlockTheEventLoop","sha":"1bc444afff79c4dfdeefce3ff35676c76387009b","user":{"login":"davisjam","id":22822319,"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},"repo":{"id":111169777,"name":"nodejs.org","full_name":"davisjam/nodejs.org","owner":{"login":"davisjam","id":22822319,"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},"private":false,"html_url":"https://github.com/davisjam/nodejs.org","description":"The Node.js website.","fork":true,"url":"https://api.github.com/repos/davisjam/nodejs.org","forks_url":"https://api.github.com/repos/davisjam/nodejs.org/forks","keys_url":"https://api.github.com/repos/davisjam/nodejs.org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/davisjam/nodejs.org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/davisjam/nodejs.org/teams","hooks_url":"https://api.github.com/repos/davisjam/nodejs.org/hooks","issue_events_url":"https://api.github.com/repos/davisjam/nodejs.org/issues/events{/number}","events_url":"https://api.github.com/repos/davisjam/nodejs.org/events","assignees_url":"https://api.github.com/repos/davisjam/nodejs.org/assignees{/user}","branches_url":"https://api.github.com/repos/davisjam/nodejs.org/branches{/branch}","tags_url":"https://api.github.com/repos/davisjam/nodejs.org/tags","blobs_url":"https://api.github.com/repos/davisjam/nodejs.org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/davisjam/nodejs.org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/davisjam/nodejs.org/git/refs{/sha}","trees_url":"https://api.github.com/repos/davisjam/nodejs.org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/davisjam/nodejs.org/statuses/{sha}","languages_url":"https://api.github.com/repos/davisjam/nodejs.org/languages","stargazers_url":"https://api.github.com/repos/davisjam/nodejs.org/stargazers","contributors_url":"https://api.github.com/repos/davisjam/nodejs.org/contributors","subscribers_url":"https://api.github.com/repos/davisjam/nodejs.org/subscribers","subscription_url":"https://api.github.com/repos/davisjam/nodejs.org/subscription","commits_url":"https://api.github.com/repos/davisjam/nodejs.org/commits{/sha}","git_commits_url":"https://api.github.com/repos/davisjam/nodejs.org/git/commits{/sha}","comments_url":"https://api.github.com/repos/davisjam/nodejs.org/comments{/number}","issue_comment_url":"https://api.github.com/repos/davisjam/nodejs.org/issues/comments{/number}","contents_url":"https://api.github.com/repos/davisjam/nodejs.org/contents/{+path}","compare_url":"https://api.github.com/repos/davisjam/nodejs.org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/davisjam/nodejs.org/merges","archive_url":"https://api.github.com/repos/davisjam/nodejs.org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/davisjam/nodejs.org/downloads","issues_url":"https://api.github.com/repos/davisjam/nodejs.org/issues{/number}","pulls_url":"https://api.github.com/repos/davisjam/nodejs.org/pulls{/number}","milestones_url":"https://api.github.com/repos/davisjam/nodejs.org/milestones{/number}","notifications_url":"https://api.github.com/repos/davisjam/nodejs.org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/davisjam/nodejs.org/labels{/name}","releases_url":"https://api.github.com/repos/davisjam/nodejs.org/releases{/id}","deployments_url":"https://api.github.com/repos/davisjam/nodejs.org/deployments","created_at":"2017-11-18T02:26:43Z","updated_at":"2017-11-18T02:26:48Z","pushed_at":"2017-11-20T23:16:25Z","git_url":"git://github.com/davisjam/nodejs.org.git","ssh_url":"git@github.com:davisjam/nodejs.org.git","clone_url":"https://github.com/davisjam/nodejs.org.git","svn_url":"https://github.com/davisjam/nodejs.org","homepage":"https://nodejs.org","size":43272,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"nodejs:master","ref":"master","sha":"d6ce830ae8b0267441bd1b7f66876e8b2e0e58f7","user":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars3.githubusercontent.com/u/9950313?v=4","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"repo":{"id":37717474,"name":"nodejs.org","full_name":"nodejs/nodejs.org","owner":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars3.githubusercontent.com/u/9950313?v=4","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nodejs/nodejs.org","description":"The Node.js website.","fork":false,"url":"https://api.github.com/repos/nodejs/nodejs.org","forks_url":"https://api.github.com/repos/nodejs/nodejs.org/forks","keys_url":"https://api.github.com/repos/nodejs/nodejs.org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nodejs/nodejs.org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nodejs/nodejs.org/teams","hooks_url":"https://api.github.com/repos/nodejs/nodejs.org/hooks","issue_events_url":"https://api.github.com/repos/nodejs/nodejs.org/issues/events{/number}","events_url":"https://api.github.com/repos/nodejs/nodejs.org/events","assignees_url":"https://api.github.com/repos/nodejs/nodejs.org/assignees{/user}","branches_url":"https://api.github.com/repos/nodejs/nodejs.org/branches{/branch}","tags_url":"https://api.github.com/repos/nodejs/nodejs.org/tags","blobs_url":"https://api.github.com/repos/nodejs/nodejs.org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nodejs/nodejs.org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nodejs/nodejs.org/git/refs{/sha}","trees_url":"https://api.github.com/repos/nodejs/nodejs.org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nodejs/nodejs.org/statuses/{sha}","languages_url":"https://api.github.com/repos/nodejs/nodejs.org/languages","stargazers_url":"https://api.github.com/repos/nodejs/nodejs.org/stargazers","contributors_url":"https://api.github.com/repos/nodejs/nodejs.org/contributors","subscribers_url":"https://api.github.com/repos/nodejs/nodejs.org/subscribers","subscription_url":"https://api.github.com/repos/nodejs/nodejs.org/subscription","commits_url":"https://api.github.com/repos/nodejs/nodejs.org/commits{/sha}","git_commits_url":"https://api.github.com/repos/nodejs/nodejs.org/git/commits{/sha}","comments_url":"https://api.github.com/repos/nodejs/nodejs.org/comments{/number}","issue_comment_url":"https://api.github.com/repos/nodejs/nodejs.org/issues/comments{/number}","contents_url":"https://api.github.com/repos/nodejs/nodejs.org/contents/{+path}","compare_url":"https://api.github.com/repos/nodejs/nodejs.org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nodejs/nodejs.org/merges","archive_url":"https://api.github.com/repos/nodejs/nodejs.org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nodejs/nodejs.org/downloads","issues_url":"https://api.github.com/repos/nodejs/nodejs.org/issues{/number}","pulls_url":"https://api.github.com/repos/nodejs/nodejs.org/pulls{/number}","milestones_url":"https://api.github.com/repos/nodejs/nodejs.org/milestones{/number}","notifications_url":"https://api.github.com/repos/nodejs/nodejs.org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nodejs/nodejs.org/labels{/name}","releases_url":"https://api.github.com/repos/nodejs/nodejs.org/releases{/id}","deployments_url":"https://api.github.com/repos/nodejs/nodejs.org/deployments","created_at":"2015-06-19T11:05:10Z","updated_at":"2017-11-21T12:18:58Z","pushed_at":"2017-11-20T23:16:28Z","git_url":"git://github.com/nodejs/nodejs.org.git","ssh_url":"git@github.com:nodejs/nodejs.org.git","clone_url":"https://github.com/nodejs/nodejs.org.git","svn_url":"https://github.com/nodejs/nodejs.org","homepage":"https://nodejs.org","size":43236,"stargazers_count":612,"watchers_count":612,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":932,"mirror_url":null,"archived":false,"open_issues_count":54,"forks":932,"open_issues":54,"watchers":612,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nodejs/nodejs.org/pulls/1478"},"html":{"href":"https://github.com/nodejs/nodejs.org/pull/1478"},"issue":{"href":"https://api.github.com/repos/nodejs/nodejs.org/issues/1478"},"comments":{"href":"https://api.github.com/repos/nodejs/nodejs.org/issues/1478/comments"},"review_comments":{"href":"https://api.github.com/repos/nodejs/nodejs.org/pulls/1478/comments"},"review_comment":{"href":"https://api.github.com/repos/nodejs/nodejs.org/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nodejs/nodejs.org/pulls/1478/commits"},"statuses":{"href":"https://api.github.com/repos/nodejs/nodejs.org/statuses/1bc444afff79c4dfdeefce3ff35676c76387009b"}},"author_association":"NONE"}}
{"actor":{"display_login":"davisjam"}}