5. One Process per User Request
[Operating System Processes, Threads, Semaphores, Mutexes and Barriers,
are the scheduling mechanisms to acquire the time slices of the CPU. The
Processes are expensive and consume more resources than Threads]
6. Drawbacks:
▪ The CGI script interpretation (compile + execution)
happens at the request processing time.
▪ One user request spawns one Process, locking all the
allocated resources even though request processing
might not need it.
▪ The CGI spawned Process is outside the Web Server
control.
14. JEE Request-To-Thread
Request 1
Application Server
Thread 1
Spring
DispatcherServlet
Thread 2
Request 2
JSF FacesServlet
Struts ActionServlet
Thread .. n
Request .. n
One Servlet instance on the App Server
spawns a new thread for each user request
15. Drawbacks:
▪ One thread per user request locks the resources
allocated to the thread at the time (wait) of I/O
operations.
▪ Context-switching between threads are expensive.
23. ▪It takes around 41 million cycles to do a
disk I/O.
▪For a network call 240 million cycles ….
“Understanding Node Event-Loop” – Must read excellent blog post from Mixu.
24. ▪Swim into the micro millisecond
world.
▪Everything in the multi-threaded
server is …..
26. ▪While the user request is waiting for an
I/O operation, the 3rd generation platforms use
Non-Blocking I/O based call-backs managed by
an Event-Loop and the Thread will move on to
the next request.
▪The whole thing happens so fast that one
Thread will be able to respond to multiple user
requests.
29. Unbelievable Concurrency ?
▪ Assuming each thread has 2 MB of
memory running on 8 GB of RAM puts it at a
theoretical maximum of 4000 concurrent
connections, plus the cost of context-switching
between threads.
▪ That’s the scenario you typically deal with in
traditional web-serving techniques. By avoiding all
that, Node.js achieves scalability levels of over
1Million concurrent connections
(as a proof-of-concept).
30. The 3rd generation platforms use the
combination below to efficiently utilize the OS
resources.
Single Thread
Non-Blocking I/O
Event Loop
31. Node.js
▪ Platform based Server-side JavaScript
▪ Event-Driven Concurrency Model
▪ Use single thread and non-blocking I/O
▪ JSON and JavaScript are practically siblings
that translate to Nodes
▪ JavaScript is a dynamically typed language
▪ Real-time web applications employing server-side
push and two-way connections where server and
client can initiate communication
▪ I/O Operations executed in parallel but not the
code
33. Node.js makes it an excellent choice
for I/O based Applications.
What are I/O based Applications?
Applications which connect to databases, make web service calls, use files for logging
and make connections to MQ, Mail & LDAP servers.
34. Node.js is not a good choice for
CPU intensive Applications.
(Node pundits argue that CPU intensive components should be evented and
passed onto another thread)
What are CPU intensive Applications?
Applications which does lot of data processing on the App server and complex
calculations which need more CPU time.
35. Node.js itself is not Non-Blocking
function getAge(user_id) {
sql = 'SELECT age FROM users WHERE id = ' + user_id;
connection.query(sql, function(err, rows, fields) {
if (err) throw err;
return rows[0].age;
});
return 0;
}
[The above database call code will starve the thread and node
will not respond to other users]
36. Below Node.js code will unblock I/O and
respond to other users
function getAge(user_id, callback) {
sql = 'SELECT age FROM users WHERE id = ' + user_id;
connection.query(sql, function(err, rows, fields) {
if (err) throw err;
var age = rows[0].age;
callback(age);
});
}
[The above database call code uses callbacks and unblock
the I/O]
37. Programming for Node.js requires clear
understanding of:
▪Asynchronous code
▪Event-Driven
▪Non-Blocking I/O
▪Callbacks and Promises
38. Who is using Node.js ?
Paypal, LinkedIn, eBay,
Yahoo, Walmart ……………
http://nodejs.org/industry/
39. Node.js does not frameworks ?
Ever growing list of presentation, data
persistence and many more
frameworks ……………
http://nodeframework.com/
40. With the ever growing cost of hardware, power
to cool them and long maintenance cycles ….
How long will enterprises withstand the
temptation of
rd
3 Generation Platform ?
41. Disclaimer:
The views and opinions expressed in this article are those of the author.
The metrics and numbers used in this presentation are from the open
blogs which are not validated. This is a technical presentation which
will make you think about the new platform options in the technology.