Evolution of Server-Side Java Script
Join the DZone community and get the full member experience.Join For Free
Many rich internet application and highly concurrent application like online game, collaboration tools and chat engines are common in recent years. On the server side, there should be a listener to process the request, manipulate them and send back to the client. The data will be transferred in the form of XML, JSON and HTML between the client and server. There are variety of frameworks for the server side to process the request and do manipulation in Java, DOT net and etc. But for the highly concurrent applications, to take care of the COQ parameter, it is necessary to choose the better web servers / hardware. The developers who are expert in java script are not fully utilized and they need to hire a different skill set of people to work on those applications.
There is a need for simple framework for highly scalable, high performance, high quality and quick to build web applications. And there is a need to use a single programming language for both client and server. So to solve all these problems, ‘Server side java script’ (SSJS) evolved in market, which uses java script in the server side too and which provides good scalability and performance for the highly concurrent applications.
In the earlier days of the web, server-side scripting was almost exclusively performed by using a combination of C programs, Perl scripts, and shell scripts using the Common Gateway Interface (CGI). Those scripts were executed by the operating system, and the results were served back by the web server. Many modern web servers can directly execute on-line scripting languages such as ASP and PHP by the web server itself.
Difference between SSJS and CSJS
The Server side java script is different from client side java script (CSJS), the later gets downloaded to browser, but the former is not. The user has access to the code received by CSJS, but the source code is hidden wrt to SSJS.
History of Server side java script Engines
In the later 1990, the first implementation of SSJS engine was from Netscape, called as Live wire. Later this Netscape transformed into Mozilla team, focused more on SSJS and they come with an engine called Trace Monkey. This Trace monkey boost the performance of java script by 20 to 40 times. Later in market, there are many Java script engines from different vendors such as, V8 from Google, Squirrel fish from web kit, Jscript from Microsoft and Rhino, Spider monkey, Common JS from the Mozilla.
Out of the above, the V8, Rhino and Spider monkey are the popular in the market. Let us see a brief over view of the same:
Rhino is a SSJS engine, which is written in Java. Rhino compiled all java script code to java byte code. Rhino works in both compiled as well as interpreted mode. But it faces two challenges as, compile time was long, since generating byte code and loading the generated classes was a resource intensive process.
Spider Monkey is a SSJS engine written in C. It provides java script support for Mozilla firefox. It contains an interpreter, JIT compiler and garbage collector. The Spider Monkey to be used in the Java script shell.
The V8 Java script engine is an open source Java script engine developed by Google for Chrome browser. The first of engine was released on 2008. V8 complies Java script to native machine code before executing it, instead of more traditional techniques such as interpreting byte code or compiling the whole program to machine code and executing it from a file system.
Jscript is Microsoft’s dialect of the EMCA script standard that is used in IE browsers. Jscript is implemented as an Active scripting engine. Jscript was first supported in IE 3.0, now the recent version is Jscript 9.0 in Internet explorer 9.
SSJS Frameworks provide an API to work on the server side java scripts. They will get executed inside the SSJS Engines. Some of the popular frameworks available in the market are Node JS based on V8, Ringo JS based on Common JS, Narwhal based on Common JS, ASP based on JScript, Wakanda based on Squirrel fish.
So let us see, some of the important features of Node JS.
The promised ‘High-scalability’ is quite comprehensively achieved using Node.js because of its following features:
In traditional web server technologies we have, every new connection (or request) remains alive until the connection is closed, which actually means, that the server would be waiting for highly time-consuming events like I/O or database transactions. The connection remains open until the operation is completed. This is called “Blocking I/O”. To make such a webserver scalable, multiple ‘copies’ of the server is required – referred to as ‘thread-based’ webservers. The event-driven model of Node.js receives the request, delegates the work to be handled by its other ‘components’ and then resumes back to receive the next request. When the original request is completed, it is put back into the processing queue, and when its turn comes for processing, the response is sent back. This is called ‘Non-blocking I/O’ as the webserver does its job of receiving requests and sending back responses and not waiting for I/O, thus making it highly scalable.
The fact that the server manages with a single OS thread for all requests, and how non-blocking I/O has been incorporated inside Node.js proves how suitably it has been developed aiming at obtaining maximum concurrency and scalability.
Simple & Lightweight
Usage of SSJS in some of the popular project / products
|Alfresco||Rhino||Java servlet container / standalone|
|Couch DB||Spider Monkey||Standalone|
Rewards of using SSJS framework
Major firms are reporting that switching to SSJS frameworks on their servers has boosted back-end performance and streamlined server-side development. After swapping to SSJS frameworks, various companies found themselves able to respond to larger numbers of requests with fewer servers and serve content more rapidly. Some of the examples are:
a. Deals website Groupon has been using node.js servers to handle 50,000 requests a minute from US users.
b. Retail giant Walmart said node.js servers drove 53 percent of all of its online traffic during the recent Black Friday sales in the US.
c. Yahoo has been using node services to handle around between 1,680,000 and 2,000,000 requests per minute.
d. PayPal is moving every one of its products and sites to node.js and by the end of 2014 hopes to have all "major experiences" redesigned, and rewritten for the platform
Opinions expressed by DZone contributors are their own.