Node.js 0.8 features

1,818 views

Published on

This meetup I will go over all the new and improved features in Node v0.8. There was a lot included in 0.8 so I hope to share some examples of what has been added and how can you use this new stuff in your own node projects.

Topics I covered -
Performance improvements!
Domain Module!
Cluster Module!
Basic API changes

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,818
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Node.js 0.8 features

    1. 1. Node Version 0.8.x What’s new in Node?http://www.meetup.com/Pittsburgh-Node-js/
    2. 2. NicholasDeveloperUX Designer & McClay @nickmcclay
    3. 3. Speed Improvementshttp://blog.nodejs.org/2012/06/25/node-v0-8-0/
    4. 4. How much faster is it?!?! A.) 1% B.) 10% C.) 50% D.) 100%
    5. 5. Ehh... its not really clear...Somewhere between 1% and 10% as far as I can tell...
    6. 6. A note about benchmarking nodeRemember it’s “./node”Huge deviation in repeated tests (3829 - 6462 #/sec)Node 0.4.x has issues running io.js (constant duration)
    7. 7. Write Speed Improvements 0.8 0.6 500 375Write 1MB 250 125 0 1kb 4kb 8kb 16kb 32kb 64kb
    8. 8. Read Speed Improvements 0.8 0.6 400 300Read 1MB 200 100 0 1kb 4kb 8kb 16kb 32kb 64kb
    9. 9. HTTP Server Improvements 0.8 0.6 0.4 6000 4500Serve “Hello World!” 3000 1500 0 #/Sec
    10. 10. Uh... Apache Bench? 0.8 0.6 0.4 2500100000 total requests 1875100 concurrent requests 1250 625 0 #/Sec
    11. 11. API Changes
    12. 12. Deprecatedhttp.Client()path.{exists,existsSync} -> fs.{exists,existsSync}tty.setRawMode(mode) -> tty.ReadStream#setRawMode()direct usage of ev_* and eio_*, should use uv_*
    13. 13. Removedwaf build system -> gyprequire(‘sys’) -> require(‘util’)process.installPrefixnode --vars
    14. 14. Lots more changes and additions process • buffer ◦ process.stdin.on(keypress) will not be emitted by default, as its an internal API. Use the keypress module now. ◦ utf16le encoding. ◦ process.stdin.pipe(dest) will automatically call process.stdin.resume(). • child_process• cluster ◦ silent option to child_process.fork() - stdout and stderr wont be shared with parent. ◦ cluster.fork() no longer return a child_process.fork() object use cluster.fork().process to get the object. ◦ .disconnect() when using child_process.fork() this will allow the child to die gracefully. ◦ the death event on the cluster object is renamed to exit. ◦ stdio option for child_process.spawn() - configuration of childs stdio (file descriptors). ◦ the kill() method is renamed to destroy(). ◦ detached option for child_process.spawn() - make the child a process group leader (see docs) ◦ the CLUSTER_WORKER_ID env is now called CLUSTER_UNIQUE_ID, but you should not have used that anyway. ◦ child.send() can now send net.Server and net.Socket as second argument. ◦ workers now kill themselves when they accidentally lose their connection to the master. • cluster• http ◦ fork, online, listening, and setup events. ◦ http.Server emits connect event instead of upgrade when the CONNECT method is requested. ◦ Worker object which is provided from cluster.workers (in the master) or cluster.worker (in the worker). ◦ http.ServerResponse sends Date: header by default. You can disable it by setting response.sendDate to false. ◦ env optional argument to cluster.fork(). ◦ http.ClientRequest emits connect event instead of request when the CONNECT method is responded. ◦ cluster.setupMaster() and cluster.settings.• net ◦ cluster.disconnect() and worker.disconnect(). ◦ net.listen(socketPath) no longer unlinks the socket unless you call server.close(). Automatic unlinking was ◦ worker.id what there before was internally known as workerID. subject to race conditions in multi-process setups. Also applies to http.listen(socketPath). ◦ worker.suicide flag set when worker disconnect or die, indicate if this was an accidental death.• child_process • crypto ◦ arguments and options arguments of child_process.fork() became an option. ◦ crypto.getDiffieHellman(). ◦ the exit event is now emitted right after the child process exits. It no longer waits for all stdio pipes to be closed. ◦ cipher.setAutoPadding() and decipher.setAutoPadding(). ◦ the close event was added that has is emitted after the child has exited and all the stdio pipes are closed. ◦ ciphers option to crypto.createCredentials().• readline • domain ◦ arguments of rl.createInterface became an option as rl.createInterface(options) but still took an old style ◦ see http://nodejs.org/docs/v0.8.0/api/domain.html • fs
    15. 15. Lots more changes and additions process l f: • buffer rse ◦ process.stdin.on(keypress) will not be emitted by default, as its an internal API. Use the keypress module now. ou ◦ utf16le encoding. ◦ process.stdin.pipe(dest) will automatically call process.stdin.resume(). ry • child_process• cluster ad fo wiki/ ◦ silent option to child_process.fork() - stdout and stderr wont be shared with parent. ◦ cluster.fork() no longer return a child_process.fork() object use cluster.fork().process to get the object. re de/ ◦ .disconnect() when using child_process.fork() this will allow the child to die gracefully. ◦ the death event on the cluster object is renamed to exit. Go .com/joyent d-v0.8 /no ◦ stdio option for child_process.spawn() - configuration of childs stdio (file descriptors). ◦ the kill() method is renamed to destroy(). ◦ detached option for child_process.spawn() - make the child a process group leader (see docs) ◦ the CLUSTER_WORKER_ID env is now called CLUSTER_UNIQUE_ID, but you should not have used that anyway. ◦ child.send() can now send net.Server and net.Socket as second argument. ◦ workers now kill themselves when they accidentally lose their connection to the master. • cluster• http git hub 0.6 -an ◦ fork, online, listening, and setup events. n-v ◦ http.Server emits connect event instead of upgrade when the CONNECT method is requested. tps: // wee ◦ Worker object which is provided from cluster.workers (in the master) or cluster.worker (in the worker). ◦ http.ServerResponse sends Date: header by default. You can disable it by setting response.sendDate to false. ht et ◦ env optional argument to cluster.fork(). ◦ http.ClientRequest emits connect event instead of request when the CONNECT method is responded. es-b ◦ cluster.setupMaster() and cluster.settings. ang• net ◦ cluster.disconnect() and worker.disconnect(). I-ch ◦ net.listen(socketPath) no longer unlinks the socket unless you call server.close(). Automatic unlinking was ◦ worker.id what there before was internally known as workerID. AP subject to race conditions in multi-process setups. Also applies to http.listen(socketPath). ◦ worker.suicide flag set when worker disconnect or die, indicate if this was an accidental death.• child_process • crypto ◦ arguments and options arguments of child_process.fork() became an option. ◦ crypto.getDiffieHellman(). ◦ the exit event is now emitted right after the child process exits. It no longer waits for all stdio pipes to be closed. ◦ cipher.setAutoPadding() and decipher.setAutoPadding(). ◦ the close event was added that has is emitted after the child has exited and all the stdio pipes are closed. ◦ ciphers option to crypto.createCredentials().• readline • domain ◦ arguments of rl.createInterface became an option as rl.createInterface(options) but still took an old style ◦ see http://nodejs.org/docs/v0.8.0/api/domain.html • fs
    16. 16. req.pause actually pauses requests
    17. 17. Domainshttp://nodejs.org/api/domain.html
    18. 18. highlightsDomains provide a way to handle multiple different IOoperations as a single group.Keeps context unlike“process.on(‘uncaughtException’)”Disabled by default
    19. 19. An async callback
    20. 20. Without domains
    21. 21. Adding domains
    22. 22. With domains
    23. 23. Clusterhttp://nodejs.org/api/domain.html
    24. 24. highlightsTake advantage of multi-core system to handle loadeasily create a network of processes that share commonportssetup and manage master-slave worker relationshipsDisabled by default
    25. 25. Adding cluster
    26. 26. More cores = more node
    27. 27. Cluster messaging
    28. 28. What about isolates?
    29. 29. Was intended to make child_process.fork() in a thread,rather than a full process.Make it cheaper to spin up new child node instances as wellas fast message-passing using shared memory.
    30. 30. Experiments sometimes fail
    31. 31. Caused too much instabilityRequires a lot of complexity added to libuv and nodeIsn’t likely to yield enough gains as the work requires
    32. 32. What’s next! Node v0.9More speed improvementsMajor overhaul of streams???
    33. 33. @nickmcclaySee you for Node v0.10! Thanks!

    ×