Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

startSampling stopSampling for every network request? #28

Open
ralph-bergmann opened this issue Jan 26, 2017 · 3 comments
Open

startSampling stopSampling for every network request? #28

ralph-bergmann opened this issue Jan 26, 2017 · 3 comments

Comments

@ralph-bergmann
Copy link

ralph-bergmann commented Jan 26, 2017

Currently I develop a movie app which loads a lot of cover images. Especially in the overview where I show the cover images in a grid and the app has to load lots of images in parallel.

Should I start / stop sampling for every image request or can I start sampling with app start and stop it when the app goes to background?

Currently I have a NetworkInterceptor for OkHttp to do start / stop but I'm not sure if it is a good idea :-(

private static class DeviceBandwidthSamplerInterceptor implements Interceptor {

    private final DeviceBandwidthSampler deviceBandwidthSampler;

    DeviceBandwidthSamplerInterceptor(final DeviceBandwidthSampler deviceBandwidthSampler) {
        this.deviceBandwidthSampler = deviceBandwidthSampler;
    }

    @Override
    public Response intercept(final Chain chain) throws IOException {
        deviceBandwidthSampler.startSampling();
        final Response response = chain.proceed(chain.request());
        deviceBandwidthSampler.stopSampling();
        return response;
    }
}
@shobhitpuri
Copy link

@the4thfloor What did you end up doing? What turned out to be optimal? Thanks in advance for taking time to answer.

@ralph-bergmann
Copy link
Author

@shobhitpuri currently I use this NetworkInterceptor for OkHttp

@sid6mathur
Copy link

Hi @the4thfloor , @shobhitpuri : You should start sampling when it comes to foreground, and stop it when it goes into background. The larger the HTTP transfers that occur between the start() and stop(), the better the odds that you don't have an "UNKNOWN" estimate.

In case your app requires quick sampling to tune video quality defaults or image loading strategies, you can also try the library that I have built : https://getfastah.com/docs/api . Since it uses its own geographically distributed ping-server network, it does a much better job estimating WiFi or 4G congestion accurately (and very fast). It's a paid API, in private beta at the moment.

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

No branches or pull requests

3 participants