background preloader

Node.js

Facebook Twitter

Node.js. Node.js is an open source, cross-platform runtime environment for server-side and networking applications.

Node.js

Node.js applications are written in JavaScript, and can be run within the Node.js runtime on OS X, Microsoft Windows, Linux, FreeBSD, NonStop and IBM i. Node.js provides an event-driven architecture and a non-blocking I/O API that optimizes an application's throughput and scalability. These technologies are commonly used for real-time web applications. Node.js is gaining adoption as a server-side platform[4] and is used by Microsoft,[5][6] Yahoo! ,[7] Walmart,[8] Groupon,[9] SAP,[10] LinkedIn,[11][12] Rakuten, PayPal,[13][14] Voxer,[15] and GoDaddy.[16] History[edit] Ryan Dahl, creator of Node.js Node.js was invented in 2009 by Ryan Dahl, and other developers working at Joyent.[17] Node.js was created and first published for Linux use in 2009. Memory management. Several methods have been devised that increase the effectiveness of memory management.

Memory management

Virtual memory systems separate the memory addresses used by a process from actual physical addresses, allowing separation of processes and increasing the effectively available amount of RAM using paging or swapping to secondary storage. The quality of the virtual memory manager can have an extensive effect on overall system performance. Dynamic memory allocation[edit] An example of external fragmentation Details[edit] The task of fulfilling an allocation request consists of locating a block of unused memory of sufficient size. Context switch. Cost[edit] When to switch?

Context switch

Debugging Node.js in Production. By Kim Trott, Yunong Xiao We recently hosted our latest JavaScript Talks event on our new campus at Netflix headquarters in Los Gatos, California.

Debugging Node.js in Production

Yunong Xiao, senior software engineer on our Node.js platform, presented on debugging Node.js in production. Yunong showed hands-on techniques using the scientific method to root cause and solve for runtime performance issues, crashes, errors, and memory leaks. We’ve shared some useful links from our talk: Event-driven programming. Event handlers[edit] Main article: Event handler A trivial event handler[edit] Because the code for checking for events and the main loop do not depend on the application, many programming frameworks take care of their implementation and expect the user to provide only the code for the event handlers.

Event-driven programming

In this simple example there may be a call to an event handler called OnKeyEnter() that includes an argument with a string of characters, corresponding to what the user typed before hitting the ENTER key. To add two numbers, storage outside the event handler must be used. Globally declare the counter K and the integer T. While keeping track of history is straightforward in a batch program, it requires special attention and planning in an event-driven program.

Asynchronous I/O. Input and output (I/O) operations on a computer can be extremely slow compared to the processing of data.

Asynchronous I/O

An I/O device can incorporate mechanical devices that must physically move, such as a hard drive seeking a track to read or write; this is often orders of magnitude slower than the switching of electric current. For example, during a disk operation that takes ten milliseconds to perform, a processor that is clocked at one gigahertz could have performed ten million instruction-processing cycles.

A simple approach to I/O would be to start the access and then wait for it to complete. But such an approach (called synchronous I/O or blocking I/O) would block the progress of a program while the communication is in progress, leaving system resources idle. When a program makes many I/O operations, this means that the processor can spend almost all of its time idle waiting for I/O operations to complete. Asynchronous I/O is used to improve throughput, latency, and/or responsiveness.

Jump up ^ Closure (computer programming) Example.

Closure (computer programming)

The following program fragment defines a higher-order function startAt with a parameter x and a nested function incrementBy. The nested function incrementBy has access to x, because incrementBy is in the lexical scope of x, even though x is not local to incrementBy. The function startAt returns a closure containing the function incrementBy, which adds the y value to the x value, and a reference to the variable x from this invocation of startAt, so incrementBy will know where to find it once invoked: function startAt(x) function incrementBy(y) return x + y return incrementBy variable closure1 = startAt(1) variable closure2 = startAt(5) Note that, as startAt returns a function, the variables closure1 and closure2 are of function type. Def f(x): def g(y): return x + y return g def h(x): return lambda y: x + y a = f(1)b = h(1)f(1)(5)h(1)(5) Note especially that the nested function definitions are not themselves closures: they have a free variable, which is not yet bound.