Node.js & Development Framework(1) – Node.js

One day, someone introduced me  a framework easy for Full Stack development.

Isn’t it good? Say frankly, it’s somewhat so tough to building, customizing & tuning OS / WAS?

The names are Node.js & other related framework

Let’s start with Node.js

  • Wiki:

Let me begin with some good points of Node.js

  • Threading –  Unlikely existing WAS, Node.js usesSingle Threading based on non-blocking I/O call. Basically, Node.js is structured of  Event Driven, Among Subject(main object)-Observer(dependents), automatically they share the state change by calling method like  Notify() (Observer Pattern).  Traditional WAS like Tomcat uses thread pool by Time division Multithreading to share the CPU resources. This causes cost of Context Switching to run the thread one by one, in the other hand, Single Threading doesn’t. Instead, to maintain high concurrency, any function performing I/O must call a callback  (Instead of Context Switching , single event loop returns thread back by calling callback). To the non blocking asynchronous I/O, libuv library with fixed size of thread pool has responsibility for that. On the other, Node.js depends on the additional modules like cluster, StrongLoop Process Manager or pm2 to utilize the increased resources vertically(more CPU cores) due to the single thread structure. 
    However, developers can increase the default number of threads in the libuv threadpool; these threads are likely to be distributed across multiple cores by the server operating system 
    The parallel tasks in Node.js are managed by thread pool, tasks threads are pulled and executed. Non-blocking tasks like networking are translated to non-blocking I/O in kernel-level  and executed but like file I/O, blocking tasks run in blocking way in its own thread. Each thread notify to the main thread by  calling callback when the task is completed. These callbacks are handled in serial,long lasting computations and other CPU-bound tasks will freeze the entire event-loop until completion.
    (Does this cause event lock??)
  • V8 – To reduce the cost to run JS(ECMA Script) by interpreting , V8 engine developed by C++ compiles to the Native Code to increase the performance. Google had made. for Chrome browser. (Like Jit compiler in JVM)
  • Unified API -Node.js can be combined with a browser, a database supporting JSON data (such as PostgresMongoDB or CouchDB) and JSON for a unified JavaScript development stack. With the adaptation of what were essentially server-side development patterns like MVC, MVP, MVVM, etc., Node.js allows the reuse of the same model and service interface between client-side and server-side..
    (Searching the implementation, it easily figured out that the server-side biz logic & typescript are integrated organically, easy to reuse)
  • Event loop – This mentioned already in the topic “thread” above, each connection is handled by event loop with the callback issued by OS (that’s why node.js is registered in OS), not by relatively heavy OS or thread, the size of heap allocation is small and instead of defining callback but server enters event loop at the end of callback definition automatically, event loop is exit, no need to define callback explicitly. No further callback is required.


572 total views, 1 views today

Leave a Reply