Wednesday, September 18

Http 1.0 versus http 1.1 protocol






Http 1.0 versus http 1.1

Http 1.0 is based on thread per request while http 1.1 is based on thread per connection.

What does that mean?

When a user send a request from browser Web Container allocate the request to a thread available in thread pool. Once response is returned ,that thread is released and is made available is pool again . This is http 1.0

In case of http 1.1 , This thread is not released but kept assigned to the user connection . So if user further send request , a new thread is not requested from threadpool instead same thread picks up that request and process that. This is http 1.1 . So here thread is not just one request scoped but stay alive for all connection duration.







Which is good ?

Won't it be a good idea to keep the thread allocated to a connection instead of just thread. In case of thread per request ,once one request is processed , thread is released So for next request http again need to negotiate and may need to wait if all threads are engaged and no ready thread is available in pool. waiting time can vary request to request based on availability of thread in pool. So overall response time for multiple requests would be very inconsistent and user experience can be very unpleasant.

Now let's talk about another scenario. There can a peak load time when thousands of user's areare accessing the website and to server those requests efficienlty it would require many threads . each connection need one thread in thread per connection scenario or once fixed number of threads in thread pool are exhausted next request will have to wait till a thread is available in the pool. So that would require too many system resources and will consume high memory

Moreover a thread will keep on waiting between two user requests. In that idle time thread could be used to do useful task for some other request.

So depending upon scenario you are dealing with there are pros and cons of both http 1.0 and http 1.1 


To remove all these bottlenecks a new approach is followed now a days. asynchronous call with thread per request model. 




 
In this approach
Thread keeps on doing useful task all the time . Anytime a processing consumes time, thread leaves that there and create asyncContext in application context. Once process is done with the current task it triggers an async even and container assign available thread to process further . Thus asynchronous approach is based on call back and a-sync events based techniques . Servlet 3.0 follows the same approach . Threads don't have to keep themselves in idle state while process is blocked for some resource like connection , I/O etc instead java SE 7.0 NIO is used to keep I/O calls non blocking.

 

No comments:

Post a Comment