1

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.

0

1 Answer 1

2

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.

1
  • 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. Nov 28, 2012 at 20:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .