19. NODE IS EVENT DRIVEN
$ ab –n 200 -c 50 http://localhost:8080/
20. NOW IN RUBY
require 'rubygems'
require 'mongrel'
class HelloWorldHandler < Mongrel::HttpHandler
def process(request, response)
sleep a2
response.start(200) do |head,out|
head["Content-Type"] = "text/plain"
out.write(“Hello World”)
end
end
end
h = Mongrel::HttpServer.new("127.0.0.1", "1337")
h.register("/", HelloWorldHandler.new)
h.run.join
$ ab –n 200 -c 50 http://localhost:1337/
21. EVENT DRIVEN VS THREADING
Lets compare Event Driven Programming
& Thread based programming!!!
• Some theory proves Threading model is better
• Some proves Event Driven Programming is better
22. EVENT DRIVEN VS THREADING
Lets take an example that is
relevant to us!!!
25. APACHE VS NGINX
The difference?
Apache uses one thread per
connection.
NGINX doesn’t use threads. It uses
an event loop
26. Disadvantages of Threading
• Context switching is not free
• Execution stacks take up
memory
• For massive concurrency,
cannot use an OS thread for
each connection.
27. AGENDA
• About Node.js
• Programming in Node.js
Web Frameworks
• Node.js internals
• Popularity of Node.js
• Downside of Node.js
38. ABOUT V8
• V8 team is led by Lars Bak
• Lars Bak was the technical lead behind HotSpot (Sun’s
Java VM).
• HotSpot improved Java’s performance 20x times
• Before HotSpot Lars Bak worked on a Smalltalk VM
• V8 uses hidden classes
44. AGENDA
• About Node.js
• Programming in Node.js
• Web Frameworks
• Node.js Internals
• Popularity of Node.js
• Downside of Node.js
45. NODE.JS ADVANTAGES
• Server side Javascript
• Javascript is dynamic
• Event based
• Learning curve is less
• Suited for event driven programming
• Uses V8 which relatively faster
• Uses CommonJS module spec
53. AGENDA
• About Node.js
• Programming in Node.js
• Web Frameworks
• Node.js Internals
• Popularity of Node.js
• Downside of Node.js
54. NODE.JS COMPLAINTS
• Programmers are used to synchronous code
• Exceptions are hard to handle
• Difficult to debug
• Most importantly it is not matured yet
• Doesn’t utilize multi-core CPU