• No se han encontrado resultados

FORMATOS DE LOS INSTRUMENTOS APLICADOS GUÍA DE ENTREVISTA

ACTIVIDADES

ANEXO 07: FORMATOS DE LOS INSTRUMENTOS APLICADOS GUÍA DE ENTREVISTA

I don’t suggest changing this, but it’s good to know that you can change the Apache log directory, and have a place to check to see where it is set.

An example of when you may wish to change this path is if running Apache in a Docker container. This depends on how you choose to handle log files generated processes in Docker containers.

There are other directives in theenvvarsconfiguration. Adjusting them is less commonly needed.

One is performance related:APACHE_ULIMIT_MAX_FILES. You may want to increase this if fine-tuning Apache performance. Each process is treated like an open file, so you may max-out the Apache or operating system limit on the maximum number of open files.

MPM Configuration

Theenvvarsconfiguration also has settings to fine-tune the Multi Processing Modules (MPM). We can define how MPM manages processes and threads.

Apache 120 Everything discussed here is also found in Apache’sMPM documentation³⁶.

Many of these settings are related to how Apache will handle spawning processes and threads. These are worth looking at when attempting to get more performance out of your server.

Remember that the default MPM Prefork only creates child processes. Other MPM’s (Worker and Event) spawn processes which create threads.

Here are worthwhile directives to know about. Keep in mind the difference between processes and threads!

MaxConnectionsPerChild - Limits the number of HTTP connections per child process. When the limit is reached, the process dies, to be replaced with a new one. This works regardless of if threading is used (MPM Event/Worker) or not.

MaxRequestWorkers - This limits the number of simultaneous requests being served. Any new request received after this limit is reached is put in a queue.

For MPM Prefork, this means the max number of processes launched to handle requests. The default is 256. To increase this, you must also increase theServerLimitdirective.

For MPM Worker/Event, this means the max number of threads available to serve requests. The default is 400, reached by the following calculation:

16 processes (defaultServerLimit) * 25 (defaultThreadsPerChild) = 400 requests.

To increase this passed 16 processes and 25 threads per process, you may need to raise the ServerLimitandThreadsPerChilddirectives.

MaxSpareThreads - The maximum number of idle threads.

Prefork has no threads, so this relates only to threaded MPM’s

For MPM Worker/Event, the default is 250. The setting is server-wide, meaning both idle threads and their processes will be killed to reach this number.

Each process/thread takes up a small about of memory, so having a maximum number of idle threads can help save memory usage.

However, idle threads can handle requests more quickly as they don’t need to be created before handling a request. Having a fair number of idle workers can help performance, especially for handling request spikes.

MinSpareThreads - This is the minimum number of idle threads that can exist. Naturally the minimum shouldn’t be higher than the maximum.

Prefork has no threads, so this relates only to threaded MPM’s.

For MPM Worker/Event, the default is 75. The setting is server-wide, meaning both idle threads and processes are created until the number is met.

³⁶http://httpd.apache.org/docs/2.4/mod/mpm_common.html

Apache 121 ServerLimit - This is an overall setting which limits other settings we’ve discussed previously. This is the upper limit on configurable number of processes. All other configurations cannot create more processes than this setting allows.

For MPM Prefork, this simply limits the number of processes set by MaxRequestWorkers. Set ServerLimithigher if you need to seMaxRequestWorkersabove the default of 250.

For MPM Worker/Event, this works in conjunction withThreadLimitto set the maximum value for MaxRequestWorkers.

Increase ServerLimit if you wish to increase the number of processes available. Remember that each process will create new threads until it reaches theThreadLimit. Under MPM Worker/Event, the default is 16 processes.

Apache will try to allocate memory to meet possible values of ServerLimit, so it should not be set too high. Otherwise memory will be allocated but not used - a waste of resources.

StartServers - This is the number of child processes created at startup. Idle processes and threads allow Apache to quickly respond to new requests. More processes are created as needed on the fly, so this setting may only need adjusting in special cases.

MPM Prefork defaults to 6, while MPM Worker defaults to 3.

