<!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>Optimization of Processing the Large Data Stream in Web-interface</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Nataliya V. Papulovskaya</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Artem A. Rapoport</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Uberall GmbH</institution>
          ,
          <addr-line>Berlin</addr-line>
          ,
          <country country="DE">Germany</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Ural Federal University named after the rst President of Russia B.N.Yeltsin</institution>
          ,
          <addr-line>Yekaterinburg</addr-line>
          ,
          <country country="RU">Russia</country>
        </aff>
      </contrib-group>
      <fpage>113</fpage>
      <lpage>122</lpage>
      <abstract>
        <p>The paper presents description of the problems related to a large amount of data frequently received from a Web-server by the Webinterface causing the insu cient performance of the latest one. A comparative analysis of methods for updating the data in the Web-interface was made, and the optimal method for updating the data in the realtime Web-application was chosen. The paper also provides an example of optimization of data processing using the data bu ering and implementation of this example in the modern JavaScript.</p>
      </abstract>
      <kwd-group>
        <kwd>data processing</kwd>
        <kwd>data bu ering</kwd>
        <kwd>big data</kwd>
        <kwd>Web-interface</kwd>
        <kwd>Webprogramming</kwd>
        <kwd>WebSocket</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>Multiple issues about insu cient performance exist in the modern
Web-applications development. These issues include: slow rst page load because of large
amounts of data; low responsiveness or even freezing of an interface when
updating a lot of data, and others.</p>
      <p>
        Web-applications can store more than 900 GB of data on the server side
