How many requests can handle a port at 'a' time
Asked Answered
M

4

5

I am creating a web application having a login page , where number of users can tries to login at same time. so here I need to handle number of requests at a time.

I know this is already implemented for number of popular sites like G talk.

So I have some questions in my mind.

"How many requests can a port handle at a time ?"

How many sockets can I(server) create ? is there any limitations?

For e.g . As we know when we implement client server communication using Socket programming(TCP), we pass 'a port number(unreserved port number)to server for creating a socket .

So I mean to say if 100000 requests came at a single time then what will be approach of port to these all requests.

Is he manitains some queue for all these requests , or he just accepts number of requests as per his limit? if yes what is handling request limit size of port ?

Summary: I want to know how server serves multiple requests simultaneously?I don't know any thing about it. I know we are connection to a server via its ip address and port number that's it. So I thought there is only one port and many request come to that port only via different clients so how server manages all the requests?

This is all I want to know. If you explain this concept in detail it would be very helpful. Thanks any way.

Mannos answered 29/2, 2012 at 11:10 Comment(3)
This depends on the number of threads you have serving the requests?Decaffeinate
pls check this link its already answered here #1575953Showman
Sorry but ,here my question remains continue after all these appreciable replies, that How many requests can a port handle at a time?Mannos
P
7

A port doesn't handle requests, it receives packets. Depending on the implementation of the server this packets may be handled by one or more processes / threads, so this is unlimited theoretically. But you'll always be limited by bandwith and processing performance.

If lots of packets arrive at one port and cannot be handled in a timely manner they will be buffered (by the server, the operating system or hardware). If those buffers are full, the congestion maybe handled by network components (routers, switches) and the protocols the network traffic is based on. TCP for example has some methods to avoid or control congestion: http://en.wikipedia.org/wiki/Transmission_Control_Protocol#Congestion_control

Pelletier answered 29/2, 2012 at 11:19 Comment(2)
Well then to remove this scenario of congestion, how should i modify my application at code and hardware level?Mannos
Your code should handle as much request as possible in parallel. If one request requires 1 second to process, you'd need 100,000 threads to handle 100,000 requests a second.Pelletier
C
1

This is typically configured in the application/web server you are using. How you limit the number of concurrent requests is by limiting the number of parallel worker threads you allow the server to spawn to serve requests. If more requests come in than there are available threads to handle them, they will start to queue up. This is the second thing you typically configure, the socket back-log size. When the back-log is full, the server will start responding with "connection refused" when new requests come in.

Candlemaker answered 29/2, 2012 at 11:18 Comment(1)
Yes that is what my question is. I don't want this "Connection Refused" scenario to happen. for this how can i modify my application at hardware and code level? 1. should i use multiple ports for accepting millions of connections 2. should i modify JVM memory or some kind of that memory level stuff 3. should i use executor, selector, or NIO ? 4 what should be my hardware to handle this kind of huge application requirement?Mannos
W
1

100,000 concurrent connections should be easily possible in Java if you use something like Netty.

You need to be able to:

  • Accept incoming connections fast enough. The NIO framework helps enormously here, which is what Netty uses internally. There is a smallish queue for incoming requests, so you need to be able to handle these faster than the queue can fill up.
  • Create connections for each client (this implies some memory overhead for things like connection info, buffers etc.) - you may need to tweak your VM settings to have enough free memory for all the connections

See this article from 2009 where they discuss achieving 100,000 concurrent connections with about 20% CPU usage on a quad-core server.

Workingwoman answered 29/2, 2012 at 11:24 Comment(1)
@mikera.-May be NIO will handle the request when socket will listen to it. but if the socket is very busy accepting other simultaneous connections , then how will the NIO will be useful?Mannos
A
1

Then you'll probably be restricted by number of File Descriptors your os supports (in case of *nix) or the number of simultaneous connections your webserver supports. The OS maximum on my machine seems to be 75000.

Aesthetic answered 29/2, 2012 at 11:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.