StartThreads - The number of idle threads to create on startup. Only relates to threaded MPMs (Worker/Event). Like processes, threads are also created dynamically as needed.

ThreadLimit - Similar toServerLimit, this sets an overall maximum for the server. In this case, it’s limiting the number of threads per process, rather than the total number of processes.

The default is 64 threads. Be careful not to set this too much higher thanThreadsPerChilddue to its potential in wasting unused allocated memory.

ThreadsPerChild - This is the number of threads created by each process. The process creates these threads at startup and never creates more.

The default value is 25 threads. Multiply this by the number of processes in existence to find your total number of threads.

The preceding configurations can all be tweaked to match what your server can handle.

The number of configured processes and threads should depend on the CPU cores and RAM available for Apache.

Nginx

“Apache is like Microsoft Word, it has a million options but you only need six. Nginx does those six things, and it does five of them 50 times faster than Apache.” - Chris Lea Nginx is a lightweight alternative to Apache. Actually, by some metrics, it has overtaken Apache in popularity. Calling it an “alternative” is doing it a disservice.

Nginx is similar to NodeJS, HAProxy, and other “web scale” technologies (put in quotes, only a tad sarcastisically). Nginx runs as an evented, single process. It manages requests asynchronously. This helps Nginx work with a large number of concurrent connections while using a stable and relatively low amount of memory.

Actually Nginx typically uses a few processes. A typical setup with Nginx will spawn as many processes as there are CPU cores on the server.

Apache, as we learned, spawns processes or threads for each connection. Its synchronous manner means that processes and threads pause (“block”) while performing slower tasks.

Examples of such tasks are reading from the file system or performing network operations. This means that Apache processes are “blocking”; We must wait for them to finish their task before moving onto the next one.

While Apache spawns many processes and threads, Nginx spawns very few processes (“workers”).

Each process is single-threaded. Nginx workers accept requests from a shared socket and execute them inside of an efficient run-loop. Nginx is asynchronous, evented and non-blocking. It is free to accomplish other tasks while waiting for slow tasks such as file I/O or network operations to finish.

Each Nginx worker can process thousands of simultaneous connections. It avoids the overhead of constantly creating, tracking and destroying new processes/threads. This is much more memory and CPU efficient.

Features

Nginx has grown an impressive feature set, most of which is pretty easy to use and setup. Nginx can act as a:

• Web Server

• Reverse Proxy (“Application Proxy”)

Nginx 123

• Content Caching (“Web Cache”)

• Load Balancer

• SSL Terminator

Nginx also has a commercial (paid) version. Notable Nginx Plus features include:

• Advanced load balancing, including dynamically adjusting available servers/nodes

• Advanced caching

• Streaming media abilities

• Monitoring capabilities

Let’s go over the Web Server and Reverse Proxy functionality. These compare directly the previous chapter on Apache. They are what we will most likely need when getting started with Nginx.

Installation

We’ll use Nginx’s “stable” repository for installation. It allows us to get the latest stable versions which can include bug fixes and security updates.

If you have Apache installed on the same server, you’ll run into issues starting Nginx, as they both attempt to bind to port 80. You’ll need to stop Apache withsudo service apache2 stop. I recommend, however, creating a new server if you’re following along here on a local virtual machine.

Here’s how to install Nginx:

1 sudo add-apt-repository -y ppa:nginx/stable 2 sudo apt-get update

3 sudo apt-get install -y nginx 4 sudo service nginx start 5

6 # Set Nginx to start on boot.

7 # Likely is already set.

8 sudo update-rc.d nginx defaults

Now we can see if this is indeed installed on our server. Let’s see if we get an HTTP response:

Nginx 124

1 $ curl -I localhost 2 HTTP/1.1 200 OK 3 Server: nginx/1.6.1

4 Date: Thu, 03 Jul 2014 00:49:14 GMT 5 Content-Type: text/html

6 Content-Length: 612

7 Last-Modified: Thu, 24 Apr 2014 12:52:24 GMT 8 Connection: keep-alive

9 ETag: "53590908-264"

10 Accept-Ranges: bytes

Great! We get a response. Nginx is on and working!

Documento similar