Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Asynchronous or Synchronous (http://www.velocityreviews.com/forums/t645993-asynchronous-or-synchronous.html)

Clement 11-25-2008 12:15 PM

Asynchronous or Synchronous
 
Hi....
I am developing a server which needs to do some work for its
client. It may be some calculation that takes some half or one sec.
How should implements.. should i go for ServerSocket with threads or
NIOServers ?

Please help me..

If any related articles there, please let me know...

John B. Matthews 11-25-2008 07:06 PM

Re: Asynchronous or Synchronous
 
In article
<541446c7-2015-4f30-ae6c-0f269c1fea22@s9g2000prg.googlegroups.com>,
Clement <jeba.ride@gmail.com> wrote:

[...]
> I am developing a server which needs to do some work for its client.
> It may be some calculation that takes some half or one sec. How
> should [I] implement [it]? [S]hould [I] go for ServerSocket with
> threads or [ServerSocketChannel]?

[...]

I'm not sure you've supplied enough information to prefer one
approach over the other.

I found this article informative, particularly section nine:

<http://www.cs.brown.edu/courses/cs161/papers/j-nio-ltr.pdf>

Here are some elementary examples:

<http://www.java2s.com/Tutorial/Java/0320__Network/Catalog0320__Network.htm>

--
John B. Matthews
trashgod at gmail dot com
http://home.roadrunner.com/~jbmatthews/

Martin Gregorie 11-25-2008 07:27 PM

Re: Asynchronous or Synchronous
 
On Tue, 25 Nov 2008 04:15:29 -0800, Clement wrote:

> Hi....
> I am developing a server which needs to do some work for its
> client. It may be some calculation that takes some half or one sec. How
> should implements.. should i go for ServerSocket with threads or
> NIOServers ?
>

Just giving the calculation time tells us nothing. We also need to know:
1) the required response time per request
2) how many clients will use the server simultaneously
3) what are the min/average/max request rates per server and in total.
4) is the server handling stateless, i.e. unrelated requests or
does it need to keep a session history for each client?
5) does the server use any shared resources such as a
method that requires locking or a database that it updates?

If you don't know these details which WILL drive the structure of a
heavily used server, then about all you can do is write an unoptimised
first cut version, instrument it to collect statistics for items 1-3 and
release it for production use, see how it performs and be prepared to
rewrite it as needed.

All the performance testing in the world is meaningless if the volumes
and arrival rates don't match what happens in real life.

The server should be designed for change from the outset, not just thrown
together. I'd start with a threaded design that creates a thread for each
incoming connection and kills it when the client disconnects. I'd also
design it with good isolation between the application-specific
calculations and the server management code. Make sure that the
calculation is modular and that each module is instrumented. This way
heavily used and/or resource-intensive modules can be spotted and
replicated more easily.


--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |

Roedy Green 11-26-2008 06:25 PM

Re: Asynchronous or Synchronous
 
On Tue, 25 Nov 2008 04:15:29 -0800 (PST), Clement
<jeba.ride@gmail.com> wrote, quoted or indirectly quoted someone who
said :

> I am developing a server which needs to do some work for its
>client. It may be some calculation that takes some half or one sec.
>How should implements.. should i go for ServerSocket with threads or
>NIOServers ?


Java Concurrency in Practice
http://www.amazon.com/gp/product/032...SIN=0321349601

Discusses the tradeoff. They tend to go for threads on the grounds
coding is simpler and new JVMs can handle much larger numbers of
threads efficiently.
--
Roedy Green Canadian Mind Products
http://mindprod.com
"Humanity is conducting an unintended, uncontrolled, globally pervasive experiment
whose ultimate consequences could be second only to global nuclear war."
~ Environment Canada (The Canadian equivalent of the EPA on global warming)


All times are GMT. The time now is 09:29 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.