I came across this article on WebPerformanceInc, which explain about establishing TCP connection and different reasons for connection failures…felt interesting.
Load Tester is a web site load testing tool, and as such we deal primarily with the most popular Internet communications protocol: the Hypertext Transfer Protocol, or HTTP, which controls the request and transmission of web pages between browser clients and web servers. HTTP is based on a lower-level protocol known as the Transmission Control Protocol, or TCP. For the most part, TCP works in the background, but its proper function is critical to your website, and problems at the TCP level can show up in many different ways during a load test. These errors can sometimes be difficult to troubleshoot, requiring a packet sniffer such as Wireshark or tcpdump to analyze, while others are simpler.
TCP uses the concept of “ports” to identify and organize connections. For every TCP connection, there are two ports – the source port, and the destination port. For our purposes, the most important ports are port 80 and port 443, which are the two most common ports utilized by web servers – 80 for normal HTTP traffic, and 443 for SSL-encrypted traffic. A typical TCP connection from a client to a webserver will involve a random source port such as 44567, and a destination port on the server of port 80. Each web server can accept many hundreds of connections on port 80, but each connection must come from a different source port on each client.
To create these connections between ports, TCP relies on a three-way handshake. The requesting client first sends a packet with the TCP SYN flag set, indicating that it wants to open a connection. If the server has a process listening on the destination port, it will respond with a packet that has both the SYN flag set and the ACK flag set, which acknowledges the client’s SYN and indicates that a connection can be created on that port. The client then sends a packet with the ACK flag set back to the server, and the connection is established. The current connections can be viewed using the netstat tool on both Windows and Linux.
What does it look like when a TCP connection attempt fails? The TCP packet with the SYN flag is sent from the client, which in our case is a load engine. If the server sees such a packet, but does not have a process listening on the target port, it will typically respond with a TCP packet that has the ACK and RST flags set – a TCP reset. This tells the client that connections are not available on this port.
Load Tester showing a connection refused (ACK RST)
So … what happens when the remote server does not respond?
Load Tester showing a connection timeout (dropped packet)
Of course, TCP connections can also fail after a connection has been established. Here’s an example:
Load Tester showing a server connection termination
In a real test, there’s a pretty large number of things that can cause this error, from server process crashes or errors, to overly aggressive firewalls, to reverse proxy failures, to misdirected traffic on a load balancer. In such a case, a traffic analyzer such as Wireshark or tcpdump can be very helpful in determining what is happening. Note that you may need to observe traffic in more locations that in front of the load engine or the controller though, as traffic can be altered by firewalls and load balancers.
----
No comments:
Post a Comment