Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
LDIF 14.24 KB | None | 0 0
  1. diff --git a/iocore/cluster/ClusterHandlerBase.cc b/iocore/cluster/ClusterHandlerBase.cc
  2. index 41da0a59e..6202a41d6 100644
  3. --- a/iocore/cluster/ClusterHandlerBase.cc
  4. +++ b/iocore/cluster/ClusterHandlerBase.cc
  5. @@ -1018,6 +1018,7 @@ ClusterHandler::startClusterEvent(int event, Event *e)
  6.        if (lock.is_locked() && lock1.is_locked()) {
  7.          vc->ep.stop();
  8.          vc->nh->open_list.remove(vc);
  9. +        vc->nh->cop_list.remove(vc);
  10.          vc->thread = nullptr;
  11.          if (vc->nh->read_ready_list.in(vc))
  12.            vc->nh->read_ready_list.remove(vc);
  13. diff --git a/iocore/net/P_UnixNet.h b/iocore/net/P_UnixNet.h
  14. index 4637f004b..f514ce846 100644
  15. --- a/iocore/net/P_UnixNet.h
  16. +++ b/iocore/net/P_UnixNet.h
  17. @@ -195,6 +195,7 @@ public:
  18.    uint32_t inactive_threashold_in;
  19.    uint32_t transaction_no_activity_timeout_in;
  20.    uint32_t keep_alive_no_activity_timeout_in;
  21. +  uint32_t default_inactivity_timeout;
  22.  
  23.    int startNetEvent(int event, Event *data);
  24.    int mainNetEvent(int event, Event *data);
  25. @@ -406,7 +407,7 @@ read_disable(NetHandler *nh, UnixNetVConnection *vc)
  26.    }
  27.  #else
  28.    if (!vc->write.enabled) {
  29. -    vc->next_inactivity_timeout_at = 0;
  30. +    vc->set_inactivity_timeout(0);
  31.      Debug("socket", "read_disable updating inactivity_at %" PRId64 ", NetVC=%p", vc->next_inactivity_timeout_at, vc);
  32.    }
  33.  #endif
  34. @@ -427,7 +428,7 @@ write_disable(NetHandler *nh, UnixNetVConnection *vc)
  35.    }
  36.  #else
  37.    if (!vc->read.enabled) {
  38. -    vc->next_inactivity_timeout_at = 0;
  39. +    vc->set_inactivity_timeout(0);
  40.      Debug("socket", "write_disable updating inactivity_at %" PRId64 ", NetVC=%p", vc->next_inactivity_timeout_at, vc);
  41.    }
  42.  #endif
  43. diff --git a/iocore/net/P_UnixNetVConnection.h b/iocore/net/P_UnixNetVConnection.h
  44. index 9a238e020..e5b5d25da 100644
  45. --- a/iocore/net/P_UnixNetVConnection.h
  46. +++ b/iocore/net/P_UnixNetVConnection.h
  47. @@ -370,41 +370,6 @@ UnixNetVConnection::get_inactivity_timeout()
  48.  }
  49.  
  50.  TS_INLINE void
  51. -UnixNetVConnection::set_inactivity_timeout(ink_hrtime timeout_in)
  52. -{
  53. -  Debug("socket", "Set inactive timeout=%" PRId64 ", for NetVC=%p", timeout_in, this);
  54. -  inactivity_timeout_in = timeout_in;
  55. -#ifdef INACTIVITY_TIMEOUT
  56. -
  57. -  if (inactivity_timeout)
  58. -    inactivity_timeout->cancel_action(this);
  59. -  if (inactivity_timeout_in) {
  60. -    if (read.enabled) {
  61. -      ink_assert(read.vio.mutex->thread_holding == this_ethread() && thread);
  62. -      if (read.vio.mutex->thread_holding == thread)
  63. -        inactivity_timeout = thread->schedule_in_local(this, inactivity_timeout_in);
  64. -      else
  65. -        inactivity_timeout = thread->schedule_in(this, inactivity_timeout_in);
  66. -    } else if (write.enabled) {
  67. -      ink_assert(write.vio.mutex->thread_holding == this_ethread() && thread);
  68. -      if (write.vio.mutex->thread_holding == thread)
  69. -        inactivity_timeout = thread->schedule_in_local(this, inactivity_timeout_in);
  70. -      else
  71. -        inactivity_timeout = thread->schedule_in(this, inactivity_timeout_in);
  72. -    } else
  73. -      inactivity_timeout = 0;
  74. -  } else
  75. -    inactivity_timeout = 0;
  76. -#else
  77. -  if (timeout_in) {
  78. -    next_inactivity_timeout_at = Thread::get_hrtime() + timeout_in;
  79. -  } else {
  80. -    next_inactivity_timeout_at = 0;
  81. -  }
  82. -#endif
  83. -}
  84. -
  85. -TS_INLINE void
  86.  UnixNetVConnection::set_active_timeout(ink_hrtime timeout_in)
  87.  {
  88.    Debug("socket", "Set active timeout=%" PRId64 ", NetVC=%p", timeout_in, this);
  89. @@ -430,7 +395,7 @@ UnixNetVConnection::set_active_timeout(ink_hrtime timeout_in)
  90.    } else
  91.      active_timeout = 0;
  92.  #else
  93. -  next_activity_timeout_at   = Thread::get_hrtime() + timeout_in;
  94. +  next_activity_timeout_at = Thread::get_hrtime() + timeout_in;
  95.  #endif
  96.  }
  97.  
  98. @@ -446,7 +411,7 @@ UnixNetVConnection::cancel_inactivity_timeout()
  99.      inactivity_timeout = nullptr;
  100.    }
  101.  #else
  102. -  next_inactivity_timeout_at = 0;
  103. +  set_inactivity_timeout(0);
  104.  #endif
  105.  }
  106.  
  107. @@ -462,7 +427,7 @@ UnixNetVConnection::cancel_active_timeout()
  108.      active_timeout = nullptr;
  109.    }
  110.  #else
  111. -  next_activity_timeout_at   = 0;
  112. +  next_activity_timeout_at = 0;
  113.  #endif
  114.  }
  115.  
  116. diff --git a/iocore/net/UnixNet.cc b/iocore/net/UnixNet.cc
  117. index d13badc9d..46d8f7530 100644
  118. --- a/iocore/net/UnixNet.cc
  119. +++ b/iocore/net/UnixNet.cc
  120. @@ -38,20 +38,10 @@ extern "C" void fd_reify(struct ev_loop *);
  121.  // INKqa10496
  122.  // One Inactivity cop runs on each thread once every second and
  123.  // loops through the list of NetVCs and calls the timeouts
  124. -int update_cop_config(const char *name, RecDataT data_type, RecData data, void *cookie);
  125. -
  126.  class InactivityCop : public Continuation
  127.  {
  128.  public:
  129. -  explicit InactivityCop(Ptr<ProxyMutex> &m) : Continuation(m.get()), default_inactivity_timeout(0)
  130. -  {
  131. -    SET_HANDLER(&InactivityCop::check_inactivity);
  132. -    REC_ReadConfigInteger(default_inactivity_timeout, "proxy.config.net.default_inactivity_timeout");
  133. -    Debug("inactivity_cop", "default inactivity timeout is set to: %d", default_inactivity_timeout);
  134. -
  135. -    RecRegisterConfigUpdateCb("proxy.config.net.default_inactivity_timeout", update_cop_config, (void *)this);
  136. -  }
  137. -
  138. +  explicit InactivityCop(Ptr<ProxyMutex> &m) : Continuation(m.get()) { SET_HANDLER(&InactivityCop::check_inactivity); }
  139.    int
  140.    check_inactivity(int event, Event *e)
  141.    {
  142. @@ -60,13 +50,8 @@ public:
  143.      NetHandler &nh = *get_NetHandler(this_ethread());
  144.  
  145.      Debug("inactivity_cop_check", "Checking inactivity on Thread-ID #%d", this_ethread()->id);
  146. -    // Copy the list and use pop() to catch any closes caused by callbacks.
  147. -    forl_LL(UnixNetVConnection, vc, nh.open_list)
  148. -    {
  149. -      if (vc->thread == this_ethread()) {
  150. -        nh.cop_list.push(vc);
  151. -      }
  152. -    }
  153. +    // The rest NetVCs in cop_list which are not triggered between InactivityCop runs.
  154. +    // Use pop() to catch any closes caused by callbacks.
  155.      while (UnixNetVConnection *vc = nh.cop_list.pop()) {
  156.        // If we cannot get the lock don't stop just keep cleaning
  157.        MUTEX_TRY_LOCK(lock, vc->mutex, this_ethread());
  158. @@ -80,17 +65,6 @@ public:
  159.          continue;
  160.        }
  161.  
  162. -      // set a default inactivity timeout if one is not set
  163. -      if (vc->next_inactivity_timeout_at == 0 && default_inactivity_timeout > 0) {
  164. -        Debug("inactivity_cop", "vc: %p inactivity timeout not set, setting a default of %d", vc, default_inactivity_timeout);
  165. -        vc->set_inactivity_timeout(HRTIME_SECONDS(default_inactivity_timeout));
  166. -        NET_INCREMENT_DYN_STAT(default_inactivity_timeout_stat);
  167. -      } else {
  168. -        Debug("inactivity_cop_verbose", "vc: %p now: %" PRId64 " timeout at: %" PRId64 " timeout in: %" PRId64, vc,
  169. -              ink_hrtime_to_sec(now), ink_hrtime_to_sec(vc->next_inactivity_timeout_at),
  170. -              ink_hrtime_to_sec(vc->inactivity_timeout_in));
  171. -      }
  172. -
  173.        if (vc->next_inactivity_timeout_at && vc->next_inactivity_timeout_at < now) {
  174.          if (nh.keep_alive_queue.in(vc)) {
  175.            // only stat if the connection is in keep-alive, there can be other inactivity timeouts
  176. @@ -103,6 +77,18 @@ public:
  177.          vc->handleEvent(EVENT_IMMEDIATE, e);
  178.        }
  179.      }
  180. +    // The cop_list is empty now.
  181. +    // Let's reload the cop_list from open_list again.
  182. +    forl_LL(UnixNetVConnection, vc, nh.open_list)
  183. +    {
  184. +      if (vc->thread == this_ethread()) {
  185. +        nh.cop_list.push(vc);
  186. +      }
  187. +    }
  188. +    // NetHandler will remove NetVC from cop_list if it is triggered.
  189. +    // As the NetHandler runs, the number of NetVCs in the cop_list is decreasing.
  190. +    // NetHandler runs 100 times maximum between InactivityCop runs.
  191. +    // Therefore we don't have to check all the NetVCs as much as open_list.
  192.  
  193.      // Cleanup the active and keep-alive queues periodically
  194.      nh.manage_active_queue(true); // close any connections over the active timeout
  195. @@ -110,33 +96,8 @@ public:
  196.  
  197.      return 0;
  198.    }
  199. -
  200. -  void
  201. -  set_default_timeout(const int x)
  202. -  {
  203. -    default_inactivity_timeout = x;
  204. -  }
  205. -
  206. -private:
  207. -  int default_inactivity_timeout; // only used when one is not set for some bad reason
  208.  };
  209.  
  210. -int
  211. -update_cop_config(const char *name, RecDataT data_type ATS_UNUSED, RecData data, void *cookie)
  212. -{
  213. -  InactivityCop *cop = static_cast<InactivityCop *>(cookie);
  214. -  ink_assert(cop != NULL);
  215. -
  216. -  if (cop != NULL) {
  217. -    if (strcmp(name, "proxy.config.net.default_inactivity_timeout") == 0) {
  218. -      Debug("inactivity_cop_dynamic", "proxy.config.net.default_inactivity_timeout updated to %" PRId64, data.rec_int);
  219. -      cop->set_default_timeout(data.rec_int);
  220. -    }
  221. -  }
  222. -
  223. -  return REC_ERR_OKAY;
  224. -}
  225. -
  226.  #endif
  227.  
  228.  PollCont::PollCont(Ptr<ProxyMutex> &m, int pt)
  229. @@ -336,6 +297,10 @@ update_nethandler_config(const char *name, RecDataT data_type ATS_UNUSED, RecDat
  230.        Debug("net_queue", "proxy.config.net.keep_alive_no_activity_timeout_in updated to %" PRId64, data.rec_int);
  231.        nh->keep_alive_no_activity_timeout_in = data.rec_int;
  232.      }
  233. +    if (strcmp(name, "proxy.config.net.default_inactivity_timeout") == 0) {
  234. +      Debug("net_queue", "proxy.config.net.default_inactivity_timeout updated to %" PRId64, data.rec_int);
  235. +      nh->default_inactivity_timeout = data.rec_int;
  236. +    }
  237.    }
  238.  
  239.    if (update_per_thread_configuration == true) {
  240. @@ -358,18 +323,21 @@ NetHandler::startNetEvent(int event, Event *e)
  241.    REC_ReadConfigInt32(inactive_threashold_in, "proxy.config.net.inactive_threashold_in");
  242.    REC_ReadConfigInt32(transaction_no_activity_timeout_in, "proxy.config.net.transaction_no_activity_timeout_in");
  243.    REC_ReadConfigInt32(keep_alive_no_activity_timeout_in, "proxy.config.net.keep_alive_no_activity_timeout_in");
  244. +  REC_ReadConfigInt32(default_inactivity_timeout, "proxy.config.net.default_inactivity_timeout");
  245.  
  246.    RecRegisterConfigUpdateCb("proxy.config.net.max_connections_in", update_nethandler_config, (void *)this);
  247.    RecRegisterConfigUpdateCb("proxy.config.net.max_active_connections_in", update_nethandler_config, (void *)this);
  248.    RecRegisterConfigUpdateCb("proxy.config.net.inactive_threashold_in", update_nethandler_config, (void *)this);
  249.    RecRegisterConfigUpdateCb("proxy.config.net.transaction_no_activity_timeout_in", update_nethandler_config, (void *)this);
  250.    RecRegisterConfigUpdateCb("proxy.config.net.keep_alive_no_activity_timeout_in", update_nethandler_config, (void *)this);
  251. +  RecRegisterConfigUpdateCb("proxy.config.net.default_inactivity_timeout", update_nethandler_config, (void *)this);
  252.  
  253.    Debug("net_queue", "proxy.config.net.max_connections_in updated to %d", max_connections_in);
  254.    Debug("net_queue", "proxy.config.net.max_active_connections_in updated to %d", max_connections_active_in);
  255.    Debug("net_queue", "proxy.config.net.inactive_threashold_in updated to %d", inactive_threashold_in);
  256.    Debug("net_queue", "proxy.config.net.transaction_no_activity_timeout_in updated to %d", transaction_no_activity_timeout_in);
  257.    Debug("net_queue", "proxy.config.net.keep_alive_no_activity_timeout_in updated to %d", keep_alive_no_activity_timeout_in);
  258. +  Debug("net_queue", "proxy.config.net.default_inactivity_timeout updated to %d", default_inactivity_timeout);
  259.  
  260.    configure_per_thread();
  261.  
  262. @@ -477,6 +445,10 @@ NetHandler::mainNetEvent(int event, Event *e)
  263.      epd = (EventIO *)get_ev_data(pd, x);
  264.      if (epd->type == EVENTIO_READWRITE_VC) {
  265.        vc = epd->data.vc;
  266. +      // Remove triggered NetVC from cop_list because it won't be timeout before next InactivityCop runs.
  267. +      if (cop_list.in(vc)) {
  268. +        cop_list.remove(vc);
  269. +      }
  270.        if (get_ev_events(pd, x) & EVENTIO_READ) {
  271.          vc->read.triggered = 1;
  272.          if (get_ev_events(pd, x) & EVENTIO_ERROR) {
  273. diff --git a/iocore/net/UnixNetAccept.cc b/iocore/net/UnixNetAccept.cc
  274. index a3094fb0d..d30ebe55e 100644
  275. --- a/iocore/net/UnixNetAccept.cc
  276. +++ b/iocore/net/UnixNetAccept.cc
  277. @@ -428,6 +428,7 @@ NetAccept::acceptFastEvent(int event, void *ep)
  278.      }
  279.  
  280.      ink_assert(vc->nh->mutex->thread_holding == this_ethread());
  281. +    vc->set_inactivity_timeout(0);
  282.      vc->nh->open_list.enqueue(vc);
  283.  
  284.  #ifdef USE_EDGE_TRIGGER
  285. diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc
  286. index ae9f10c7e..79cc75680 100644
  287. --- a/iocore/net/UnixNetVConnection.cc
  288. +++ b/iocore/net/UnixNetVConnection.cc
  289. @@ -1205,6 +1205,7 @@ UnixNetVConnection::acceptEvent(int event, Event *e)
  290.      return EVENT_DONE;
  291.    }
  292.  
  293. +  set_inactivity_timeout(0);
  294.    nh->open_list.enqueue(this);
  295.  
  296.  #ifdef USE_EDGE_TRIGGER
  297. @@ -1419,9 +1420,9 @@ UnixNetVConnection::connectUp(EThread *t, int fd)
  298.    SET_HANDLER(&UnixNetVConnection::mainEvent);
  299.  
  300.    nh = get_NetHandler(t);
  301. +  set_inactivity_timeout(0);
  302.    nh->open_list.enqueue(this);
  303.  
  304. -  ink_assert(!inactivity_timeout_in);
  305.    ink_assert(!active_timeout_in);
  306.    this->set_local_addr();
  307.    action_.continuation->handleEvent(NET_EVENT_OPEN, this);
  308. @@ -1484,6 +1485,41 @@ UnixNetVConnection::apply_options()
  309.    con.apply_options(options);
  310.  }
  311.  
  312. +TS_INLINE void
  313. +UnixNetVConnection::set_inactivity_timeout(ink_hrtime timeout_in)
  314. +{
  315. +  Debug("socket", "Set inactive timeout=%" PRId64 ", for NetVC=%p", timeout_in, this);
  316. +#ifdef INACTIVITY_TIMEOUT
  317. +  if (inactivity_timeout)
  318. +    inactivity_timeout->cancel_action(this);
  319. +  if (timeout_in) {
  320. +    inactivity_timeout_in = timeout_in;
  321. +    if (read.enabled) {
  322. +      ink_assert(read.vio.mutex->thread_holding == this_ethread() && thread);
  323. +      if (read.vio.mutex->thread_holding == thread)
  324. +        inactivity_timeout = thread->schedule_in_local(this, inactivity_timeout_in);
  325. +      else
  326. +        inactivity_timeout = thread->schedule_in(this, inactivity_timeout_in);
  327. +    } else if (write.enabled) {
  328. +      ink_assert(write.vio.mutex->thread_holding == this_ethread() && thread);
  329. +      if (write.vio.mutex->thread_holding == thread)
  330. +        inactivity_timeout = thread->schedule_in_local(this, inactivity_timeout_in);
  331. +      else
  332. +        inactivity_timeout = thread->schedule_in(this, inactivity_timeout_in);
  333. +    } else
  334. +      inactivity_timeout = 0;
  335. +  } else
  336. +    inactivity_timeout = 0;
  337. +#else
  338. +  if (timeout_in == 0) {
  339. +    // set default inactivity timeout
  340. +    timeout_in = HRTIME_SECONDS(nh->default_inactivity_timeout);
  341. +  }
  342. +  inactivity_timeout_in      = timeout_in;
  343. +  next_inactivity_timeout_at = Thread::get_hrtime() + inactivity_timeout_in;
  344. +#endif
  345. +}
  346. +
  347.  /*
  348.   * Close down the current netVC.  Save aside the socket and SSL information
  349.   * and create new netVC in the current thread/netVC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement