Exponential backoff algorithm exponential back-off algorithm

Source: Internet
Author: User

In many scenarios, we need to solve some problems such as rotation. If such an algorithm appears on the app, this rotation is a huge disaster for app performance and power consumption, so how do you solve this problem?

The app uses the exponential backoff algorithm exponential back-off algorithm to reduce the frequency of updates in the event that it has not been used since the last update operation. Here we introduce the exponential backoff algorithm.


Sharedpreferences sp = context.getsharedpreferences (PREFS, context.mode_world_readable);

Boolean appused = Sp.getboolean (prefs_appused, false); long updateinterval = Sp.getlong (Prefs_interval, Default_refresh _interval), if (!appused)  if ((updateinterval *= 2) > Max_refresh_interval)    updateinterval = Max_refresh_ INTERVAL; Editor SpeDIt = Sp.edit (); Spedit.putboolean (prefs_appused, false); Spedit.putlong (Prefs_interval, updateinterval); Spedit.apply (); rescheduleupdates (updateinterval); Executeupdateorprefetch ();

The cost of initializing a network connection does not change if the data has been successfully downloaded. We can use the exponential backoff algorithm to reduce the number of repeated attempts (retry) to avoid wasting power. For example:


private void Retryin (long interval) {  Boolean success = Attempttransfer ();  if (!success) {    Retryin (interval*2 < max_retry_interval?            ) Interval*2:max_retry_interval);}  }


Exponential backoff algorithm exponential back-off algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.