Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
remove refs to PR and percent gain
  • Loading branch information
jrit committed Mar 17, 2016
commit d215d635810983f36e2db95d90be277c40d7c896
13 changes: 5 additions & 8 deletions doc/topics/blocking-vs-non-blocking.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ fs.readFile('/file.md', (err, data) => {
The first example appears simpler than the second but has the disadvantage of
the second line **blocking** the execution of any additional JavaScript until
the entire file is read. Note that in the synchronous version if an error is
thrown it will need to be caught or the process will crash. In the asynchronous version, it is up to the author to decide whether an error should throw as
thrown it will need to be caught or the process will crash. In the asynchronous
version, it is up to the author to decide whether an error should throw as
shown.

Let's expand our example a little bit:
Expand Down Expand Up @@ -93,14 +94,12 @@ occurring.
As an example, let's consider a case where each request to a web server takes
50ms to complete and 45ms of that 50ms is database I/O that can be done
asychronously. Choosing **non-blocking** asynchronous operations frees up that
45ms per request to handle other requests. This is an effective 90% difference
in capacity just by choosing to use **non-blocking** methods instead of
45ms per request to handle other requests. This is a significant difference in
capacity just by choosing to use **non-blocking** methods instead of
**blocking** methods.

The event loop is different than models in many other languages where additional
threads may be created to handle concurrent work. For an introduction to the
event loop see [Overview of the Event Loop, Timers, and
`process.nextTick()`](https://github.com/nodejs/node/pull/4936)
threads may be created to handle concurrent work.


## Dangers of Mixing Blocking and Non-Blocking Code
Expand Down Expand Up @@ -141,6 +140,4 @@ The above places a **non-blocking** call to `fs.unlink()` within the callback of
## Additional Resources

- [libuv](http://libuv.org/)
- [Overview of the Event Loop, Timers, and
`process.nextTick()`](https://github.com/nodejs/node/pull/4936)
- [About Node.js](https://nodejs.org/en/about/)