Showing posts with label Apache. Show all posts
Showing posts with label Apache. Show all posts

Wednesday, April 3, 2013

Apache config for Worker MPM vs Prefork MPM

Some installations of Apache will have been compiled to work with either Prefork or Worker MPM, but most by default are compiled only to work with Prefork. Changing to Worker MPM may allow your server to handle much higher traffic, more user sessions, with less RAM use. Your site or server will not scale well if it is running Prefork MPM. Worker is a bit more difficult to set up properly, and has some restrictions regarding functionality of PHP scripts.

To determine which MPM is currently running 
/usr/sbin/apachectl -l
If you see worker.c in the list of loaded modules, your Apache is running Worker MPM.
 If prefork.c, it is running prefork.






Monday, March 25, 2013

High system calls in Apache?

In apache web server the system calls are very high  (find using strace tool)

Sol: In httpd.conf disable the Extended Status
ExtendedStatus off

"Reached max clients" error in web server?

Verify the error in err_log file, it shows the "Reached max clients" error.
 If you found this error verify how many http process are running
                                # ps -ef|grep -c httpd|wc -l
                                #17
Open the httpd.conf file and verify the the maxClients is 16.

So web server reached max clients , for that it thrown the "Reached max clients" error in web server?

Solution:
Step 1:Find out the how much memory on avg each http process is using

                       #top -b -c -n 1|grep httpd|awk '{print $6}'
                       #18m
                         18m
                         18m
                         20m
                         18m
                          15m
                 (or) use below script 

 ps -ylC httpd | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}'

Avg: 18m

Step 2 : Stop Apache , determine the amount of Free memory available (without running apache)

                     #free -m
                     #total        used    free
                       432        26        405
Step 3: It is good to have at least 20mb of free memory , if apache was running at it max.

                        = free memory - 20mb
                        =385
Step 4:
 
                            free Memory after stopping Apache - 20 mb
     maxClient =  __________________________________
                                   avg http consuming memory

                maxClients = 385/18
                                    =21
                                    =round (21)
                                    =20

So maxClients in httpd.conf is 20

Why my web server memory utilization is very high?

Sol 1:
Use sttaic IP's instead of wildcard IP's(*).

virtualhostIP.conf (in this file don't use wildcard character)

uses less memory 
<virtualHost 10.62.55.11:80>
<virtualHost 10.62.55.11:443>

Uses More memory

<virtualHost *:80>
<virtualHost *:443>


listenIPs.conf (in this file don't use wildcard character)


uses less memory 
<listen 10.62.55.11:80>
<listen 10.62.55.11:443>

Uses More memory

<listen *:80>
<listen *:443>

Sol 2:

Comment unnecessary modules in you httpd.conf file

 if not using perl comment it
if not using CGI comment it




Sunday, March 18, 2012

Too many files opened issue

How to solve too many files issue?

This issue occur in two areas
1. If Web server, App server and Data base servers residing in One machine, then you m ayget this error
2. If socket timed out not mentioned then this issue may this issue.

Using ulimit -a command, we will find how many sockets had that machine. In any machine 1024 is the maximum sockets.

Bottleneck identification:

Using netstat -a|grep WAIT|wc -l command we will find how many sockets opened by the application. If 1024 connection are utilized then we will get too many open files.

If you want know which server opened more socket, just use lsof -p <Process ID> for finding the sockets opened by that process.

Internal Process  of a socket: All HTTP requests internally used TCP connection. One TCP connection is one Socket in computer science language. So if you send n number of requests to the server , the server opens the socket to handle your requests but we need to close the sockets once your request got over other wise socket won't close, for this we need to mention the socket timed out.

Solutions:

For issue 1: Just increase the sockets using ulimit -Hn <Parameter> (Ex ulimit -Hn 2048)command, but it is not recommended , you have to discuss with your architect on this.

For issue 2: Just provide the socket time out in your server configuration file. In web server change the value in  uri_worker.property file



Where web server residing in any Application architecture?


Web server always residing before the Application server. The request flow from client to server shown below

        Client-->Web server --->Application server ---->Data base Server.
1.Client sends the request to the server
2.web server takes the request from the client,if the request has business logic then using load balancing request will goes to the Application server
3.Request will goes to DB server using the connection pool configuration.

How HTTP request passes through OSI layers for communicating the web server?


In this way, HTTP is the top layer in a "protocol stack" of "HTTP over TCP over IP," as depicted in Figure shown below. A secure variant, HTTPS, inserts a cryptographic encryption layer (called TLS or SSL) between HTTP and TCP .

HTTP Request Vs ISO layers
When HTTP wants to transmit a message, it streams the contents of the message data, in order, through an open TCP connection. TCP takes the stream of data, chops up the data stream into chunks called segments, and transports the segments across the Internet inside envelopes called IP packets . This is all handled by the TCP/IP software; the HTTP programmer sees none of it.


Monday, March 5, 2012

Causes for websites slow?

1. A client first needs to determine the IP address and port number of the web server from the URI. If the hostname in the URI was not recently visited, it may take tens of seconds to convert the hostname from a URI into an IP address using the DNS resolution infrastructure.
 Luckily, most HTTP clients keep a small DNS cache of IP addresses for recently accessed sites. When the IP address is already "cached" (recorded) locally, the lookup is instantaneous. Because most web browsing is to a small number of popular sites, hostnames usually are resolved very quickly.
2. Next, the client sends a TCP connection request to the server and waits for the server to send back a connection acceptance reply. Connection setup delay occurs for every new TCP connection. This usually takes at most a second or two, but it can add up quickly when hundreds of HTTP transactions are made.
3. Once the connection is established, the client sends the HTTP request over the newly established TCP pipe. The web server reads the request message from the TCP connection as the data arrives and processes the request. It takes time for the request message to travel over the Internet and get processed by the server.
4. The web server then writes back the HTTP response, which also takes time.
The magnitude of these TCP network delays depends on hardware speed, the load of the network and server, the size of the request and response messages, and the distance between client and server. The delays also are significantly affected by technical intricacies of the TCP protocol.

Thursday, February 23, 2012

How web browser communicates with web server?


Here are the steps:
(a) The browser extracts the server's hostname from the URL.
(b) The browser converts the server's hostname into the server's IP address.
(c) The browser extracts the port number (if any) from the URL.
(d) The browser establishes a TCP connection with the web server.
(e) The browser sends an HTTP request message to the server.
(f) The server sends an HTTP response back to the browser.
(g) The connection is closed, and the browser displays the document.
Below is the Example:


What is web server? What is the Use of Web server?



Web server is a server, it handles HTTP protocol. When web server receive the http request (Ex http://gmail.com), it respond with an http response, such as sending back an HTML page.

In detail below is the example for http request and Http response
Uses of Web server:
1. Reduce the traffic to App server (all static data can handled by Web server only business logic should go Application server)
2. Most secure because it captures the end user system information like
a. IP address,
b. Browser information (which browser),
c. what request user sent
d. which OS end user using and
            e. Date and Time

Examples for web server: