Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I cache the query result in a file in the server side. When a new query is submitted the webservice searches to see if it has the answer in one of the cached files. If so, it will send out the file. If not it will generate the result and send it to the client. Now, when it send the cached file, downloading is much faster (compared to generating the result and sending it in a string format). By download time I mean (the total time the user waits for the response)-(time spent for processing on the server)

Do you have any idea what the reason is? Or any suggestion that how I can find it out?

the webservice is written in ruby and the client is in javascript.

share|improve this question

migrated from Nov 28 '12 at 5:42

This question came from our site for professional and enthusiast programmers.

Sending a file is handled by the operating system. It just jams the content into the socket and requires no overhead from your application. It's literally fire and forget.

Sending a stream of data from the database server is considerably more complicated. The query must be composed, encoded, sent over the socket, interpreted by the server, executed, and the result set must be re-encoded and sent back over the wire. Maybe you're deducting this time from your calculation, but it's not clear.

Then, once the client has received the result, it must read it off the socket, convert it to Ruby objects, possibly models that incur even more overhead, and hand that result object back to the requesting method. If you're then re-serializing it into a result it has to go through the process of copying this data a second time into the output stream.

So in summary, reading from a pre-existing file: Zero reads, zero copies.

Reading from the database: One read, two copies.

share|improve this answer
thanks tadman. I should point out that I'm already deducting the time spent on the server. And also when the client receives it, I calculate the time before it does anything(like converting to objects,...) In fact, data is sent in JSON format in both cases. – Elaheh kamaliha Nov 28 '12 at 20:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.