28
SYNCHORNOUS AND ASYNCHROUS EXECUTION (WEBSERVERS) EWERE DIAGBOYA

webservers

Embed Size (px)

Citation preview

Page 1: webservers

SYNCHORNOUS AND ASYNCHROUS EXECUTION (WEBSERVERS)

EWERE DIAGBOYA

Page 2: webservers

SYNCHRONOUS EXECUTION• Synchronous processes wait for one to complete before the

next begins

• When you execute something synchronously, you wait for it to finish before moving on to another task. When you execute something asynchronously, you can move on to another task before it finishes.

Page 3: webservers

ASYNCHRONOUS EXECUTION•  Asynchronous refers to processes that do not depend on each other's

outcome, and can therefore occur on different threads simultaneously• Asynchronous communication is the exchange of messages, such as

among the hosts on a network or devices in a computer, by reading and responding as schedules permit rather than according to some clock that is synchronized for both the sender and receiver or in real time. It is usually used to describe communications in which data can be transmitted intermittently rather than in a steady stream.

Page 4: webservers

SYNCHRONOUS & ASYNCHRONOUS EXECUTION

SYNCHRONOUS• You are in a queue to get a movie ticket. You cannot get one until everybody in

front of you gets one, and the same applies to the people queued behind you.ASYNCHRONOUS• You are in a restaurant with many other people. You order your food. Other

people can also order their food, they don't have to wait for your food to be cooked and served to you before they can order. In the kitchen restaurant workers are continuously cooking, serving, and taking orders. People will get their food served as soon as it is cooked.

Page 5: webservers

SIDE NOTE

• Although asynchronous workflow processes might process faster, synchronous processing is sometimes preferred. If a calling application depends on information from the workflow process, you should run the process synchronously to ensure that the calling application gets the information it needs from the process before the workflow finishes and the application closes.

Page 6: webservers

WHAT IS A WEB SERVER

• A web server is an information technology that processes requests via HTTP, the basic network protocol used to distribute information on the World Wide Web. The term can refer either to the entire computer system, an appliance, or specifically to the software that accepts and supervises the HTTP requests

Page 7: webservers

WEB SERVERS

• Lighttpd (asynchronous)• Apache * (synchronous)• Nginx * (asynchronous)• IIS (Internet Information Services) (synchronous)• AWS Lambda (event, asynchronous), AWS Kinesis• Apache Tomcat

Page 8: webservers

APACHE WEB SERVERThe Apache HTTP Server, colloquially called Apache is the world's most used web server software. Originally based on the NCSA HTTPd server, development of Apache began in early 1995 after work on the NCSA code stalled. Apache played a key role in the initial growth of the World Wide Web, quickly overtaking NCSA HTTPd as the dominant HTTP server, and has remained most popular since April 1996. In 2009, it became the first web server software to serve more than 100 million websites.

Page 9: webservers

APACHE WEB SERVERInstead of implementing a single architecture, Apache provides a variety of MultiProcessing Modules (MPMs), which allow Apache to run in a process-based, hybrid (process and thread) or event-hybrid mode, to better match the demands of each particular infrastructure.

But Apache slows down under heavy load, because of the need to spawn new processes, thus consuming more computer memory. It also creates new threads that must compete with others for access to memory and CPU. Apache will also refuse new connections when traffic reaches the limit of processes configured by the administrator.

Page 10: webservers

• Load Balancing• Loadable Dynamic Modules• User and Session tracking• Concurrent connection limiting• Embedded Perl, PHP and Lua scripting• Custom logging with rotation• Concurrent connection limiting• Request processing rate limiting• Bandwidth throttling• Server Side Includes• IP address-based geolocation

FEATURES: APACHE WEB SERVER

Page 11: webservers

COMPANIES USING APACHE

Page 12: webservers

NGINX

• Nginx was created to be both a web server and a proxy server.  

• Nginx was built to solve the C10k problem• Uses asynchronous, non-blocking, event-driven connection

handling algorithm.

• This style of connection processing allows Nginx to scale incredibly far with limited resources. Since the server is single-threaded and processes are not spawned to handle each new connection, the memory and CPU usage tends to stay relatively consistent, even at times of heavy load. 

Page 13: webservers

FEATURES: NGINX• Handling of static files, index files and auto-indexing• Reverse proxy with caching• Load balancing with in-band health checks• FastCGI, SCGI, uWSGI support with caching• Name- and IP address-based virtual servers• IPv6-compatible• HTTP/2 and SPDY protocol support• FLV and MP4 streaming• Web page access authentication• URL rewriting• Concurrent connection limiting• Request processing rate limiting

Page 14: webservers

• Quora.com• Appnexus• Wix• Montana• Mulesoft• NASA• Groupon• Zendesk

COMPANIES USING NGINX

Page 15: webservers

WEB SERVER USAGE

MAY 2014 JUNE 2014

Page 16: webservers

CONTRASTS BETWEEN APACHE AND NGINX

Page 17: webservers

MODULES: APACHE• Apache's module system allows you to dynamically load or unload modules

to satisfy your needs during the course of running the server.• The Apache core is always present, while modules can be turned on or off,

adding or removing additional functionality and hooking into the main server.• Apache uses this functionality for a large variety tasks. Due to the maturity

of the platform, there is an extensive library of modules available. • These can be used to alter some of the core functionality of the server, such

as ‘mod_php’  which embeds a PHP interpreter into each running worker.• Modules are not limited to processing dynamic content, they can be used

used for rewriting URLs, authenticating clients, hardening the server, logging, caching, compression, proxying, rate limiting, and encrypting. Dynamic modules can extend the core functionality considerably without much additional work.

Page 18: webservers

MODULES: NGINX• Nginx also implements a module system, but it is quite different from the Apache

system.• In Nginx, modules are not dynamically loadable, so they must be selected and

compiled into the core software.• While distributions' packages tend to include the most commonly used modules,

if you require a non-standard module, you will have to build the server from source yourself.

• Nginx modules are still very useful though, and they allow you to dictate what you want out of your server by only including the functionality you intend to use.

• Nginx modules allow many of the same capabilities as Apache modules. For instance, Nginx modules can provide proxying support, compression, rate limiting, logging, rewriting, geolocation, authentication, encryption, streaming, and mail functionality.

Page 19: webservers

• Apache servers can handle static content using its conventional file-based methods. The performance of these operations is mainly a function of the MPM methods described above.

• Apache can also process dynamic content by embedding a processor of the language in question into each of its worker instances. This allows it to execute dynamic content within the web server itself without having to rely on external components. These dynamic processors can be enabled through the use of dynamically loadable modules.

• Apache's ability to handle dynamic content internally means that configuration of dynamic processing tends to be simpler. Communication does not need to be coordinated with an additional piece of software and modules can easily be swapped out if the content requirements change.

STATIC & DYNAMIC CONTENT: NGINX: APACHE

Page 20: webservers

• Nginx does not have any ability to process dynamic content natively. To handle PHP and other requests for dynamic content, Nginx must pass to an external processor for execution and wait for the rendered content to be sent back. The results can then be relayed to the client.

• For administrators, this means that communication must be configured between Nginx and the processor over one of the protocols Nginx knows how to speak (http, FastCGI, SCGI, uWSGI, memcache). This can complicate things slightly, especially when trying to anticipate the number of connections to allow, as an additional connection will be used for each call to the processor.

• However, this method has some advantages as well. Since the dynamic interpreter is not embedded in the worker process, its overhead will only be present for dynamic content. Static content can be served in a straight-forward manner and the interpreter will only be contacted when needed. Apache can also function in this manner.

STATIC & DYNAMIC CONTENT: NGINX

Page 21: webservers

• Apache provides a variety of multi-processing modules (Apache calls these MPMs) that dictate how client requests are handled. Basically, this allows administrators to swap out its connection handling architecture easily. These are:

• mpm_prefork (our model)• mpm_worker • mpm_event (new implementation)

CONNECTION HANDLING: APACHE

Page 22: webservers

This processing module spawns processes with a single thread each to handle request. Each child can handle a single connection at a time. As long as the number of requests is fewer than the number of processes, this MPM is very fast. However, performance degrades quickly after the requests surpass the number of processes, so this is not a good choice in many scenarios. Each process has a significant impact on RAM consumption, so this MPM is difficult to scale effectively. This may still be a good choice though if used in conjunction with other components that are not built with threads in mind. For instance, PHP is not thread-safe, so this MPM is recommended as the only safe way of working with ‘mod_php’, the Apache module for processing these files.

CONNECTION HANDLING: APACHE: MPM_PREFORK

Page 23: webservers

This module is similar to the worker module in most situations, but is optimized to handle keep-alive connections. When using the worker MPM, a connection will hold a thread regardless of whether a request is actively being made for as long as the connection is kept alive. The event MPM handles keep alive connections by setting aside dedicated threads for handling keep alive connections and passing active requests off to other threads. This keeps the module from getting bogged down by keep-alive requests, allowing for faster execution. This was marked stable with the release of Apache 2.4.

CONNECTION HANDLING: APACHE: MPM_EVENT

Page 24: webservers

• Nginx spawns worker processes, each of which can handle thousands of connections. The worker processes accomplish this by implementing a fast looping mechanism that continuously checks for and processes events. Decoupling actual work from connections allows each worker to concern itself with a connection only when a new event has been triggered.

• Each of the connections handled by the worker are placed within the event loop where they exist with other connections. Within the loop, events are processed asynchronously, allowing work to be handled in a non-blocking manner. When the connection closes, it is removed from the loop.

CONNECTION HANDLING: NGINX

Page 25: webservers

APACHE & NGINX IMPLEMENTATION• Looking at the features of both technologies we see the strength of

one can complement the weakness of the other. • For great performance both technologies could be used hand in

hand• Placing Nginx in front of Apache helps to leverage the fast

processing ability to handle large number of concurrent requests• While Nginx is a good load balancer and better in delivery of static

content, apache has the internal functionality of processing dynamic content (e.g. PHP) better

• Dynamic requests can be proxied to Apache by Nginx• Nginx returns the process page back to the user/client

Page 26: webservers

APACHE & NGINX IMPLEMENTATION (STATIC & DYNAMIC)server {server_name .example.com;root /home/example.com/www;[...]location ~* \.php.$ {# Proxy all requests with an URI ending with .php*# (includes PHP, PHP3, PHP4, PHP5...)proxy_pass http://127.0.0.1:8080;}location / {# Your other options here for static content# for example cache control, alias...expires 30d;}}

FILES THAT REQUIRE PROCESSING BEFORE BEING SENT TO THE CLIENT, SUCH AS PHP, PERL, AND RUBY SCRIPTS, WILL BE SERVED BY APACHE

Page 27: webservers

GOING CLOUD …..

• AWS; AWS Lambda• A Lambda function and an event source are the core

components that you use when you work with AWS Lambda. Event sources publish events, and a Lambda function is the custom code that you write to process the events that automatically gets invoked in response to events. In addition, you can invoke your Lambda function directly over HTTPS or using AWS SDKs.

Page 28: webservers

THANK YOU