aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Open ports in a huge web application. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Open ports in a huge web application." Watch "Open ports in a huge web application." New topic
Author

Open ports in a huge web application.

Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
After a long time I am visiting JR , looks great !

Here goes the question !
Say suppose there is a very huge site (terms of traffic that it gets) , like Facebook.com , which draws a lot of users.This question is about scalability. Below I have mentioned some of the technical details , which might be worth going through to understand the question that I am going to state later.

When a web page opens up in our browser , it establishes a persistent TCP/IP connection.It’s persistent because it keeps the connection open and uses the same connection for multiple HTTP request response pairs.It a connection remains open for certain amount of time , then the client/browser closes it by sending a TCP packet with it’s fin bit set. So there exists a communication channel with a port in the user’s workstation and a port in the server hosting the website. Now the port number is specified using 16 bits unsigned type , which means that there can be at most 65536 ports in a computer. I am ignoring the fact that ports below 1024 are reserverd.

So the question is , is it that at any given point of time no more that 65K users are online concurrently ?

I am sure that it’s possible but how ?

My take , but wanted to confirm it or my understanding might not be completely correct , so please point to some good resources.

Say the site that I am talking about is www.fakeit.com , so when my browser requests for the IP of www.fakeit.com then the DNS sends the request to the dns of the domain fakiit.com and it returns the IP of a host which is less loaded. So the DNS of fakeit.com acts as the load balancer and there can be a lot of host and multiples of 65K ports.


Thanks,
Rahul Bhattacharjee
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42950
    
  71
Server sockets work differently than client sockets - they can (and generally are) multi-threaded and can serve multiple clients simultaneously. So the server app only uses a single socket (generally port 80 for web apps) for multiple clients.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Yes , there is a single server socket listening to all the requests , but once the server socket accepts a request , it creates another socket (with a different port number) in the server.Now the communication happens between the client socket and the new server socket and the original server socket goes back to listening for more requests.

So , my question still holds good , unless I am missing something silly here.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42950
    
  71
Got you. It depends on what one means by "concurrent users". Even keep-alive connections are closed after a period of inactivity (my Firefox has it set to 115 seconds).

If you actually have a web app that is accessed by that many users on an ongoing basis (so that the timeout doesn't kick in) you'll most likely have to resort to multiple servers much sooner than you reach that number of users.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Thanks Ulf. One last thing for confirmation.

Yes , but how do we add multiple servers. Is that something the DNS would take care of . Suppose my site's host name is www.fakeit.com and I have multiple servers with my application running on those. And there would be one DNS for my domain (dns for fakeit.com) .

So when the browser requests the IP of www.fakeit.com , the dns query reaches my dns (the dns to handle name-ip resolution for only fakeit.com) and it returns the ip of the host which it thinks has less traffic (which has open ports). Is it how this works ?

Thanks,
Rahul Bhattacharjee
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42950
    
  71
It could work that way, but probably doesn't. Load balancing isn't really something you want to handle on the DNS level (at least not completely). See Round robin DNS for some discussion of that.

If we're talking web apps, then you could have Apache handle it, or Apache and Tomcat together.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Thanks a lot Ulf

Regards,
Rahul Bhattacharjee
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Open ports in a huge web application.