Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending data in gzip format caused the ajax progress stopped for a while

I am maing an ajax call via jquery and in server side I am using PHP. The purpose is to bring a big JSON data from server side. As the JSON size is big that is why I am using gzip compression while sending the data.

In server side;

ob_start('ob_gzhandler');
header('Content-Encoding: gzip');

Now I am seeing significant amount of reduce in data size which is being transferred. But I am seeing that the ajax call progress get stuck in between for a while (I am checking via chrome network monitoring area).

The observation is as follow;

1. Call status showing pending for around 23 sec (which is perfect as it is exactly same time to generate the JSON)

2. Data transfer starts on 24th sec, and continues to transfer 94.4 kB data in next 5 to 6 sec

3. After that it got stuck for 20 sec almost, when the time does not increase even, I mean it shows same time that stays in point 2.

4. And then suddenly it shows ajax call completed and I am getting full data and time shows directly to around 56sec. And the data size remains same that is 94.4 kb, which means no extra data has been transferred in stage 3 and stage 4

So can you please explain me the stage 3 and stage 4, I am not getting the reason of this kind of behavior.

And kind of help will be very much helpful. If you need any more information please let me know.

like image 740
KOUSIK MANDAL Avatar asked May 03 '18 09:05

KOUSIK MANDAL


3 Answers

To me this behavior seems related to how the gzip compression works.

The timings you are seeing cannot be interpreted in the same way as w/o the gzip compression because you have more things happening:

  • buffering of the data on the server side for compression
  • doing the actual compression after buffering is complete
  • sending the much smaller compressed data over to the client
  • client is now buffering compressed data and needs to wait until it gets all of it before it can decompress it
  • finally the client can decompress the data which happens much faster than the compression time

You may need to enable "Use Large Request Rows" in the Network monitoring tab to see more detailed timing. Maybe that will also help.

enter image description here

(image source)

like image 167
Ilie Pandia Avatar answered Nov 07 '22 02:11

Ilie Pandia


  1. If you provided crucial parts (or all) of your code, you would have your true matched answer.
  2. You did not mention how many trials you did. If that happens all the time, only then it is a matter to investigate.
  3. Server does seem answer client nicely and send data. Thus your client uses a code that cripples it self.
  4. If you don't use asynchronous data mode, then it is obvious what happens. But even with asynch mode, delays are due since extraction is also part of progress.
  5. Step-4 should only last a few seconds, so the culprit may not even be related to your scripts. Did you tried to use your code without compression? Always use plain methods first, then try complex ones.
  6. Have you ever think it could be JSON data extraction that takes time? 100kb gzipped json file!! That's a lot of data to progress from a json file. This could be the villain of your story I guess.
like image 32
Yılmaz Durmaz Avatar answered Nov 07 '22 01:11

Yılmaz Durmaz


We can't tell you what is happening inside your server or on the network between you and the server. We can't comment on specific issues in your code since you've not shown us any. However...

Have you measured the response profile on the server itself?

With compression disabled?

With compression and PHP's output buffering disabled?

Why are you compressing in php and not on the webserver? Or in the SSL tier?

Have you instrumented your code to identify execution progress?

Have you profiled your code?

Does your code explicitly do an ob_end_flush() immediately followed by an exit (with any cleanup handled in a registered shutdown function)?

like image 1
symcbean Avatar answered Nov 07 '22 03:11

symcbean