turtleboy
turtleboy

Reputation: 7572

GZIP has no effect on web call

I've an app that call a webservice. I've logged the time it takes to complete this call with and without GZIP. I ran the app 5 times with and 5 time without GZIP and it actually took longer with GZIP. So i can only think GZIP had no effect or i have implemented it badly. Any ideas why there is no change?

public String connect(String url) {



        HttpClient httpclient = new DefaultHttpClient();

        // Prepare a request object
        HttpGet httpget = new HttpGet(url);
        httpget.addHeader("Accept-Encoding", "gzip");

        // Execute the request
        HttpResponse response;
        try {
            long start = System.currentTimeMillis();
            response = httpclient.execute(httpget);
            // Examine the response status
            Log.i(TAG, response.getStatusLine().toString());






            // Get hold of the response entity
            HttpEntity entity = response.getEntity();
            // If the response does not enclose an entity, there is no need
            // to worry about connection release

            if (entity != null) {

                InputStream instream = response.getEntity().getContent();
                Header contentEncoding = response.getFirstHeader("Content-Encoding");
                if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
                    instream = new GZIPInputStream(instream);
                }

                // A Simple JSON Response Read
                //InputStream instream = entity.getContent();
                result = convertStreamToString(instream);
                Log.i(TAG, result);

                // A Simple JSONObject Creation
                //json = new JSONObject(result);



                // Closing the input stream will trigger connection release
                instream.close();
                long end = System.currentTimeMillis();
                long elapsed = (end - start);
                Log.e(TAG, "web call took ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" + elapsed);

            }

                } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
         return result;

    }

.

RESULTS:

Without GZIP: average of 5 runs = 2923ms

With GZIP: average of 5 runs = 3179ms

Upvotes: 0

Views: 144

Answers (1)

Aki Suihkonen
Aki Suihkonen

Reputation: 20027

There are at least two major contributions in the timing:

  • client side: connection speed vs. decoding speed
  • server side: connection speed vs. encoding speed

The gzip encoding can be static or dynamic on the server side. For some content it would make sense to store query data in already compressed form. For some content it can't be done and the server may have the "compression engine" occupied.

The timings are likely to change between ADSL, WLAN or direct ethernet connections.

Upvotes: 1

Related Questions