(or in a database), for example, the data of the students from all around the
world [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. Therefore, one of the most signi cant problems in the development
of the Web-frontend part in the Web-applications is the low speed of handling
the big data ow sent from the server to the Web-client (the latter most often
being a Web-browser). Implementation of updating the visual data in a
Webclient can be done in di erent ways: update (and re-render) the data only after
a speci c user action; use polling (in this case the Web-client sends requests to
the server with a time interval), or using the network messaging protocol, other
than HTTP (HyperText Transfer Protocol), which would allow the Web-server
and Web-browser to communicate in real-time (e.g. WebSocket) and others [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ].
      </p>
      <p>This research shows the advantages of data updating implementation by
using the Websocket comparing to other implementations of real-time data
Webapplications and the e ciency of using an additional data handling optimization
by application of bu ering.</p>
    </sec>
    <sec id="sec-2">
      <title>Comparison of data updating implementations</title>
      <p>Implementation of updating the visual data in a Web-client can be done by
wellknown HTTP-requests, which are red by some user actions. For instance, this
exact method is used in the search engine of the Google, USA: by pressing the
search button, the user sends HTTP-request to the server, and after some short
period of time, the Web-client receives the response and updates the information
on the page. Listing 1 contains the example of a simple HTTP-request written
in the JavaScript.</p>
      <p>Listing 2-1. HTTP-request example, written in JavaScript
import a x i o s from ' a x i o s ' ; //HTTP r e q u e s t s l i b r a r y
import C l i e n t S t o r e from ' . / C l i e n t S t o r e ' ; // s t o r e o f Web c l i e n t
/ Function t h a t r e q u e s t s t he data from s e r v e r and r e c e i v e s
an answer
@ f u n c t i o n g e t I n f o F r o m S e r v e r
@return f v o i d g /
f u n c t i o n g e t I n f o F r o m S e r v e r ( ) f
a x i o s . g e t ( ' / a p i / i n f o ' )
//Got ' p o s i t i v e ' r e s p o n s e with th e data from t he s e r v e r
. then ( ( r e s p o n s e ) =&gt; f
// Rewrite t h e data i n th e Web c l i e n t s t o r e</p>
      <p>C l i e n t S t o r e . r e w r i t e C o n t e n t ( r e s p o n s e . data ) ;
g )
//Got ' n e g a t i v e ' r e s p o n s e from th e s e r v e r ( an e r r o r ) .
. c a t c h ( ( r e s p o n s e ) =&gt; f
// Inform th e u s e r about th e e r r o r
c o n s o l e . e r r o r ( ' E r r o r w h i l e r e c e i v i n g r e s p o n s e = ' ,</p>
      <p>r e s p o n s e . data ) ;
g
g ) ;</p>
      <p>Implementation of updating the visual data in a Web-client can be done by
the help of HTTP-polling. In this case, the same simple HTTP data request is
used, but it is repeated with a time interval, so that the Web-client can show
the real-time information (Listing 2 has the example written in the JavaScript).
This method is easy to implement and can be used when developing a simple
Web-interface of a network device to observe relatively small amounts of data,
for example, monitor one parameters table of a network device in real time.</p>
      <p>Listing 2-2. HTTP-polling example, written in the JavaScript
import a x i o s from ' a x i o s ' ; //HTTP r e q u e s t s l i b r a r y
import C l i e n t S t o r e from ' . / C l i e n t S t o r e ' ; // s t o r e o f Web c l i e n t
l e t r e f r e s h I d = n u l l ; // i d o f t he p o l l i n g i n t e r v a l
/ @ f u n c t i o n s e t I n f o P o l l i n g</p>
      <p>@return f v o i d g /
f u n c t i o n s e t I n f o P o l l i n g ( ) f
r e f r e s h I d = s e t I n t e r v a l (
( ) =&gt; f
a x i o s . g e t ( ' / a p i / i n f o ' )
//Got ' p o s i t i v e ' r e s p o n s e
// with t he data from th e s e r v e r
. then ( ( r e s p o n s e ) =&gt; f
// Rewrite th e data i n th e Web c l i e n t s t o r e
C l i e n t S t o r e . r e w r i t e C o n t e n t ( r e s p o n s e . data ) ;
g )
//Got ' n e g a t i v e ' r e s p o n s e from t h e s e r v e r
. c a t c h ( ( r e s p o n s e ) =&gt; f
// Inform th e u s e r about th e e r r o r
c o n s o l e . e r r o r ( ' E r r o r w h i l e r e c e i v i n g r e s p o n s e = ' ,
r e s p o n s e . data ) ;
/
g ) ;
g , 1000 ) ;
g
/ @ f u n c t i o n s t o p I n f o P o l l i n g
f u n c t i o n s t o p I n f o P o l l i n g ( ) f
i f ( r e f r e s h I d ) f</p>
      <p>c l e a r I n t e r v a l ( r e f r e s h I d ) ;
g</p>
      <p>
        g
Finally, the WebSocket can be an implementation of updating the visual data. In
this case, the Web-client establishes a connection with the server and subscribes
to some necessary topics (themes) of data, and the server sends the data when
and only when it is obligatory, for example, when the data has been changed in
the database. (Listing 3 contains WebSocket example implementation written in
the Javascript). Any Web-application with real-time data can be set as a good
WebSocket implementation (as in the short example), because the WebSocket is
the most performance-wise and server-load-wise e cient transport [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ],[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
Yandex.Mail uses the WebSocket to load messages (e-mails) from the server in real
time (Fig.1).
      </p>
      <p>Listing 2-3. Example of the WebSocket session handling, written in JavaScript
c o n s t DATA URL = ' data ' ;
c o n s t GET SNAPSHOT RPC = ' getSnapshot ' ;
/ Handler that a b s t r a c t s the AutobahnJS (WAMP) methods
@ c l a s s S e s s i o n H a n d l e r /
c l a s s S e s s i o n H a n d l e r f
/ P r i v a t e f i e l d that s t o r e s s e s s i o n o b j e c t</p>
      <p>@private /
s e s s i o n = n u l l ;
/ @constructor
@param f? S e s s i o n g [ s e s s i o n = n u l l ]</p>
      <p>C l i e n t s e r v e r s e s s i o n . Null by d e f a u l t . /
c o n s t r u c t o r ( s e s s i o n = n u l l ) f</p>
      <p>t h i s . s e t S e s s i o n ( s e s s i o n ) ;
g
/ Method that s t o r e s the s e s s i o n i n the</p>
      <p>S e s s i o n H a n d l e r s i n s t a n c e
@method s e t S e s s i o n
@param f? S e s s i o n g [ s e s s i o n = n u l l ]</p>
      <p>C l i e n t s e r v e r s e s s i o n . Null by d e f a u l t .</p>
      <p>@return f void g /
s e t S e s s i o n = ( s e s s i o n = n u l l ) =&gt; f</p>
      <p>t h i s . s e s s i o n = s e s s i o n ;
g ;
/ Callback f u n c t i o n that h an d le s s u b s c r i p t i o n messages
@see http : / / autobahn . ws/ j s / r e f e r e n c e . html#s u b s c r i b e</p>
      <p>Autobahn documentation
@callback s u b s c r i p t i o n C a l l b a c k F n
@param f Array g a r g s a r r a y with event payload
@param f Object g kwargs o b j e c t with event payload
@param f Object g d e t a i l s o b j e c t with event metadata
@return f void g /
/ Method that s u b s c r i b e s to data updates messages
@method subscribeToData
@param f s u b s c r i p t i o n C a l l b a c k F n g c a l l b a c k F u n c t i o n
f u n c t i o n that should be executed when r e c e i v e d a message
@return f Promise g /
subscribeToData = ( c a l l b a c k F u n c t i o n ) =&gt; f
i f ( ! t h i s . s e s s i o n ) f</p>
      <p>c o n s o l e . e r r o r ( ' Tried to s u b s c r i b e to d e v i c e data but
no s e s s i o n was s p e c i f i e d i n SessionHandler ' ) ;</p>
      <p>r e t u r n n u l l ;
g
r e t u r n t h i s . s e s s i o n . s u b s c r i b e (DATA URL, c a l l b a c k F u n c t i o n ) ;
g ;
/ Method that r e q u e s t s snapshot ( f o r the c o l d s t a r t )
@method g e t S n a p s h o t
@return f Promise g /
g e t S n a p s h o t = ( ) =&gt; f
i f ( ! t h i s . s e s s i o n ) f</p>
      <p>c o n s o l e . e r r o r ( ' Tried g e t s n a p s h o t but no s e s s i o n
was s p e c i f i e d i n S e s s i o n H a n d l e r ' ) ;</p>
      <p>r e t u r n n u l l ;
g
r e t u r n t h i s . s e s s i o n . c a l l (GET SNAPSHOT RPC ) ;
g ;
g</p>
      <p>
        The deduction (that most e cient option to handle big data is WebSocket)
appears when comparing the options described above using several criteria
(Table 1) because the size of the messages ow between the Web-client and the
server is the smallest and most justi ed at this point. The method of updating
data only by user action is not suitable for the application with real-time data,
and polling is not suitable for it when the data becomes bloated. Moreover, with
using polling, the Web-client always sends requests, even when the data in the
database was not changed. Multiple WebSocket protocol \wrappers" without
the standardization, on the other hand, are the apparent draw back for a
developer. In this case, the developer should choose a protocol supported both on the
Web-client and on the server side. Despite of the tiny amount of box solutions of
this protocol data transfer implementations, the WAMP (the Web Application
Messaging Protocol) [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] might be a suitable open-standard protocol that allows
one to implement messaging though WebSocket is relatively simply [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ].
3
      </p>
    </sec>
    <sec id="sec-3">
      <title>Solution overview</title>
      <p>
        To solve the issue of excessive messages ow from the server to the Web-client,
for example, in the case of monitoring a huge network, handling of each received
message should contain minimum amount of calculations. So that the overall
message handling time is decreased, which gives the Web-client more time to
execute other tasks (for example such heavy tasks as DOM (Document Object
Model) rendering) in the one-thread Web-client. This can be e ciently done with
using data bu ering. This kind of bu ering works alike the bu ering in a CPU[
        <xref ref-type="bibr" rid="ref8">8</xref>
        ].
More speci cally, the Web-client does not handle the messages immediately after
it receives them from the server, but stores them in a bu er, not into an array
but into one message object. So applying the object to the store data is simple
and should only be done once per time interval.
      </p>
      <p>Let us assume that Web-application (that is needed to be developed) can have
either huge or small amount of data in the database. For example, in the case of
network monitoring application with real-time data. If there is a low amount of
network nodes (assuming their quantity is from 1 up to 50), the bu ering will
not change much in terms of performance because the modern computers have
enough calculation resources to handle telemetries of such nodes amount in a
short time (if every message does not lead to recalculation and re-render of the
network map graph, of course).</p>
      <p>criteria
Possible to cre- no
ate an
application with
realtime data
updates
Big number yes
of boilerplates
(ready-made
implementations) and,
therefore,
simplicity of
development
Web-client to
server requests
amount</p>
      <p>Depends on the Requests are sent by an There is only one
frequency of the interval, e.g. every 2 sec- request: to
estabuser actions onds lish the
connection to the server
Necessity of Data ow can be The polling is used in The server sends
implementation large only when the real-time data ap- the data to the
of the big data there is a high plications; therefore, the Web-client by
ow optimiza- amount of direct data should be updated himself;
theretion methods in user requests. It quite often. On the other fore, if the server
the Web-client should be handled hand, if the server con- observes
freon the server, so tains too much data, then quent changes
that other users the polling, even with of the data in
do not experience the data clustering im- the database, all
lags during work- plementation, might be- the changes will
ing with the inter- come inappropriate deci- be sent to the
face sion. Web-client as a
large messages
ow.</p>
      <p>It follows that the bu ering in uence on visual Web-interface user experience
is somehow needed to be minimized when there are not so many network nodes,
or, more speci cally, messages from the server (when the messages come from
the server less frequently than the bu ering interval). On the other hand, the
bu ering impact on the frequency of the data updates is also needed to be
increased in order to avoid stack over ow of the calculation operations and,
thus, avoid the interface freezing when the messages start to come from the
server more frequently. To implement this, the timeout of updating the data
should be refreshed when no message was received in the bu ering interval at
the shortest point and when the sum of the time intervals (including the time
refresh-iterations) becomes somewhat critical to do a force update at the longest
point. For instance, assuming minimum update interval is 200ms, if the
Webclient receives only one message during these 200 ms, the data from this message
will be applied to the data in the Web-client's store immediately after this time
interval. Otherwise, if the Web-client gets more than 1 message per these 200
ms, the timeout will be refreshed and will wait for the next message again, then
the timeout will be refreshed again etc. This will go on until the total sum of
the time intervals becomes critical, e.g. equal to 1 second. In this case, all the
data, which were merged from the messages (that were received during this 1
second) will be applied to the Web-client's data store. Thus, when the messages
ow is large, the update occurs only 1 time per second and when the messages
ow is smaller, the update can occur from as frequent as 1 time per 200 ms to
as frequent as 1 time per 1 second.</p>
      <p>
        Listing 4 contains the implementation of the algorithm above written in
JavaScript, EcmaScript 2015 standard [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]. There, the UpdateHandler class does
the accumulating and applying the accumulated data to the Web-client's data
store. In this implementation, the class handles the messages about the events
that occur in a massive network, therefore, the bu ering needed to be
introduced so that the operations delay becomes minimal. The external WebSocket
message handlers pass the messages with data updates of events, occurred in the
network, to the \bu eredUpdate" method. Assuming that the constant named
Constants.DEFAULT UPDATE TIMEOUT is equal to 200 ms, the
implementation of the algorithm described above is presented in the listing.
Listing 3-4. The example of updates handling with bu ering usage, written in the
JavaScript
import
import
as Constants from ' . . / Constants ' ;
as e v e n t s A c t i o n s from ' a c t i o n s / e v e n t s A c t i o n s ' ;
c l a s s UpdateHandler f
/ i d o f t h e timeout with minimum i n t e r v a l /
      </p>
      <p>i n t e r v a l = n u l l ;
/ i d o f t h e timeout with maximum i n t e r v a l</p>
      <p>( when th e f o r c e update o c c u r s ) /
m a x I n t e r v a l = n u l l ;
/
/
@type f Boolean g</p>
      <p>Boolean f l a g o f t he f o r c e update
f o r c e A p p l y = f a l s e ;</p>
      <p>Main data s t o r e i n s t a n c e
s t o r e = n u l l ;
/
/
/ @type f S t r i n g g</p>
      <p>Updating mode ( can be e i t h e r s e t
to updating or accumulating )
mode = n u l l ;
/
/ @type f Object g</p>
      <p>Object with accumulated updates o f type
f e v e n t s : Mapg /
accumulatedUpdates ;
bufferedUpdate ( updates ) f
// s t o p p i n g ` i n t e r n a l ` timeout
c l e a r I n t e r v a l ( t h i s . i n t e r v a l ) ;
// adding updates ( accumulating )
t h i s . accumulateUpdates ( updates ) ;
i f ( t h i s . f o r c e A p p l y === t r u e ) f
/ i f the f o r c e update f l a g i s s e t to t r u e</p>
      <p>updating the data /
t h i s . applyAccumulatedUpdatesIfNeeded ( ) ;
// e x i t i n g the c u r r e n t method
r e t u r n ;
g
t h i s . i n t e r v a l = s e t I n t e r v a l ( ( ) =&gt; f
/ c r e a t i n g ` i n t e r n a l ` timeout ,</p>
      <p>a f t e r which the data update i s c a l l e d /
t h i s . applyAccumulatedUpdatesIfNeeded ( ) ;
g , Constants .DEFAULT UPDATE TIMEOUT) ;
accumulateUpdates ( updates ) f
i f ( ! updates ) f r e t u r n ; g
updates . forEach ( update =&gt; f
/ e l s e , f o r each update add the data</p>
      <p>to accumulated updates o b j e c t /
t h i s . accumulatedUpdates . e v e n t s =</p>
      <p>UpdateHandler . appendEventMessage (
t h i s . accumulatedUpdates . events ,
update ) ;
g ) ;
g
s t a t i c appendEventMessage ( i n i t i a l V a l u e , newMessage ) f
/ Here , depending on the message s t r u c t u r e ,</p>
      <p>new data about the network e v e n t s i s added /
r e t u r n i n i t i a l V a l u e . s e t ( newMessage . id , newMessage . v a l ) ;
g
applyAccumulatedUpdates ( ) f
c o n s t f e v e n t s g = t h i s . accumulatedUpdates ;
// a p p l y i n g data to the s t o r e
t h i s . s t o r e . d i s p a t c h ( e v e n t s A c t i o n s . updateEvents ( e v e n t s ) ) ;
/ i n i t i a l i z i n g the v a l u e f o r the accumulated updates /
t h i s . accumulatedUpdates . e v e n t s = new Map ( ) ;</p>
      <p>This algorithm was successfully implemented and used in the task of creating
the Web-interfaces of network and geographical map that might contain up to 10
thousand of network devices and around 50 thousand wireless broadband links
between them. The Web-server can send messages quicker than 1 message per
1 ms in the con guration with such a big network. Therefore the one-thread
Web-client could not be able to handle and apply the data without a signi cant
visual delay (when not using bu ering).</p>
      <p>Applying adaptive methods of the data handling, on the other hand, allows
one to increase performance while decreasing the calculations amounts for any
width of the data ow.
4</p>
    </sec>
    <sec id="sec-4">
      <title>Conclusion</title>
      <p>Modern Web-programming technologies allow the developers to implement the
Web-applications that do not have the excessive calculations and optimization
operations. Especially, it is important when having a low amount of data but
also do not have the signi cant calculations delay when having a big data ow.
Di erent development tasks require using di erent techniques, methods, and
approaches to handle information and optimize the data ow. Nevertheless, using
the WebSocket and bu ering in the Web-client is an e cient way to organize
and handle the data updating in the Web-application and to optimize the data
ow.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>AWS</given-names>
            <surname>Case</surname>
          </string-name>
          <article-title>Study: Kaplan</article-title>
          . https://aws.amazon.com/solutions/case-studies/ kaplan/
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Liping</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Dongfang</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Naixue</surname>
            ,
            <given-names>X.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Changhoon</surname>
          </string-name>
          , L.:
          <article-title>CoWebDraw: a real-time collaborative graphical editing system supporting multi-clients based on HTML5</article-title>
          .
          <source>Multimedia Tools and Applications</source>
          . Vol.
          <volume>77</volume>
          ,
          <issue>4</issue>
          , 5067{
          <fpage>5082</fpage>
          (
          <year>2018</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <article-title>Chto takoe Long-Polling, WebSockets, SSE i Comet. https://myrusakov.ru/ long-polling-websockets-sse-and-comet</article-title>
          .html
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <article-title>Postojannoe soedinenie mezhdu brauzerom i serverom</article-title>
          . https://www.insight-it. ru/interactive/2012/postoyannoe
          <article-title>-soedinenie-mezhdubrauzerom-i-serverom/</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Kotov</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Krasil</surname>
          </string-name>
          'nikov, N.:
          <article-title>Klasterizacija dannyh</article-title>
          . http://yury.name/internet/ 02ia-seminar-note.pdf
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>WAMP - The Web Application Messaging Protocol</surname>
          </string-name>
          . http://wampproto.org/
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <article-title>GitHub - WAMP in JavaScript for Browsers and NodeJS</article-title>
          . https://github.com/ crossbario/autobahn-js
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Muller</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Flynn</surname>
            ,
            <given-names>M. J.</given-names>
          </string-name>
          :
          <article-title>Processor Architecture and Data Bu ering</article-title>
          .
          <source>IEEE Transactions on computers</source>
          . Vol.
          <volume>41</volume>
          ,
          <issue>10</issue>
          ,
          <fpage>1211</fpage>
          -
          <lpage>1222</lpage>
          (
          <year>1992</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <article-title>ECMAScript 2015 Language Speci cation { ECMA-262 6th Edition</article-title>
          . http://www. ecma-international.
          <source>org/ecma-262/6</source>
          .0/
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>