Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Request gzipped data to speed up transfers from Picasa Web #13

Merged
merged 2 commits into from
Oct 23, 2012

Conversation

viniciusteles
Copy link

Wojciech, thanks a lot for this gem!

In order to speed up the transfer of data from Picasa Web, we can request gzipped data, instead of uncompressed data.

To achieve this goal, I propose the use of the gem HTTParty to handle
all of the HTTP connections. Not only because HTTParty already knows how
to handle compressed data properly, but also because it's a mature gem
for handling HTTP connections in general. And it's use can simplify the
connection code.

I created a new class Picasa::HTTP which sets all of the defaults for
HTTParty related to:

  • base uri
  • proxy
  • headers
  • format

So this doesn't need to be done at Picasa::Connection anymore. And since
all of the requests are similar, the logic was centralized in the new
method Picasa::Connection#exec_request for http methods get, post and
delete.

OBS:

  • To request gzipped data from Picasa API it's necessary to have " (gzip)" in the user agent url and to set the appropriate Accept-Encoding header. See:
    https://developers.google.com/picasa-web/faq_gdata#gzip
  • I moved the constants API_URL, API_AUTH_URL and API_VERSION to the new
    class Picasa::HTTP, because it looks like a more appropriate place.

request gzipped data, instead of uncompressed data.

To achieve this goal, I propose the use of the gem HTTParty to handle
all of the HTTP connections. Not only because HTTParty already knows how
to handle compressed data properly, but also because it's a mature gem
for handling HTTP connections in general. And it's use can simplify the
connection code.

I created a new class Picasa::HTTP which sets all of the defaults for
HTTParty related to:

* base uri
* proxy
* headers
* format

So this doesn't need to be done at Picasa::Connection anymore. And since
all of the requests are similar, the logic was centralized in the new
method Picasa::Connection#exec_request for http methods get, post and
delete.

OBS:
* To request gzipped data from Picasa API it's necessary to have " (gzip)" in the user agent url and to set the appropriate Accept-Encoding header. See:
https://developers.google.com/picasa-web/faq_gdata#gzip
* I moved the constants API_URL, API_AUTH_URL and API_VERSION to the new
 class Picasa::HTTP, because it looks like a more appropriate place.
@morgoth
Copy link
Owner

morgoth commented Oct 23, 2012

Thanks.

I didn't know about that option in Picasa API.
I'm looking how gzipped response is handled at https://github.com/jnunemaker/httparty/blob/master/lib/httparty/request.rb#L179
Looks pretty simple.
I would like to avoid adding other gem dependencies, but I will take a look at httparty source.

@viniciusteles
Copy link
Author

Hi Wojciech,

I agree with you that dealing with gzip is simple and I understand your preference for not adding another dependency. Still, I believe the use of HTTParty can really help to simplify the code of the your gem.

Actually there are a few more simplifications that I'm working on right now and will be pushing soon for your consideration. It has to do with the parsing process, that can also be completely delegated to HTTParty.

One last thing, related to the parsing. I've run a few benchmarks and I realized that parsing a JSON response from Picasa Web is quite faster than a XML response.

When writing to Picasa Web, we can only use XML at the present moment. But JSON can be used for reading. So, I'd like to try a solution where we use JSON for all of the readings. This, together with the use of gzip, has generated speed differences in my tests of up to an order of magnitude.

Anyway, I'll be sending a few more changes during the day for your consideration.

HTTParty's response object has a method #parsed_response that returns a
hash with the response properly parsed. Internally, it uses MultiJSON or
MultiXML, depending on the format you've chosen to use in the request.

I believe that delegating this to HTTParty is interesting because the
HTTP request and it's corresponding parsing are all handled by this HTTParty, which already does it well,  and the Picasa gem
can be dedicated to dealing only with Picasa issues.
@morgoth
Copy link
Owner

morgoth commented Oct 23, 2012

Reading via JSON sounds interesting - I wanted to switch to JSON, but fact that POSTing is not supported discouraged me.
That would have another benefit - avoiding inconsistency of XML parsers, like: sferik/multi_xml#31 sferik/multi_xml#30

Looking forward to your changes - I will merge when finished.
Thanks.

@viniciusteles
Copy link
Author

Nice. Good to know that you're also interested in using JSON.

I'm working on it and hopefully will be pushing it soon.

@morgoth
Copy link
Owner

morgoth commented Oct 23, 2012

Switching to JSON can be a lot of work - we can do it in second step if you like.

@viniciusteles
Copy link
Author

Yeah, I agree with you. Actually I do have a code of my own that already deals with JSON for Picasa Web. But changing the gem to use JSON really seems to take some work, because the parsed response has some important differences. In particular, where the XML parser generates something like "title"=>"My nice pictures", the JSON parsed response generates "title"=>{"$t"=>"My nice pictures"}.

I believe it's better to tackle this in a different branch and to just leave the current one as it is. If you decide to merge it, I'd only ask you to please review carefully the changes. They didn't break the tests, but I'm not sure how comprehensive the tests are at this point. You certainly have far more experience with the code to evaluate it.

@morgoth morgoth merged commit c1ead80 into morgoth:master Oct 23, 2012
@morgoth
Copy link
Owner

morgoth commented Oct 23, 2012

I noticed some problems with parsing xml.
Very subtle issue - title attribute of private album list, parses as {"__content__"=>"some-title", "type"=>"text"} after this change.
Need to investigate it little more or switch to JSON as we discussed, so I'm not releasing new gem yet.

@viniciusteles
Copy link
Author

Sorry about that. :-/

I'll take a look as well and let you know if I find something.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants