Advertisement
Guest User

Untitled

a guest
Apr 12th, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
LDIF 14.58 KB | None | 0 0
  1. diff --git a/iocore/cluster/ClusterHandlerBase.cc b/iocore/cluster/ClusterHandlerBase.cc
  2. index 6202a41d6..41da0a59e 100644
  3. --- a/iocore/cluster/ClusterHandlerBase.cc
  4. +++ b/iocore/cluster/ClusterHandlerBase.cc
  5. @@ -1018,7 +1018,6 @@ 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 f514ce846..4637f004b 100644
  15. --- a/iocore/net/P_UnixNet.h
  16. +++ b/iocore/net/P_UnixNet.h
  17. @@ -195,7 +195,6 @@ 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. @@ -407,7 +406,7 @@ read_disable(NetHandler *nh, UnixNetVConnection *vc)
  26.    }
  27.  #else
  28.    if (!vc->write.enabled) {
  29. -    vc->set_inactivity_timeout(0);
  30. +    vc->next_inactivity_timeout_at = 0;
  31.      Debug("socket", "read_disable updating inactivity_at %" PRId64 ", NetVC=%p", vc->next_inactivity_timeout_at, vc);
  32.    }
  33.  #endif
  34. @@ -428,7 +427,7 @@ write_disable(NetHandler *nh, UnixNetVConnection *vc)
  35.    }
  36.  #else
  37.    if (!vc->read.enabled) {
  38. -    vc->set_inactivity_timeout(0);
  39. +    vc->next_inactivity_timeout_at = 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 e5b5d25da..9a238e020 100644
  45. --- a/iocore/net/P_UnixNetVConnection.h
  46. +++ b/iocore/net/P_UnixNetVConnection.h
  47. @@ -370,6 +370,41 @@ 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. @@ -395,7 +430,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. @@ -411,7 +446,7 @@ UnixNetVConnection::cancel_inactivity_timeout()
  99.      inactivity_timeout = nullptr;
  100.    }
  101.  #else
  102. -  set_inactivity_timeout(0);
  103. +  next_inactivity_timeout_at = 0;
  104.  #endif
  105.  }
  106.  
  107. @@ -427,7 +462,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 c7f1798fc..d13badc9d 100644
  118. --- a/iocore/net/UnixNet.cc
  119. +++ b/iocore/net/UnixNet.cc
  120. @@ -38,10 +38,20 @@ 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()) { SET_HANDLER(&InactivityCop::check_inactivity); }
  130. +  explicit InactivityCop(Ptr<ProxyMutex> &m) : Continuation(m.get()), default_inactivity_timeout(0)
  131. +  {
  132. +    SET_HANDLER(&InactivityCop::check_inactivity);
  133. +    REC_ReadConfigInteger(default_inactivity_timeout, "proxy.config.net.default_inactivity_timeout");
  134. +    Debug("inactivity_cop", "default inactivity timeout is set to: %d", default_inactivity_timeout);
  135. +
  136. +    RecRegisterConfigUpdateCb("proxy.config.net.default_inactivity_timeout", update_cop_config, (void *)this);
  137. +  }
  138. +
  139.    int
  140.    check_inactivity(int event, Event *e)
  141.    {
  142. @@ -50,8 +60,13 @@ public:
  143.      NetHandler &nh = *get_NetHandler(this_ethread());
  144.  
  145.      Debug("inactivity_cop_check", "Checking inactivity on Thread-ID #%d", this_ethread()->id);
  146. -    // The rest NetVCs in cop_list which are not triggered between InactivityCop runs.
  147. -    // Use pop() to catch any closes caused by callbacks.
  148. +    // Copy the list and use pop() to catch any closes caused by callbacks.
  149. +    forl_LL(UnixNetVConnection, vc, nh.open_list)
  150. +    {
  151. +      if (vc->thread == this_ethread()) {
  152. +        nh.cop_list.push(vc);
  153. +      }
  154. +    }
  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. @@ -65,6 +80,17 @@ 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. @@ -77,18 +103,6 @@ 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. @@ -96,8 +110,33 @@ 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. @@ -262,8 +301,7 @@ NetHandler::NetHandler()
  230.      max_connections_active_in(0),
  231.      inactive_threashold_in(0),
  232.      transaction_no_activity_timeout_in(0),
  233. -    keep_alive_no_activity_timeout_in(0),
  234. -    default_inactivity_timeout(0)
  235. +    keep_alive_no_activity_timeout_in(0)
  236.  {
  237.    SET_HANDLER((NetContHandler)&NetHandler::startNetEvent);
  238.  }
  239. @@ -298,10 +336,6 @@ update_nethandler_config(const char *name, RecDataT data_type ATS_UNUSED, RecDat
  240.        Debug("net_queue", "proxy.config.net.keep_alive_no_activity_timeout_in updated to %" PRId64, data.rec_int);
  241.        nh->keep_alive_no_activity_timeout_in = data.rec_int;
  242.      }
  243. -    if (strcmp(name, "proxy.config.net.default_inactivity_timeout") == 0) {
  244. -      Debug("net_queue", "proxy.config.net.default_inactivity_timeout updated to %" PRId64, data.rec_int);
  245. -      nh->default_inactivity_timeout = data.rec_int;
  246. -    }
  247.    }
  248.  
  249.    if (update_per_thread_configuration == true) {
  250. @@ -324,21 +358,18 @@ NetHandler::startNetEvent(int event, Event *e)
  251.    REC_ReadConfigInt32(inactive_threashold_in, "proxy.config.net.inactive_threashold_in");
  252.    REC_ReadConfigInt32(transaction_no_activity_timeout_in, "proxy.config.net.transaction_no_activity_timeout_in");
  253.    REC_ReadConfigInt32(keep_alive_no_activity_timeout_in, "proxy.config.net.keep_alive_no_activity_timeout_in");
  254. -  REC_ReadConfigInt32(default_inactivity_timeout, "proxy.config.net.default_inactivity_timeout");
  255.  
  256.    RecRegisterConfigUpdateCb("proxy.config.net.max_connections_in", update_nethandler_config, (void *)this);
  257.    RecRegisterConfigUpdateCb("proxy.config.net.max_active_connections_in", update_nethandler_config, (void *)this);
  258.    RecRegisterConfigUpdateCb("proxy.config.net.inactive_threashold_in", update_nethandler_config, (void *)this);
  259.    RecRegisterConfigUpdateCb("proxy.config.net.transaction_no_activity_timeout_in", update_nethandler_config, (void *)this);
  260.    RecRegisterConfigUpdateCb("proxy.config.net.keep_alive_no_activity_timeout_in", update_nethandler_config, (void *)this);
  261. -  RecRegisterConfigUpdateCb("proxy.config.net.default_inactivity_timeout", update_nethandler_config, (void *)this);
  262.  
  263.    Debug("net_queue", "proxy.config.net.max_connections_in updated to %d", max_connections_in);
  264.    Debug("net_queue", "proxy.config.net.max_active_connections_in updated to %d", max_connections_active_in);
  265.    Debug("net_queue", "proxy.config.net.inactive_threashold_in updated to %d", inactive_threashold_in);
  266.    Debug("net_queue", "proxy.config.net.transaction_no_activity_timeout_in updated to %d", transaction_no_activity_timeout_in);
  267.    Debug("net_queue", "proxy.config.net.keep_alive_no_activity_timeout_in updated to %d", keep_alive_no_activity_timeout_in);
  268. -  Debug("net_queue", "proxy.config.net.default_inactivity_timeout updated to %d", default_inactivity_timeout);
  269.  
  270.    configure_per_thread();
  271.  
  272. @@ -446,10 +477,6 @@ NetHandler::mainNetEvent(int event, Event *e)
  273.      epd = (EventIO *)get_ev_data(pd, x);
  274.      if (epd->type == EVENTIO_READWRITE_VC) {
  275.        vc = epd->data.vc;
  276. -      // Remove triggered NetVC from cop_list because it won't be timeout before next InactivityCop runs.
  277. -      if (cop_list.in(vc)) {
  278. -        cop_list.remove(vc);
  279. -      }
  280.        if (get_ev_events(pd, x) & EVENTIO_READ) {
  281.          vc->read.triggered = 1;
  282.          if (get_ev_events(pd, x) & EVENTIO_ERROR) {
  283. diff --git a/iocore/net/UnixNetAccept.cc b/iocore/net/UnixNetAccept.cc
  284. index d30ebe55e..a3094fb0d 100644
  285. --- a/iocore/net/UnixNetAccept.cc
  286. +++ b/iocore/net/UnixNetAccept.cc
  287. @@ -428,7 +428,6 @@ NetAccept::acceptFastEvent(int event, void *ep)
  288.      }
  289.  
  290.      ink_assert(vc->nh->mutex->thread_holding == this_ethread());
  291. -    vc->set_inactivity_timeout(0);
  292.      vc->nh->open_list.enqueue(vc);
  293.  
  294.  #ifdef USE_EDGE_TRIGGER
  295. diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc
  296. index 81bfde2a4..ae9f10c7e 100644
  297. --- a/iocore/net/UnixNetVConnection.cc
  298. +++ b/iocore/net/UnixNetVConnection.cc
  299. @@ -1205,7 +1205,6 @@ UnixNetVConnection::acceptEvent(int event, Event *e)
  300.      return EVENT_DONE;
  301.    }
  302.  
  303. -  set_inactivity_timeout(0);
  304.    nh->open_list.enqueue(this);
  305.  
  306.  #ifdef USE_EDGE_TRIGGER
  307. @@ -1420,9 +1419,9 @@ UnixNetVConnection::connectUp(EThread *t, int fd)
  308.    SET_HANDLER(&UnixNetVConnection::mainEvent);
  309.  
  310.    nh = get_NetHandler(t);
  311. -  set_inactivity_timeout(0);
  312.    nh->open_list.enqueue(this);
  313.  
  314. +  ink_assert(!inactivity_timeout_in);
  315.    ink_assert(!active_timeout_in);
  316.    this->set_local_addr();
  317.    action_.continuation->handleEvent(NET_EVENT_OPEN, this);
  318. @@ -1485,40 +1484,6 @@ UnixNetVConnection::apply_options()
  319.    con.apply_options(options);
  320.  }
  321.  
  322. -TS_INLINE void
  323. -UnixNetVConnection::set_inactivity_timeout(ink_hrtime timeout_in)
  324. -{
  325. -  Debug("socket", "Set inactive timeout=%" PRId64 ", for NetVC=%p", timeout_in, this);
  326. -#ifdef INACTIVITY_TIMEOUT
  327. -  if (inactivity_timeout)
  328. -    inactivity_timeout->cancel_action(this);
  329. -  if (timeout_in) {
  330. -    inactivity_timeout_in = timeout_in;
  331. -    if (read.enabled) {
  332. -      ink_assert(read.vio.mutex->thread_holding == this_ethread() && thread);
  333. -      if (read.vio.mutex->thread_holding == thread)
  334. -        inactivity_timeout = thread->schedule_in_local(this, inactivity_timeout_in);
  335. -      else
  336. -        inactivity_timeout = thread->schedule_in(this, inactivity_timeout_in);
  337. -    } else if (write.enabled) {
  338. -      ink_assert(write.vio.mutex->thread_holding == this_ethread() && thread);
  339. -      if (write.vio.mutex->thread_holding == thread)
  340. -        inactivity_timeout = thread->schedule_in_local(this, inactivity_timeout_in);
  341. -      else
  342. -        inactivity_timeout = thread->schedule_in(this, inactivity_timeout_in);
  343. -    } else
  344. -      inactivity_timeout = 0;
  345. -  } else
  346. -    inactivity_timeout = 0;
  347. -#else
  348. -  if (timeout_in == 0) {
  349. -    // set default inactivity timeout
  350. -    inactivity_timeout_in = timeout_in = HRTIME_SECONDS(nh->default_inactivity_timeout);
  351. -  }
  352. -  next_inactivity_timeout_at = Thread::get_hrtime() + timeout_in;
  353. -#endif
  354. -}
  355. -
  356.  /*
  357.   * Close down the current netVC.  Save aside the socket and SSL information
  358.   * and create new netVC in the current thread/netVC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement