<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>E ciency Evaluation of Node.js Web-Server Frameworks</article-title>
      </title-group>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>ITMO University</institution>
          ,
          <addr-line>Saint Petersburg</addr-line>
          ,
          <country country="RU">Russia</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>This article deals with the problem of choice of tools on the JavaScript-based platform Node.js. The platform is aimed at solving a wide range of tasks which include web applications development. That could be done with bare platform modules but to increase development speed and reduce the number of errors an additional layer of abstraction over the network interfaces of the platform is used in the form of small libraries and frameworks. However selecting the right framework often takes a lot of time. That is so because the Node.js ecosystem introduces a great variety of such solutions from independent developers. Thus a huge problem arises: application developers should make a lot of researches on the existing frameworks. This study partly solves that problem in several steps. First, this article presents a classi cation of frameworks by type for their clustering. Then, the performance of frameworks is obtained but it is not measured directly because such benchmark cannot be examined on the frameworks themselves. Therefore a template application is introduced and implemented on each framework. Consequently all the systems are stress tested. As a result of the study, the measurements and conclusions on them are suggested. Obtained measurements could be applied in a form of a basis for further researches or use recommendations for developers.</p>
      </abstract>
      <kwd-group>
        <kwd>JavaScript classi cation</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>REST
This article is devoted to the Node.js server frameworks performance study
represented by the example of simple web applications which implement REST
(Representational State Transfer) API (Application Programming Interface). The
main goals are forming frameworks' e ciency rank of and also nding
recommendations for these frameworks usage. In order to achieve these aims several
steps are required which are: determine framework types; choose application
model and de ne minimal set of modules; select optimal productivity criterion.</p>
      <p>Copyright c 2019 for this paper by its authors. Use permitted under Creative
Commons License Attribution 4.0 International (CC BY 4.0).</p>
      <p>REST architecture design template is in high demand for many years. At
the present time it makes integral part of single page, mobile applications and
micro services server side organization. Particularly it is essential for this kind
of applications to be constructed with restricted amount of resources and more
importantly without implantation of bulky technologies. However, to increase
the development speed and reduce the number of errors, an additional layer of
abstraction over the network interfaces of the language is used. These are small
libraries and frameworks, which will be discussed later on the Node.js example.</p>
      <p>
        Building a RESTful API can be performed using a variety of languages and
platforms for compiling and launching them. And yet Node.js pick is a common
way to solve this task due to some features, namely asynchronous requests
handling based on an event generation, the so-called event-driven runtime [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]: each
request emits an event that enters the processing queue and then Node.js
completes the response when it has execution time. This avoids process blocking and
excessive memory usage. Furthermore this method di ers from the more known
concurrency model where operating system threads are involved and a unit of
RAM is allocated for each request which can lead to memory over ow.
      </p>
      <p>Therefore Node.js platform is a su cient tool for developing REST systems
but thus a more specialized problem of creating applications arises that is the
choice of an appropriate framework. This issue appeared because originally, when
the platform just started its evolution, there was no large suitable framework for
implementing any complexity applications. As a result, independent developers
created their own solutions on a basis of Node built-in modules. Consequently,
nowadays the platform ecosystem has a large number of libraries and frameworks
for building web applications that overlap in capabilities or have only minor
differences. This problem forces developers of nal products to constantly conduct
their own researches on that topic in order to identify suitable frameworks. The
article aims to simplify this kind of search.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Framework types</title>
      <p>Initially it is required to identify types of frameworks since structural features
of the framework a ect many parameters of a future application including
potential size, complexity and scalability. For further research small libraries or
frameworks that have the minimal necessary functionality to form a REST
application are preferred.</p>
      <p>
        The following types of frameworks by usage purpose are de ned:
1. HTTP server library is a set of functions that grant the ability to build
applications based on them; due to the fact that these libraries allow to
organize web systems, they belong to the class of frameworks, but they are
not completely such [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ].
2. API framework is a set of functions which is a skeleton for developing an
application that can be accessed via a speci c syntax interface.
3. HTTP server framework is an extension of the HTTP library forming an
additional layer of abstraction over HTTP commands and also providing a
frame of a server organized by such functions [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ].
4. MVC framework is a framework that is used to create applications based
on the MVC (Model-View-Controller) pattern; this architecture determines
how the application will be built.
      </p>
      <p>
        At the rst stage of the study Fastify developers and TechPower researches [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]
on determining the frameworks performance were explored. Then repositories
containing the code of libraries and frameworks in the Node.js ecosystem were
investigated. Table 1 summarizes these analyses and includes GitHub rating,
which was obtained at the time of writing, as it represents how often these
frameworks are applied in projects. Rates are shown in brackets next to the names of
the frameworks and are measured in thousands. The types of frameworks, their
possible utilization, advantages and disadvantages are also revealed.
      </p>
      <p>
        On the basis of frameworks documentation and their description, the most
suitable frameworks for comparing performance based on REST applications are
listed below [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]:
1. Express is the most famous framework of the Node.js platform which was
edited and reissued for a plenty of times; on its basis both simple APIs
and large applications are built; it is also often the foundation for other
frameworks, for example Nest.
2. Restify is a framework for organizing the right RESTful services, the syntax
and construction of which is similar to Express by design.
3. Loopback is a large project that has currently moved to the fourth iteration,
which has its own engine, automatic API generation and native support for
Typescript.
4. Fastify is considered as the fastest framework for developing applications on
      </p>
      <p>Node.js.
5. Koa is a framework with an intentionally minimal set of functions, modular
form and a new request transfer through middlewares unlike Express.
6. Hapi is a framework with built-in functionality that allows to develop any
applications expandable by Hapi's plugins.
7. Sails is a popular MVC framework that imitates a framework like Ruby on</p>
      <p>Rails but focuses on the informational API and service architecture.
8. Nest is Typescript-based framework that combines object-oriented and
functional application structures, is an abstraction over Express or Fastify
depending on the choice of the developer; it allows building both simple APIs
and large applications.
3</p>
    </sec>
    <sec id="sec-3">
      <title>REST API application template</title>
      <p>The problem of comparing the quantitative characteristics of frameworks arises
because all frameworks di er in built-in functionality, organization of interaction
with requests, creation of a requests queue, extension libraries. In order to unify
the task of performance measuring, in this study it is proposed to introduce a
general application template that will be implemented with di erent frameworks
but which will provide a standard functionality.</p>
      <p>REST API applications are in most cases used to provide clients with remote
resources. In this study the system is de ned which organizes the CRUD (Create,
Read, Update, Delete) process for the application log. Also it is necessary to add
static les middleware for subsequent performance measurements on requests for
the formatted text and les.</p>
      <p>The application state management should be taken into account as well.
Although the REST architecture implies an absence of storage for client states,
session information or a websocket may be in need for storing during data
transfer to the client. In this case, the types of these applications are distinguished:
with a state where this kind of data is stored in a running application, and
without state where such information is stored in special repositories, for example,
Redis.</p>
      <p>Node.js frameworks have a similar structure, so the application composition
can be pre-determined as:
1. Logger is a middleware which saves the information about requests.
2. Bodyparser is a module that selects a request body which is required for</p>
      <p>Create and Update operations.
3. Logger is a middleware which saves the information about requests.
4. Static handler is a middleware issuing static les from the public directory.
5. Application state storage.
6. Router which processes the requested paths for further the task allocation
to functions; in this application should include:
(a) Path for index.html.</p>
      <p>(b) Paths that form CRUD operations, in other words application APIs.
7. Log storage middleware for the json le.
8. The errors handler which were generated along the request processing, for
example, 404 Bad Request or 500 Internal Server Error.</p>
    </sec>
    <sec id="sec-4">
      <title>Performance measurement plan</title>
      <p>Application e ciency is characterized by a large number of its parameters
including the technology's e ectiveness, the architecture organization accuracy,
resistance to external loads and so forth. Therefore it is necessary to adhere to
a uniform approach of metering.</p>
      <p>There are two approaches in the system performance testing. The rst one
is simulating a workload by means of arti cial scenarios of the application's
utilization. The second one is beta testing which is carried by end users. In this
work the simulating approach was selected since it allows controlling each round
of tests and varying measurement parameters.</p>
      <p>
        Moreover there are several types of performance testing that web applications
may be brought to, which are presented below [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]:
1. Load testing is a performance assessment which is done by the exterior
system that makes repeated transactions to the application. This method
permits to quickly identify application's bottlenecks and present its operating
quality.
2. Stress testing is a subtype of the load testing which di ers from it in the
kind of evaluation: stress testing is carried in the application's conditions
that exceed its limits of the normal functioning.
3. Stability testing is a kind of load testing that is conducted in the long period
of time in order to detect running stability of the application.
      </p>
      <p>In this paper, the load testing approach was chosen as the most reproducible
