SlideShare uma empresa Scribd logo
1 de 116
Baixar para ler offline
Scaling with event–
       based webservers
       Morten Siebuhr


       Open Source Days
       March 5th 2011




1/66
whoami(1)

       Defining “web–server work”

            Killing Apache

         Event–based servers

             Using Node.js

              Questions




2/66
whoami(1)




3/66
Computer Scientist



       Distributed Systems / Scientific Computing




          (Web–)developer @ One.com




4/66
Web–development @ one.com:



         Rich Internet Applications
         e–mail, calendar, galleries, . . .




           + 900.000 customers




5/66
6/66
Defining
       “Web–server work”




7/66
Typical web–server work




8/66
Typical web–server work



            Serving static files




8/66
Typical web–server work



            Serving static files


           Talking to databases




8/66
Typical web–server work



             Serving static files


           Talking to databases


       Not doing lots of computations




8/66
Typical web–server work



                 Serving static files


                Talking to databases


           Not doing lots of computations


       ≈ 100 → 1000 connections served ASAP




8/66
(A)typical web–server work




9/66
(A)typical web–server work



           Persistent connections




9/66
(A)typical web–server work



           Persistent connections


        = ∞ simultaneous connections




9/66
(A)typical web–server work



            Persistent connections


        = ∞ simultaneous connections


       ≈ 10000 simultaneous connections




9/66
(A)typical web–server work



                  Persistent connections


              = ∞ simultaneous connections


            ≈ 10000 simultaneous connections


       (But we don’t care as much about latency. . . )




9/66
waiting...




10/66
sleep(1.0)




11/66
12/66
Response time w. sleep(1).
                                25 s
                                                                                                      WSGI


                                20 s
        Average response time




                                15 s



                                10 s



                                 5s



                                 0s
                                       0   100   200   300     400      500      600      700   800      900   1000
                                                                Concurrent requests




13/66
Response time w. sleep(1).
                                25 s
                                                                                                           WSGI


                                20 s
        Average response time




                                15 s



                                10 s



                                 5s



                                 0s
                                       0   1000   2000   3000    4000    5000     6000       7000   8000     9000   10000
                                                                  Concurrent requests




14/66
Threading




15/66
Use threads




16/66
Wasted resources!




17/66
Add threads




18/66
Response time w. sleep(1).
                                25 s
                                                                                                   WSGI
                                                                                                  Apache

                                20 s
        Average response time




                                15 s



                                10 s



                                 5s



                                 0s
                                       0   100   200   300     400      500      600      700   800    900   1000
                                                                Concurrent requests




19/66
Response time w. sleep(1).
                                25 s
                                                                                                        WSGI
                                                                                                       Apache

                                20 s
        Average response time




                                15 s



                                10 s



                                 5s



                                 0s
                                       0   1000   2000   3000    4000    5000     6000       7000   8000   9000   10000
                                                                  Concurrent requests




20/66
21/66
22/66
23/66
Memory usage w. sleep(1).
                             1500 MB
                                                                                                 WSGI
                                                                                                Apache

                             1250 MB



                             1000 MB
        Max Virtual Memory




                             750 MB



                             500 MB



                             250 MB



                               0 MB
                                       0   100   200   300     400      500      600     700   800   900   1000
                                                                Concurrent requests




25/66
Memory usage w. sleep(1).
                             1500 MB
                                                                                                      WSGI
                                                                                                     Apache

                             1250 MB



                             1000 MB
        Max Virtual Memory




                             750 MB



                             500 MB



                             250 MB



                               0 MB
                                       0   1000   2000   3000    4000    5000     6000      7000   8000   9000   10000
                                                                  Concurrent requests




26/66
A single connection




27/66
A single connection

                 =

              1 thread




27/66
A single connection

                        =

                    1 thread

                        =

        1 C–stack & kernel data structures




27/66
A single connection

                         =

                     1 thread

                         =

        1 C–stack & kernel data structures

                         +

        Locking & switching overhead &c. . .




27/66
28/66
Add memory!




29/66
Add memory!




        Memory is cheap




29/66
Add memory!




                   Memory is cheap



        Except, actually using it isn’t cheap. . .




29/66
Memory Wall


        1986 → 2000:




30/66
Memory Wall


           1986 → 2000:


        + 55% CPU speed P/A




