GZIP Compression

21 views
Skip to first unread message

Dustin Whitney

unread,
Feb 6, 2009, 4:41:01 PM2/6/09
to Sublime SimpleDB
FYI, results from a simple db query can come back gzip compressed.

import org.apache.commons.httpclient._
import org.apache.commons.httpclient.methods._
import org.apache.commons.httpclient.params._
import java.io._
import java.util.zip.GZIPInputStream

val get = new GetMethod(uri)
get.addRequestHeader("Accept-Encoding", "gzip")
val code = client executeMethod get
val stream = new GZIPInputStream(get.getResponseBodyAsStream)
val data = new StringBuffer
val buffer = new BufferedReader(new InputStreamReader(stream))

var line = "ignore"
while(line != null){
line = buffer.readLine()
if(line != null) data.append(line)
}
stream.close
response = data.toString

Robin Barooah

unread,
Feb 6, 2009, 7:59:57 PM2/6/09
to sublime-...@googlegroups.com
Interesting. Do you have any idea at what size of result that becomes
worth doing?



On Feb 6, 2009, at 1:41 PM, Dustin Whitney <dustin....@gmail.com>
wrote:

Dustin Whitney

unread,
Feb 7, 2009, 12:24:39 PM2/7/09
to Sublime SimpleDB
There is a lot of redundancy in any result set. I'd think gzipping the
following XML would result in at least a 40% reduction in size :

<SelectResponse>
<SelectResult>
<Item>
<Name>robin</Name>
<Attribute>
<Name>role</Name>
<Value>author</Value>
</Attribute>
</Item>
<Item>
<Name>dustin</Name>
<Attribute>
<Name>role</Name>
<Value>editor</Value>
</Attribute>
</Item>
<SelectResult>
<SelectResponse>

On Feb 6, 7:59 pm, Robin Barooah <robi...@gmail.com> wrote:
> Interesting.  Do you have any idea at what size of result that becomes  
> worth doing?
>
> On Feb 6, 2009, at 1:41 PM, Dustin Whitney <dustin.whit...@gmail.com>  

Robin

unread,
Feb 7, 2009, 4:37:46 PM2/7/09
to sublime-...@googlegroups.com
So it's probably worth doing almost all of the time if you're not running on EC2.
--
-Robin

Robin Barooah
http://www.sublime.org
Reply all
Reply to author
Forward
0 new messages