libceph: monc hunt rate is 3s with backoff up to 30s
authorIlya Dryomov <idryomov@gmail.com>
Thu, 21 Jan 2016 15:33:19 +0000 (16:33 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Fri, 25 Mar 2016 17:51:39 +0000 (18:51 +0100)
Unless we are in the process of setting up a client (i.e. connecting to
the monitor cluster for the first time), apply a backoff: every time we
want to reopen a session, increase our timeout by a multiple (currently
2); when we complete the connection, reduce that multipler by 50%.

Mirrors ceph.git commit 794c86fd289bd62a35ed14368fa096c46736e9a2.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
include/linux/ceph/libceph.h
include/linux/ceph/mon_client.h
net/ceph/mon_client.c

index f5466273b9a3df68535f6aee4b71e402c7dc2ed2..e7975e4681e1a9110ee26506eaf4402ffcbad082 100644 (file)
@@ -68,8 +68,11 @@ struct ceph_options {
 #define CEPH_OSD_KEEPALIVE_DEFAULT     msecs_to_jiffies(5 * 1000)
 #define CEPH_OSD_IDLE_TTL_DEFAULT      msecs_to_jiffies(60 * 1000)
 
+#define CEPH_MONC_HUNT_INTERVAL                msecs_to_jiffies(3 * 1000)
 #define CEPH_MONC_PING_INTERVAL                msecs_to_jiffies(10 * 1000)
 #define CEPH_MONC_PING_TIMEOUT         msecs_to_jiffies(30 * 1000)
+#define CEPH_MONC_HUNT_BACKOFF         2
+#define CEPH_MONC_HUNT_MAX_MULT                10
 
 #define CEPH_MSG_MAX_FRONT_LEN (16*1024*1024)
 #define CEPH_MSG_MAX_MIDDLE_LEN        (16*1024*1024)
index 8b2d2f0b659e6064a2d03f915c9f4a949a122a7a..e230e7ed60d369f202020e6c955f50c644b89dfa 100644 (file)
@@ -72,6 +72,9 @@ struct ceph_mon_client {
        unsigned long sub_renew_sent;
        struct ceph_connection con;
 
+       bool had_a_connection;
+       int hunt_mult; /* [1..CEPH_MONC_HUNT_MAX_MULT] */
+
        /* pending generic requests */
        struct rb_root generic_request_tree;
        int num_generic_requests;
index 23a270c49baf25798251eb12f9fdc365e4012e07..fd1cf408fd899ab790d2bcea4a1514190f513a9e 100644 (file)
@@ -171,6 +171,12 @@ static void __open_session(struct ceph_mon_client *monc)
 
        pick_new_mon(monc);
 
+       if (monc->had_a_connection) {
+               monc->hunt_mult *= CEPH_MONC_HUNT_BACKOFF;
+               if (monc->hunt_mult > CEPH_MONC_HUNT_MAX_MULT)
+                       monc->hunt_mult = CEPH_MONC_HUNT_MAX_MULT;
+       }
+
        monc->sub_renew_after = jiffies; /* i.e., expired */
        monc->sub_renew_sent = 0;
 
@@ -192,11 +198,6 @@ static void __open_session(struct ceph_mon_client *monc)
        __send_prepared_auth_request(monc, ret);
 }
 
-static bool __sub_expired(struct ceph_mon_client *monc)
-{
-       return time_after_eq(jiffies, monc->sub_renew_after);
-}
-
 /*
  * Reschedule delayed work timer.
  */
@@ -204,11 +205,11 @@ static void __schedule_delayed(struct ceph_mon_client *monc)
 {
        unsigned long delay;
 
-       if (monc->cur_mon < 0 || __sub_expired(monc)) {
-               delay = 10 * HZ;
-       } else {
+       if (monc->hunting)
+               delay = CEPH_MONC_HUNT_INTERVAL * monc->hunt_mult;
+       else
                delay = CEPH_MONC_PING_INTERVAL;
-       }
+
        dout("__schedule_delayed after %lu\n", delay);
        schedule_delayed_work(&monc->delayed_work,
                              round_jiffies_relative(delay));
@@ -902,6 +903,8 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
        monc->hunting = true;
        monc->sub_renew_after = jiffies;
        monc->sub_renew_sent = 0;
+       monc->had_a_connection = false;
+       monc->hunt_mult = 1;
 
        INIT_DELAYED_WORK(&monc->delayed_work, delayed_work);
        monc->generic_request_tree = RB_ROOT;
@@ -959,6 +962,10 @@ static void finish_hunting(struct ceph_mon_client *monc)
        if (monc->hunting) {
                dout("%s found mon%d\n", __func__, monc->cur_mon);
                monc->hunting = false;
+               monc->had_a_connection = true;
+               monc->hunt_mult /= 2; /* reduce by 50% */
+               if (monc->hunt_mult < 1)
+                       monc->hunt_mult = 1;
        }
 }