30/66
Memory Wall


                                 1986 → 2000:


                           + 55% CPU speed P/A


                           + 10% RAM speed P/A


        (Source: http://www.cs.virginia.edu/papers/Hitting_Memory_Wall-wulf94.pdf)




30/66
31/66
Threads and connections mapped 1:1




32/66
Threads and connections mapped 1:1



              We use a lot of threads




32/66
Threads and connections mapped 1:1



                         We use a lot of threads



        Which we don’t have the memory bandwidth to move around.




32/66
Events!




33/66
waiting...




34/66
35/66
36/66
Event-basics




37/66
Event-basics



         Event queue




37/66
Event-basics



         Event queue



          Event loop




37/66
Event-basics



          Event queue



           Event loop



        “The Event Loop”




37/66
A single connection




38/66
A single connection

                 =

              1 “Event”




38/66
A single connection

                   =

                1 “Event”

                   =

        Some variables & function




38/66
A single connection

                    =

                1 “Event”

                    =

        Some variables & function

                    =

        Hash table & some pointers




38/66
A single connection

                          =

                       1 “Event”

                          =

              Some variables & function

                          =

              Hash table & some pointers

                          +

        Queue of events waiting to be processed




38/66
39/66
39/66
39/66
39/66
Why not earlier




40/66
Why not earlier




        Simply not a problem!




40/66
Why not earlier




                            Simply not a problem!




        Traditional back–end programmers not used to thinking this way




40/66
What we gain




41/66
What we gain



        Relatively low memory use




41/66
What we gain



        Relatively low memory use



           No threading issues




41/66
What we gain



                  Relatively low memory use



                     No threading issues



        Client-side programmers have no preconditions.




41/66
Node.js




42/66
Node.js is a set of bindings to the V8 JavaScript engine
                     for scripting network programs.




                                                      — Ryan Dahl




43/66
Node.js is a set of bindings to the V8 JavaScript engine
                     for scripting network programs.




                                                      — Ryan Dahl




43/66
JavaScript




44/66
JavaScript


        Built for event-based programming.




44/66
JavaScript


        Built for event-based programming.




44/66
JavaScript


        Built for event-based programming.




        Netscape needed something fast. . .




44/66
JavaScript


                 Built for event-based programming.




                   Netscape needed something fast. . .
        . . . JavaScript “designed” and implemented in 14 days




44/66
JavaScript


                 Built for event-based programming.




                   Netscape needed something fast. . .
        . . . JavaScript “designed” and implemented in 14 days




44/66
Google V8




        JIT’ing JavaScript to native machine code




45/66
Google V8




        JIT’ing JavaScript to native machine code




                = Compiling server code




45/66
Node.js




        Non–browser V8–bindings for various libraries




                  Everything non–blocking




46/66
A minimal webserver in Node.js. . .


        // Import HTTP package
        var http = require ( ’ http ’) ;

        // Set up basic server
        var server = http . createServer ( function ( req , res ) {
           res . writeHead (200 , { ’ Content - Type ’: ’ text / plain ’ }) ;
           res . end ( ’ Hello World  n ’) ;
        }) ;

        // Start the server
        server . listen (8124 , " 127.0.0.1 " ) ;
        console . log ( ’ Server running at http : / / 1 2 7 . 0 . 0 . 1 : 8 1 2 4 / ’) ;




47/66
. . . with “database”

        // Import HTTP package
        var http = require ( ’ http ’) ;

        // Set up basic server
        var server = http . createServer ( function ( req , res ) {
           setTimeout ( function () {
              res . writeHead (200 , { ’ Content - Type ’: ’ text / plain ’ }) ;
              res . end ( ’ Hello World  n ’) ;
           } , 1000) ;
        }) ;

        // Start the server
        server . listen (8124 , " 127.0.0.1 " ) ;
        console . log ( ’ Server running at http : / / 1 2 7 . 0 . 0 . 1 : 8 1 2 4 / ’) ;




48/66
Response time w. sleep(1).
                                25 s
                                                                                                   WSGI
                                                                                                  Apache
                                                                                                  Node.js
                                20 s
        Average response time




                                15 s



                                10 s



                                 5s



                                 0s
                                       0   100   200   300     400      500      600      700   800     900   1000
                                                                Concurrent requests




49/66
Response time w. sleep(1).
                                25 s
                                                                                                        WSGI
                                                                                                       Apache
                                                                                                       Node.js
                                20 s
        Average response time




                                15 s



                                10 s



                                 5s



                                 0s
                                       0   1000   2000   3000    4000    5000     6000       7000   8000    9000   10000
                                                                  Concurrent requests




50/66
Memory usage w. sleep(1).
                             1500 MB
                                                                                                      WSGI
                                                                                                     Apache
                                                                                                     Node.js
                             1250 MB



                             1000 MB
        Max Virtual Memory




                             750 MB



                             500 MB



                             250 MB



                               0 MB
                                       0   1000   2000   3000    4000    5000     6000      7000   8000   9000   10000
                                                                  Concurrent requests




51/66
Connections in Node.js




52/66
Connections in Node.js

                  =

               1 “Event”




52/66
Connections in Node.js

                     =

                 1 “Event”

                     =

        1 Closure + callback function




52/66
Connections in Node.js

                     =

                 1 “Event”

                     =

        1 Closure + callback function

                     =

          1 struct + some pointers




52/66
Connections in Node.js

                          =

                      1 “Event”

                          =

             1 Closure + callback function

                          =

               1 struct + some pointers

                          +

        Event queue operations + function calls




52/66
Alternatives




53/66
Alternatives

        Well–written thread program!




53/66
Alternatives

        Well–written thread program!
                   Erlang
            http://www.erlang.org/




53/66
Alternatives

        Well–written thread program!
                   Erlang
            http://www.erlang.org/

                Google GO
              http://golang.org/




53/66
Alternatives

        Well–written thread program!
                    Erlang
            http://www.erlang.org/

                 Google GO
              http://golang.org/

             Lua Event Machine
          https://github.com/esmil/lem




53/66
Alternatives

        Well–written thread program!
                    Erlang
            http://www.erlang.org/

                 Google GO
              http://golang.org/

             Lua Event Machine
          https://github.com/esmil/lem

                    Nginx
            http://wiki.nginx.org/




53/66
Alternatives

        Well–written thread program!
                    Erlang
            http://www.erlang.org/

                 Google GO
              http://golang.org/

             Lua Event Machine
          https://github.com/esmil/lem

                    Nginx
            http://wiki.nginx.org/

                   Varnish
         http://www.varnish-cache.org/




53/66
Working with Node.js




54/66
I’m new to JavaScript!




55/66
56/66
JavaScript WTFs


                         Always add ;!


                  Function arguments. . .


                this   scoped to callee object!


        Stacktraces + events sometimes look strange




57/66
JSLint




58/66
JSLint

        www.crockfordfacts.com




58/66
Nice code!


        def process ( user ) :
          user = getAuth ( user )
          if not user :
            return ’ Fail ’

          db = getC onnnecti on ( params )
          data = db . getUserData ( user )
          if not data :
            return ’ Fail ’

          return data




59/66
Boomerang code

        function process ( user , callback ) {
          getAuth ( req . username , function ( err , user ) {
            if ( err ) return callback ( err ) ;

              g etDB Co n ne ct io n ( params , function ( err , db ) {
                 if ( err ) return callback ( err ) ;

                db . getUserData ( user , function ( err , data ) {
                   if ( err ) return callback ( err ) ;

                     return callback ( null , data ) ;
                  }) ;
               }) ;
            }) ;
        }




60/66
NPM




61/66
Express.js



        var app = require ( ’ express ’) . createServer () ;

        app . get ( ’/ ’ , function ( req , res ) {
           setTimeout ( function () {
              res . send ( ’ Hello World ’) ;
           } , 1000) ;
        }) ;

        app . listen (3000) ;




62/66
Express.js - Chat server

        var app = require ( ’ express ’) . createServer () ,
            chat = [];

        app . get ( ’/ ’ , function ( req , res ) {
           chat . push ( res ) ;
        }) ;

        app . get ( ’ /: msg ’ , function ( req , res ) {
           chat . forEach ( function ( conn ) {
              conn . write ( req . params . msg ) ;
           }) ;
        }) ;

        app . listen (3000) ;




63/66
Questions

          (The end)




64/66
http://nodejs.org/




        https://github.com/joyent/node




65/66
function process ( user , callback ) {
          var user = null , db = null ;
          function done_ () {
            if ( user && db ) {
              db . getUserData ( user , function ( err , data ) {
                 if ( err ) return callback ( err ) ;
                 return callback ( null , data ) ;
              }) ;
            }
          }

            getAuth ( req . username , function ( err , retuser ) {
               if ( err ) return callback ( err ) ;
               user = retuser ;
               done_ () ;
            }) ;

            g et DBCo n ne ct i on ( params , function ( err , retdb ) {
               if ( err ) return callback ( err ) ;
               db = retdb ;
               done_ () ;
            }) ;
        }




66/66

Mais conteúdo relacionado

Destaque

High Availability Django - Djangocon 2016
High Availability Django - Djangocon 2016High Availability Django - Djangocon 2016
High Availability Django - Djangocon 2016Frankie Dintino
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsGraham Dumpleton
 
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance TuningPyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance TuningGraham Dumpleton
 
Django deployment and rpm+yum
Django deployment and rpm+yumDjango deployment and rpm+yum
Django deployment and rpm+yumWalter Liu
 
MongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDBMongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDBRick Copeland
 
Python Deployment with Fabric
Python Deployment with FabricPython Deployment with Fabric
Python Deployment with Fabricandymccurdy
 
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Eric Palakovich Carr
 
OpenStack API's and WSGI
OpenStack API's and WSGIOpenStack API's and WSGI
OpenStack API's and WSGIMike Pittaro
 

Destaque (9)

High Availability Django - Djangocon 2016
High Availability Django - Djangocon 2016High Availability Django - Djangocon 2016
High Availability Django - Djangocon 2016
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance TuningPyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
 
Django deployment and rpm+yum
Django deployment and rpm+yumDjango deployment and rpm+yum
Django deployment and rpm+yum
 
MongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDBMongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDB
 
Python Deployment with Fabric
Python Deployment with FabricPython Deployment with Fabric
Python Deployment with Fabric
 
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!
 
OpenStack API's and WSGI
OpenStack API's and WSGIOpenStack API's and WSGI
OpenStack API's and WSGI
 
Beyond OpenStack
Beyond OpenStackBeyond OpenStack
Beyond OpenStack
 

Último

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Scaling with event-based webservers

  • 1. Scaling with event– based webservers Morten Siebuhr Open Source Days March 5th 2011 1/66
  • 2. whoami(1) Defining “web–server work” Killing Apache Event–based servers Using Node.js Questions 2/66
  • 4. Computer Scientist Distributed Systems / Scientific Computing (Web–)developer @ One.com 4/66
  • 5. Web–development @ one.com: Rich Internet Applications e–mail, calendar, galleries, . . . + 900.000 customers 5/66
  • 7. Defining “Web–server work” 7/66
  • 9. Typical web–server work Serving static files 8/66
  • 10. Typical web–server work Serving static files Talking to databases 8/66
  • 11. Typical web–server work Serving static files Talking to databases Not doing lots of computations 8/66
  • 12. Typical web–server work Serving static files Talking to databases Not doing lots of computations ≈ 100 → 1000 connections served ASAP 8/66
  • 14. (A)typical web–server work Persistent connections 9/66
  • 15. (A)typical web–server work Persistent connections = ∞ simultaneous connections 9/66
  • 16. (A)typical web–server work Persistent connections = ∞ simultaneous connections ≈ 10000 simultaneous connections 9/66
  • 17. (A)typical web–server work Persistent connections = ∞ simultaneous connections ≈ 10000 simultaneous connections (But we don’t care as much about latency. . . ) 9/66
  • 20. 12/66
  • 21. Response time w. sleep(1). 25 s WSGI 20 s Average response time 15 s 10 s 5s 0s 0 100 200 300 400 500 600 700 800 900 1000 Concurrent requests 13/66
  • 22. Response time w. sleep(1). 25 s WSGI 20 s Average response time 15 s 10 s 5s 0s 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 Concurrent requests 14/66
  • 27. Response time w. sleep(1). 25 s WSGI Apache 20 s Average response time 15 s 10 s 5s 0s 0 100 200 300 400 500 600 700 800 900 1000 Concurrent requests 19/66
  • 28. Response time w. sleep(1). 25 s WSGI Apache 20 s Average response time 15 s 10 s 5s 0s 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 Concurrent requests 20/66
  • 29. 21/66
  • 30. 22/66
  • 31. 23/66
  • 32.
  • 33. Memory usage w. sleep(1). 1500 MB WSGI Apache 1250 MB 1000 MB Max Virtual Memory 750 MB 500 MB 250 MB 0 MB 0 100 200 300 400 500 600 700 800 900 1000 Concurrent requests 25/66
  • 34. Memory usage w. sleep(1). 1500 MB WSGI Apache 1250 MB 1000 MB Max Virtual Memory 750 MB 500 MB 250 MB 0 MB 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 Concurrent requests 26/66
  • 36. A single connection = 1 thread 27/66
  • 37. A single connection = 1 thread = 1 C–stack & kernel data structures 27/66
  • 38. A single connection = 1 thread = 1 C–stack & kernel data structures + Locking & switching overhead &c. . . 27/66
  • 39. 28/66
  • 41. Add memory! Memory is cheap 29/66
  • 42. Add memory! Memory is cheap Except, actually using it isn’t cheap. . . 29/66
  • 43. Memory Wall 1986 → 2000: 30/66
  • 44. Memory Wall 1986 → 2000: + 55% CPU speed P/A 30/66
  • 45. Memory Wall 1986 → 2000: + 55% CPU speed P/A + 10% RAM speed P/A (Source: http://www.cs.virginia.edu/papers/Hitting_Memory_Wall-wulf94.pdf) 30/66
  • 46. 31/66
  • 47. Threads and connections mapped 1:1 32/66
  • 48. Threads and connections mapped 1:1 We use a lot of threads 32/66
  • 49. Threads and connections mapped 1:1 We use a lot of threads Which we don’t have the memory bandwidth to move around. 32/66
  • 52. 35/66
  • 53. 36/66
  • 55. Event-basics Event queue 37/66
  • 56. Event-basics Event queue Event loop 37/66
  • 57. Event-basics Event queue Event loop “The Event Loop” 37/66
  • 59. A single connection = 1 “Event” 38/66
  • 60. A single connection = 1 “Event” = Some variables & function 38/66
  • 61. A single connection = 1 “Event” = Some variables & function = Hash table & some pointers 38/66
  • 62. A single connection = 1 “Event” = Some variables & function = Hash table & some pointers + Queue of events waiting to be processed 38/66
  • 63. 39/66
  • 64. 39/66
  • 65. 39/66
  • 66. 39/66
  • 68. Why not earlier Simply not a problem! 40/66
  • 69. Why not earlier Simply not a problem! Traditional back–end programmers not used to thinking this way 40/66
  • 71. What we gain Relatively low memory use 41/66
  • 72. What we gain Relatively low memory use No threading issues 41/66
  • 73. What we gain Relatively low memory use No threading issues Client-side programmers have no preconditions. 41/66
  • 75. Node.js is a set of bindings to the V8 JavaScript engine for scripting network programs. — Ryan Dahl 43/66
  • 76. Node.js is a set of bindings to the V8 JavaScript engine for scripting network programs. — Ryan Dahl 43/66
  • 78. JavaScript Built for event-based programming. 44/66
  • 79. JavaScript Built for event-based programming. 44/66
  • 80. JavaScript Built for event-based programming. Netscape needed something fast. . . 44/66
  • 81. JavaScript Built for event-based programming. Netscape needed something fast. . . . . . JavaScript “designed” and implemented in 14 days 44/66
  • 82. JavaScript Built for event-based programming. Netscape needed something fast. . . . . . JavaScript “designed” and implemented in 14 days 44/66
  • 83. Google V8 JIT’ing JavaScript to native machine code 45/66
  • 84. Google V8 JIT’ing JavaScript to native machine code = Compiling server code 45/66
  • 85. Node.js Non–browser V8–bindings for various libraries Everything non–blocking 46/66
  • 86. A minimal webserver in Node.js. . . // Import HTTP package var http = require ( ’ http ’) ; // Set up basic server var server = http . createServer ( function ( req , res ) { res . writeHead (200 , { ’ Content - Type ’: ’ text / plain ’ }) ; res . end ( ’ Hello World n ’) ; }) ; // Start the server server . listen (8124 , " 127.0.0.1 " ) ; console . log ( ’ Server running at http : / / 1 2 7 . 0 . 0 . 1 : 8 1 2 4 / ’) ; 47/66
  • 87. . . . with “database” // Import HTTP package var http = require ( ’ http ’) ; // Set up basic server var server = http . createServer ( function ( req , res ) { setTimeout ( function () { res . writeHead (200 , { ’ Content - Type ’: ’ text / plain ’ }) ; res . end ( ’ Hello World n ’) ; } , 1000) ; }) ; // Start the server server . listen (8124 , " 127.0.0.1 " ) ; console . log ( ’ Server running at http : / / 1 2 7 . 0 . 0 . 1 : 8 1 2 4 / ’) ; 48/66
  • 88. Response time w. sleep(1). 25 s WSGI Apache Node.js 20 s Average response time 15 s 10 s 5s 0s 0 100 200 300 400 500 600 700 800 900 1000 Concurrent requests 49/66
  • 89. Response time w. sleep(1). 25 s WSGI Apache Node.js 20 s Average response time 15 s 10 s 5s 0s 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 Concurrent requests 50/66
  • 90. Memory usage w. sleep(1). 1500 MB WSGI Apache Node.js 1250 MB 1000 MB Max Virtual Memory 750 MB 500 MB 250 MB 0 MB 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 Concurrent requests 51/66
  • 92. Connections in Node.js = 1 “Event” 52/66
  • 93. Connections in Node.js = 1 “Event” = 1 Closure + callback function 52/66
  • 94. Connections in Node.js = 1 “Event” = 1 Closure + callback function = 1 struct + some pointers 52/66
  • 95. Connections in Node.js = 1 “Event” = 1 Closure + callback function = 1 struct + some pointers + Event queue operations + function calls 52/66
  • 97. Alternatives Well–written thread program! 53/66
  • 98. Alternatives Well–written thread program! Erlang http://www.erlang.org/ 53/66
  • 99. Alternatives Well–written thread program! Erlang http://www.erlang.org/ Google GO http://golang.org/ 53/66
  • 100. Alternatives Well–written thread program! Erlang http://www.erlang.org/ Google GO http://golang.org/ Lua Event Machine https://github.com/esmil/lem 53/66
  • 101. Alternatives Well–written thread program! Erlang http://www.erlang.org/ Google GO http://golang.org/ Lua Event Machine https://github.com/esmil/lem Nginx http://wiki.nginx.org/ 53/66
  • 102. Alternatives Well–written thread program! Erlang http://www.erlang.org/ Google GO http://golang.org/ Lua Event Machine https://github.com/esmil/lem Nginx http://wiki.nginx.org/ Varnish http://www.varnish-cache.org/ 53/66
  • 104. I’m new to JavaScript! 55/66
  • 105. 56/66
  • 106. JavaScript WTFs Always add ;! Function arguments. . . this scoped to callee object! Stacktraces + events sometimes look strange 57/66
  • 108. JSLint www.crockfordfacts.com 58/66
  • 109. Nice code! def process ( user ) : user = getAuth ( user ) if not user : return ’ Fail ’ db = getC onnnecti on ( params ) data = db . getUserData ( user ) if not data : return ’ Fail ’ return data 59/66
  • 110. Boomerang code function process ( user , callback ) { getAuth ( req . username , function ( err , user ) { if ( err ) return callback ( err ) ; g etDB Co n ne ct io n ( params , function ( err , db ) { if ( err ) return callback ( err ) ; db . getUserData ( user , function ( err , data ) { if ( err ) return callback ( err ) ; return callback ( null , data ) ; }) ; }) ; }) ; } 60/66
  • 112. Express.js var app = require ( ’ express ’) . createServer () ; app . get ( ’/ ’ , function ( req , res ) { setTimeout ( function () { res . send ( ’ Hello World ’) ; } , 1000) ; }) ; app . listen (3000) ; 62/66
  • 113. Express.js - Chat server var app = require ( ’ express ’) . createServer () , chat = []; app . get ( ’/ ’ , function ( req , res ) { chat . push ( res ) ; }) ; app . get ( ’ /: msg ’ , function ( req , res ) { chat . forEach ( function ( conn ) { conn . write ( req . params . msg ) ; }) ; }) ; app . listen (3000) ; 63/66
  • 114. Questions (The end) 64/66
  • 115. http://nodejs.org/ https://github.com/joyent/node 65/66
  • 116. function process ( user , callback ) { var user = null , db = null ; function done_ () { if ( user && db ) { db . getUserData ( user , function ( err , data ) { if ( err ) return callback ( err ) ; return callback ( null , data ) ; }) ; } } getAuth ( req . username , function ( err , retuser ) { if ( err ) return callback ( err ) ; user = retuser ; done_ () ; }) ; g et DBCo n ne ct i on ( params , function ( err , retdb ) { if ( err ) return callback ( err ) ; db = retdb ; done_ () ; }) ; } 66/66