63

Why isn't it sensible to dedicate more than one TCP/IP port to http? Although admittedly naive, isn't it intuitive to think that server performance could somehow be increased?

Marcos Gonzalez
  • 1,081
  • 1
  • 12
  • 13

10 Answers10

74

Port 80 is a well-known port, which means it is well-known as the location you'll normally find HTTP servers. You can find it documented in the HTTP/1.1 RFC.

Having a default is useful precisely because you don't have to type it into your web browser with the URI. If you run an HTTP server (or in fact any service) on a non-standard port, you force the client to remember which arbitrary 16-bit number you chose and type it in.

In addition to this unfriendliness, there is no performance benefit: a port is just one part of the (dst ip:port, src ip:port) 4-tuple which uniquely identifies a TCP connection. If two connections share a dst ip:port, that doesn't mean they share some system resource - they can reside in different threads, or different processes.

Now, if you have logically different services which both happen to use HTTP, there is no problem with running them on different ports. It just makes the URI a little uglier.

Useless
  • 866
  • 6
  • 4
30

The server doesn't waste resources by handling connections in one or more ports. Server resources are allocated to handle connections, and the port number is just a way to connect a specific program to a specific connection.

For example: the HTTP server knows that he'll listen to connections that come in the port 80. And the server knows that anytime he receives some request on port 80, he'll handle it to the http server. After that, the http server will handle the communication and then will consume resources.

woliveirajr
  • 1,002
  • 2
  • 14
  • 18
28

You seem to think of ports as something real; its just a 16-bit unsigned number (0-65535) that's a label in the header of an IP packet. This helps with application-level multiplexing. When an incoming packet arrives at a network card, the OS gets a notification. It checks what port the incoming packet was directed to, and then forwards the packet to only the right application. If you are running your webserver (nginx) to listen on port 80, only nginx gets packets sent to port 80.

When a client (IP: 100.200.100.200) makes an HTTP request to server (55.55.55.55), they make that request to destination port 80 on the server (55.55.55.55:80), but the source port is randomly chosen by the OS for the web browser (something like 45490). The HTTP response from the web server then comes from (55.55.55.55:80), but sent to the destination (your IP) (100.200.100.200:45490). Your computer's OS knows that incoming packets on port 45490 (from 55.55.55.55:80) need to be given to the web browser that made the request. As each unique connection to a web site from the client gets a unique random port, so you can have multiple web browsers connecting to the same web site and when a page is reloaded in one browser the other windows aren't affected.

Each IP packet has both the source and destination IP addresses and port available to it in the header. The OS and application (web browser or web server) can use both to figure out the appropriate action on how to process the packet.

dr jimbob
  • 381
  • 2
  • 6
15

Port 80 & 443 are the "default" ports for HTTP/HTTPS

This means that you do not have to specify the port (http://www.example.com:80, https://www.example.com:443) when using a web browser.

If you want to have a webserver listening on any other ports, the users have to manually add the port to the URL, or it has to be encoded in any link to that particular port.

Also, most Proxies and Firewalls will not let connections to those ports unless specifically configured to do so (Without configuration, Outgoing proxies won't be listening to non-default ports, hence will not forward the request to the webservers, while Firewalls would simply block non-TCP80/443 connections attempts)

All of this limits what can be done at the TCP/IP level

One way of boosting performance would be by having a load balancing device/service listening to TCP80/443 which would then redirect the request to servers on different ports and/or ip (Local Balancing) or even different remote sites (Global Balancing). But this is another topic altogether

Remi Letourneau
  • 2,204
  • 13
  • 14
12

Adding extra ports does not add extra bandwidth or anything like that, a port is more of a label than a pipe, it can "grow" as wide as you need it to without getting any slower due to the pipe being full.

If a server receives too many requests, the server will of course slow down, however this is not the type of issue that can be fixed by adding another port number.

David
  • 221
  • 1
  • 6
9

Each TCP/IP connection has a sourceIP:sourcePort and a destinationIP:destinationPort.

When you initiate a connection, you would always use 80 as the destination port (which makes sense since the Server needs to only listen on port 80 for HTTP and not on several ports). The trick is that the sourcePort is dynamic for each connection.

Example:

user1: 1.1.1.1:29999 to 2.2.2.2:80

user2: 1.1.1.2:45333 to 2.2.2.2:80

Mike Pennington
  • 30,049
  • 12
  • 82
  • 153
Thieron
  • 446
  • 2
  • 4
9

If you used random ports, the user would have to add the correct port numbers each time they went to your site. i.e. www.example.com:80; www.example.com:81; www.example.com:82 etc

It would not increase performance to use more ports. The source ports for each connection an ephemeral ports and so different anyway

mellowd
  • 3,844
  • 21
  • 24
4

Don't mistake a different port for a different physical connection or a higher network bandwidth or server processing performance. What the server gets are TCP or UDP packets, which happen to have a port number as part of the address. They still come over the same wires, go through the same network interface hardware and driver, and so on.

If you were to send two packets to a server, in terms of resources the server expends to process these two packets it doesn't matter if one of the two have different port numbers or the same port numbers associated with them, the internal handling will be close to identical.

Therefore, this is not a method to increase performance in any way.

The only possible exception to this is if you were to associate two different demons (or two copies of the same) running at the same time to the two different port numbers, and if each of these demons would scale up extremely badly with load. Which is typically not the case.

3

As Remi mentioned, Port 80 & 443 are the "default" ports for HTTP/HTTPS.

Most networks and firewalls don't block traffic going through this ports. So using this ports is easier as most of the time you may not need to worry about firewalls blocking your service else you may have to go through reconfiguring firewall rules and getting approvals from compliance/security for same.

2

As everyone else on here has said, it is basically pointless to host a web server on any port other than port 80... unless you're hosting it from home. Many ISPs throttle outbound TCP/UDP ports 80 and 443 (IANA defines as HTTP and HTTPS, respectively), and in this case, using those ports will detract from site loading speeds, etc. However, IANA has assigned 3 HTTP-ALT ports for both TCP and UDP. These are: 591, 8008 and 8080. Using these ports is also acceptable, but you will be making the life of server admins hell.

Source of port numbers: https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml