Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpResponseCache slow down UrlConnection #7

Closed
andi78 opened this issue Apr 30, 2012 · 6 comments
Closed

HttpResponseCache slow down UrlConnection #7

andi78 opened this issue Apr 30, 2012 · 6 comments

Comments

@andi78
Copy link

andi78 commented Apr 30, 2012

in simulator with "slow" file system access and mobile devices with bad file system performance:
A simple http get download is slower when HttpResponseCache is enabled.

URLConnection con = url.openConnection();
...
InputStream is = (InputStream) con.getContent();

i suppose HttpResponseCache store it on filesystem before the app is allowed to access the inputstream.

in my opinion this library should only be used if you expect high cache hit ratio.

Our service used "Etag" and "If Modified Since" headers. (for instance for images with size of about 15kb)
With enabled HttpResponseCache it was noticeable slower (with 304-not modified header) than regular urlConnection without caching at all.

@candrews
Copy link
Owner

Your testing is very different from what would be experienced in the real world.

In the real world:

  • storage read/write access may be slow (compared to "normal" computing standards), but it's still faster than the emulator.
  • Mobile devices have unreliable network access. So if you can cache something locally, you don't need to use the network at all - so the user won't see an error if the network is down - the app continues to work.
  • Mobile network access is slow - I bet that the incredibly slow mobile network is slower than the storage, so caching wins.
  • Mobile network access is metered - so using less bandwidth means the user doesn't hit their limit as fast, making them happier users of your app.

With that said, I'd be really psyched if you looked through the code and took a look at ways to make it faster. Even if you just submit ideas, that would be pretty great - a patch / merge request would be even better.

@jaypatrickhoward
Copy link

I just integrated the cache into my app, which serially pulls down about 20 images at launch (while showing a splash screen) before allowing the user to do anything and stores them in an in-memory cache. I then tested performance on a Samsung Galaxy Nexus using both the built-in ICS HttpResponseCache and your port. The performance was roughly the same between the two; if anything your port performed a little better. But that's the good news. The bad news:

  • Time to load with no HttpResponseCache installed: ~7 sec
  • Time to load with HttpResponseCache installed and populated: ~1 sec
  • Time to load with HttpResponseCache installed but empty: ~33 sec

Is this huge disparity between "empty cache" and "no cache at all" merely caused by the general slowness of writing to internal storage? Or is something else going on?

It is not, at least, an issue with your port per se since the ICS-provided HttpResponseCache also exhibits the poor behavior. Maybe what's needed is some delayed write functionality so the caller doesn't have to wait for the requested data to be fully cached before it's made available to him?

@iNoles
Copy link

iNoles commented Jul 13, 2012

If you turn on StrictMode, you will see violation for HttpResponseCache installed. It will be very wise to put HttpResponseCache installed under AsyncTask.

@jaypatrickhoward
Copy link

I started my timing at the point when I began loading the images, not when I installed the cache.

Is the install process maybe "lazy", i.e. it only does the work when you first use a HttpURLConnection that has caching turned on?

@jaypatrickhoward
Copy link

Applying the patch in issue #9 solved the performance issues I described above. What it implies, however, that app developers should prefer to use candrews's HttpResponseCache even on ICS since the stock version that ships with ICS doesn't have the patch to fix the unreasonably slow performance when writing to cache.

@candrews
Copy link
Owner

candrews commented Aug 4, 2012

I added a note to the README.md that this library may be a later version that one included in Android on the target, so developer may want to use it unconditionally. See 59e8ed9

@candrews candrews closed this as completed Aug 4, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants