views:

1204

answers:

3

Hi All

I am implementing a multi-threaded web service. A thread is spawned per incoming request. For each client, a session is created and each session contains a data section - say a DOM tree. Client requests will basically be get/set methods and the server will read/write the DOM.

So the DOM data is per client.

Now my question is, should the server treat this DOM tree as a critical section?

Basically the question is will there be a scenario where the server has two threads which are servicing the same client?

The request/response are SOAP over tcp. As per my understanding, a tcp client cannot send simultaneous requests even if the client is multithreaded. So at the server side, I will not have a situation where two threads are for the same client. Please correct me if I am wrong, I am new to tcp/ip client-server programming.

Thanks.

A: 

You should take in account that thread-per-request won't scale good for higher rates of requests, you'll lose most of the time doing thread-switching

Arkaitz Jimenez
I think you mean creating and destroying threads, switching between threads is no problem. This overhead however can be resolved with thread pools.
tstenner
thread pools help, but appropriately resizing them is a chore. anyway, you'll be bogged down by SOAP even sooner than by multithreading
Javier
if u have 10000 requests and u have 10000 threads you need to change thread context 10000 times to attend each of them in a 1 core machine, change context, deal cache faults due to the stack change and more, it only scales well for low rates
Arkaitz Jimenez
Thread pools solve this problem. Also, if you have 10000 concurrent requests you will likely need a server that has more than 1-core?
Cheeso
@Cheeso, still doesn't scalate properly, 2 cores 5000 per-core, not a good deal.Thread pools doesn't solve this, thread pools solve the thread creation overhead, here we are talking about thread switching overhead
Arkaitz Jimenez
A: 

you need to check it with your server's documentation. advanced server most probably allows you to configure request handling strategy (e.g., sequential, thread per connection, thread per request, thread pools, etc.).

I'm afraid that the client can send simultaneous requests if it's multithreaded.

oo_olo_oo
+1  A: 

As per my understanding, a tcp client cannot send simultaneous requests even if the client is multithreaded.

?? where did that come from?

In HTTP, which is of course based on TCP, concurrent client requests are expected. RFC2616 says that HTTP Clients (browsers, REST clients, etc) SHOULD limit the number of concurrent outbound requests to a particular server, to 2. But this is not a firm requirement of the protocol, and this guideline is sometimes purposefully not followed in some architectures.

I raise this only to illustrate that TCP itself supports multiple concurrent outbound requests by clients. In the general case, a TCP client can open many many concurrent outbound requests.

It may be that a particular communications framework you are using does not support multiple concurrent outbound requests by clients. But that is a different matter.

Cheeso