way of the performance determining for di erent applications. Stress testing and
stability testing to a greater extent show the fault tolerance of web applications
but not their quantitative e ciency parameters.</p>
      <p>
        It is important to indicate that Node.js processes originally run on one
core [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], however a special platform module can be implemented to use several
cores. Due to the fact that all frameworks are launched on a single platform,
their behavior on one core could be extrapolated to several cores. Testing was
carried out on the equipment, characteristics of which are presented below:
1. CPU: Intel Core i5-4200U CPU @ 1.60GHz 2.30GHz.
2. OS: Ubuntu 18.04 x64.
3. 8 GB RAM.
4. 128 GB SSD ROM.
5. Node 12.13.1.
      </p>
      <p>It should be noted that there are several basic metrics of the application
undergoing stress testing, namely: consumed processor time and RAM units,
the disk subsystem usage, processed number of requests per time unit, response
time. This study is focused on determining characteristics that are irrespective
of the physical platform and can be measured both on the application side and
on the client. Thus selected application parameters are processed requests per
second and the application response time in milliseconds.</p>
      <p>
        Moreover there are universally recognized tools for measuring performance.
In this research it is suggested to use the same platform for testing system
as for creating applications and utilize performance measurement tools which
are available for Node.js. One of the most popular load testing utility on this
platform is AutoCannon [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] which imitates client connections and follows some
actions scenario for them.
5
      </p>
    </sec>
    <sec id="sec-5">
      <title>Results</title>
      <p>Further the created systems were benchmarked in order to detect the most e
ective framework. Several tests have been conducted simulating clients connections
to the application. The measurements started from 25 connections and ended
with 1000 by the increment of 25 connections. In order to combine previously
selected load testing metrics for a better representation, this study proposes to
divide the number of processed requests by the response time. The results of the
measurements are presented in Figure 2.</p>
      <p>The graph depicts that the best results are shown by modular frameworks
Fastify and Koa, while the slowest ones are large frameworks Loopback and
Hapi. The chart also displays that after about 300 connections, a sharp decrease
of the frameworks performance becomes more gradual. Thus for this research
testing stand 300 connections is the most optimal criterion and therefore Table 2
presents the framework characteristics for this round of tests.</p>
      <p>Proceeding from the data which was obtained during the applications
creation and their testing, the following frameworks and libraries usage
recommendations are formulated:
6</p>
    </sec>
    <sec id="sec-6">
      <title>Conclusion</title>
      <p>In this article types of frameworks were selected to classify these frameworks in
accordance with their purpose. For each type, representatives were identi ed as
well as its features in the form of advantages and disadvantages. Due to the fact
that abstract frameworks load testing execution is extremely di cult without an
existent application, a template of the REST system was introduced and then
implemented on all frameworks. Finally all applications were benchmarked with
Node.js tool and use cases were proposed based on the frameworks classi cation
as well as on the carried load testing.</p>
      <p>The study can be used as the foundation for further researches or for the
initial choice of web project framework.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1. Node.js About, https://nodejs.org/en/about.
          <source>Last accessed 10 Nov</source>
          <year>2019</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Cantelon</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Harter</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Holowaychuk</surname>
            ,
            <given-names>T. J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Rajlich</surname>
          </string-name>
          , N.:
          <source>Node. js in Action. 2nd edn. Manning</source>
          ,
          <string-name>
            <surname>Greenwich</surname>
          </string-name>
          (
          <year>2017</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>TechPower</surname>
          </string-name>
          <article-title>'s web framework benchmarks</article-title>
          , https://www.techempower.com/benchmarks/.
          <source>Last accessed 25 Nov</source>
          <year>2019</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4. Loopback frameworks comparison, https://loopback.io/lb3/resources.
          <source>Last accessed 21 Nov</source>
          <year>2019</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Matam</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Jagdeep</surname>
            ,
            <given-names>J.. Pro</given-names>
          </string-name>
          <string-name>
            <surname>Apache</surname>
          </string-name>
          <article-title>JMeter: web application performance testing</article-title>
          .
          <source>Apress</source>
          ,
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6. Benchmarking tool AutoCannon, https://github.com/mcollina/autocannon.
          <source>Last accessed 30 Nov</source>
          <year>2019</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>