http.ResponseWriter and gzipResponseWrite in ServeV1Query


#1

I’d like to ask to add the support for gzipResponseWrite for on-fly gzipping the output json.
In some situations, this helps to decrease the time needed to upload the output payload (json) to a client (a database via apache, a browser via apace or a simple js in /static/ folder of the cayley).

I have notice that the latency time (time needed to deliver the response back, I have tested libcurl ) may be twice larger than the cayley query time even for small jsons (~100 elements and each of ~ 100 bytes).

Here is a few examples of an optimization of http traffic:


http://zoompf.com/blog/2012/02/lose-the-wait-http-compression
and the gzipping plays the important role.

Because I transfer quite big JSONs (about 100K elements) back, I propose to introduce GzipServeV1Query utilizing gzipResponseWrite. Example of the gzipResponseWrite can be found here
https://groups.google.com/forum/#!topic/golang-nuts/eVnTcMwNVjM
and here


if you decide to implement gzipping, you can find additional information on the choice of the compresser: gzip or zlib, below.

  1. PHP supports both
    http://php.net/manual/en/function.zlib-decode.php
  2. apache supports only zlib (deflate)
    http://httpd.apache.org/docs/2.2/mod/mod_deflate.html
  3. HTTP specification supports both
    http://stackoverflow.com/questions/1574168/deflate-compression-browser-compatibility-and-advantages-over-gzip
    but not all browsers supports both :slight_smile:
    http://www.vervestudios.co/projects/compression-tests/results
  4. https://github.com/SlyMarbo/web uses gzip
    https://github.com/SlyMarbo/web/blob/master/gzip.go
  5. here is an example of zlib in go
    http://golang.org/pkg/compress/zlib/
  6. In principal, zlib and gzip formats are compatible (except headers)
    http://stackoverflow.com/questions/1838699/how-can-i-decompress-a-gzip-stream-with-zlib

From: https://github.com/cayleygraph/cayley/issues/175