I don’t know if it’s simply because page-loads take a little time, or the way servlets have an abstraction framework above the ‘bare metal’ of HTTP, or just because of the “Enterprise” in Jave-EE, but in my head I have the notion that a servlet-based app is inherently adding overhead compared to a Java app which simply deals with sockets directly.
Forget web-pages, imagine instead a Java server app where you send it a question over an HTTP request and it looks up an answer from memory and returns the answer in the response. You can easily write a Java socket-based app which does this, you can also do a servlet approach and get away from the “bare metal” of sockets.
Is there any measurable performance impact to be expected implementing the same approach using Servlets rather than a custom socket-based HTTP listening app?
And yes, I am hazy on the exact data sent in HTTP requests and I know it’s a vague question. It’s really about whether servlet implementations have lots of layers of indirection or anything else that would add up to a significant overhead per call, where by significant I mean maybe an additional 0.1s or more.
Of course there is some overhead. What it’s hard to define is how much, not because it’s hard to measure, but because it’s hard to find an alternative which doesn’t introduce the risk of being more fragile, bug ridden and poorly scalable.
In other words, supposing you are really dying for performance… will you roll out you own server? How will it deal with managing concurrent requests (all hitting the same port)? Will you write your own parser for the HTTP request? Will it be able to work correctly with all browsers? How will you recognize a session from a given client?
In other words your question is a bit like asking “do relational DBs introduce a significant overhead when measured against an imaginary custom datastore which nobody has written yet but that would cut out all the unecessary features in favour of raw speed?”
My answer: yes, of course. I would still use a DB, because it works now, and has been tuned for lots of things developers take for granted, but are horribly inefficient to reinvent every time you discover you need them for your application.
I strongly suggest, in case you haven’t already, to have a look at Jetty, and specifically at the WebSockets implementation.