• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Controlling sequence of processing individual requests

 
Dave Klein
author
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way to control the order of processing of individual requests in Tomcat? Say that 100 requests come in within a 1 second period and the handling of each request takes 3 to 4 seconds. Is there any way to ensure that each of those requests is completed in the order it is received?

Thanks,
Dave
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.
 
Dave Klein
author
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I thought, but I'm being asked to do just that. Can you point me toward any references or articles that would explain this fact? My saying "It doesn't work that way" isn't cutting it.

Thanks,
Dave
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no configuration that controls how the order of unrelated requests are handled. I'm not sure how else to word it.
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I might not be wrong if I say that requests are threaded and thread behaviour is unpredictable. Maintaining such an order is synonymous to running them serially which is not the concept.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to me you could write your own mechanism - how about putting each arriving request Thread in a queue in a long sleep state. A separate working Thread could remove a request Thread from the queue and interrupt it to resume processing.

Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd fear disastrous effects on performance, but if the requirement is more important than reality...

Can you find out the reason of this rather bizarre requirement? It smacks of a sledge-hammer approach to solve another problem that probably has a simpler and less weird solution.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTTP servers are designed to handle all requests at an equal priority. In theory, that means first-in, first-out, but in the case of HTTP servers like Tomcat and Apache, the requests are dispatched to individual handler threads running asynchronously, so the concept of order of arrival doesn't even begin to apply until all the threads in the server are busy and queueing needs to be done.

This isn't just a Tomcat issue, and it isn't just a Java issue. Like the forbidding of unsolicited responses, it's part of the basic architectural definition of how HTTP works as defined in the various RFCs that make up the standards.

If you want some sort of ordering or prioritizing, you'd have to look elsewhere. To make a FIFO out of an HTTP server, you'd actually have to downgrade its functionality (use only one thread). If you're looking at prioritization of traffic, you'd generally have to play games with your routers and switches.

Alternatively, you could use a non-HTTP protocol that supports such refinements, such as a messaging service. However, non-HTTP means that you'll need a custom app to submit them, since web browsers deal in HTTP, and like I said, HTTP doesn't support that.
 
Dave Klein
author
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all, your comments have been very helpful.

Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic