Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2005

Tip: Looking for answers? Try searching our database.

Newbie: Network Sockets and Ports

Thread view: 
boanator@optonline.net - 10 May 2005 16:16 GMT
Can someone tell me if there is a problem with this set up?
I have a server that is listening to a single port (port 6070).
Requests are made to the server at port(6070) and processed.  Clients
will send requests to the server for several different services.  Let's
say there are 10 different services managed by this server.

>From my understanding, each request will setup a new socket for
communication and continue to listen on port 6070 for new client
requests.

Even though each client request creates a new socket for communication,
will it slow things down if all of these requests are going through the
same port 6070, synchronous or not?

Also, will it speed things up if I create a new server for each
service?
Say:
service 1 listens to port: 6070
service 2 listens to port: 6071
service 3 listens to port: 6072
...

Thanks in advance for any advice?
Matt Humphrey - 10 May 2005 18:38 GMT
> Can someone tell me if there is a problem with this set up?
> I have a server that is listening to a single port (port 6070).
[quoted text clipped - 5 lines]
> communication and continue to listen on port 6070 for new client
> requests.

I can't say empirically whether there is a performance difference for
requests on the same port.  I would not expect to find any performance
differences because TCP connections are uniquely identified by their client
ip, the client port, the server ip and the server port. Even requests from
the same client to the same server and same server port will still be
completely separate because the client port numbers will be different.

> Even though each client request creates a new socket for communication,
> will it slow things down if all of these requests are going through the
> same port 6070, synchronous or not?

No. The requests aren't being processed by the port--rather they are handled
by each socket independently, usually in a separate thread which is arranged
to take advantage of potential request parallelism.

> Also, will it speed things up if I create a new server for each
> service?
> Say:
> service 1 listens to port: 6070
> service 2 listens to port: 6071
> service 3 listens to port: 6072

Aside from the time your server requires to parse the request itself, I
can't see any reason that using different port numbers would be
significantly (or even measurably) faster.  Are you considering a
high-performance application and have you done profiling that shows that
socket connection time is a problem?  This issue doesn't seem to be a
problem for the very large scale web servers that have to serve up
documents, images, functionality (servlets, etc.)

Cheers,
Matt Humphrey  matth@ivizNOSPAM.com  http://www.iviz.com/
Ghost - 11 May 2005 01:05 GMT
Thanks Matt and Steve,
Your input was very helpfull.  I have not done any profiling yet.  The
website I am working on consists of JSPs and Servlets that access an
underlying Java server.  The Website consists of 3 different frames
that are constantly refreshing (every 30 seconds).    Each frame must
access the Java server.  I thought each frame was competing for access
to the Java server, but apparently this might not be the problem.

I have been using NetBeans to design new code and view the existing
code.  However, the NetBeans Profiler only works with JVM processes.
Do you have any suggestions on how to profile this Website to determine
where the slow-down might be?
Matt Humphrey - 11 May 2005 12:18 GMT
> Thanks Matt and Steve,
> Your input was very helpfull.  I have not done any profiling yet.  The
[quoted text clipped - 3 lines]
> access the Java server.  I thought each frame was competing for access
> to the Java server, but apparently this might not be the problem.

The constant refreshing could be a problem if you're expecting hundreds or
thousands of requests per minute.  If you want to ensure scalability, are
you sure you need to refresh?  Perhaps you could have an embedded applet or
JavaScript that polls the server every 30 seconds to first find out if you
need to refresh.

> I have been using NetBeans to design new code and view the existing
> code.  However, the NetBeans Profiler only works with JVM processes.
> Do you have any suggestions on how to profile this Website to determine
> where the slow-down might be?

Sorry, I'm unfamilier with profiling JSP.

Good luck,
Matt Humphrey   matth@ivizNOSPAM.com  http://www.iviz.com/
Ghost - 11 May 2005 20:05 GMT
Thanks for the suggestions Matt.  I am looking into JProbe to do the
profiling.
Steve Horsley - 10 May 2005 19:17 GMT
> Can someone tell me if there is a problem with this set up?
> I have a server that is listening to a single port (port 6070).
> Requests are made to the server at port(6070) and processed.  Clients
> will send requests to the server for several different services.  Let's
> say there are 10 different services managed by this server.

I don't see any problem with this arrangement, provided that the
server can distinguish between the different types of requests.

>>From my understanding, each request will setup a new socket for
> communication and continue to listen on port 6070 for new client
> requests.

From the server software's point of view, each incoming
connection causes the ServerSocket to return a new Socket from
its accept() method. The ServerSocket continues to listen for new
calls.

You could simply process one request over each new connection and
then close it, or you may choose to support multiple requests
over one connection, perhaps even allowing a second request to be
sent before the first has been answered. The trade-off is really
efficiency vs complexity. It is probably easiest to start by
handling single requests.

> Even though each client request creates a new socket for communication,
> will it slow things down if all of these requests are going through the
> same port 6070, synchronous or not?

I don't think the port number is relevant. Getting your threading
right, so you can continue to process some requests while others
are waiting for database or disk I/O is the important thing. This
used to be done by using one thread per connection/request, but
the recent java.nio packages allow one thread to service many
connections efficiently by looking to see which ones have data
ready, and this can scale to larger numbers of concurrent requests.

> Also, will it speed things up if I create a new server for each
> service?
> Say:
> service 1 listens to port: 6070
> service 2 listens to port: 6071
> service 3 listens to port: 6072

I don't see why it should. This decision should be based on other
considerations such as ease of implementation, support,
enhancement, flexibility etc.

> Thanks in advance for any advice?

HTH
Steve


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.