You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by GitBox <gi...@apache.org> on 2022/09/29 23:18:14 UTC

[GitHub] [trafficserver] SolidWallOfCode opened a new pull request, #9114: Add event loop timing histogram data.

SolidWallOfCode opened a new pull request, #9114:
URL: https://github.com/apache/trafficserver/pull/9114

   This is based on a problem I had at LinkedIn involving latency in requests. The event loop data looked as if the event loops were very long (billions of nanoseconds in some cases) but it wasn't possible to tell if this was the exception or the rule (i.e. is there a plugin that now and then blocks on an `ET_NET` thread, or are the plugins in general slowing things up?). This adds histogram data for event loop timing so it's possible to see
   
   1. How relatively common long loops.
   2. Whether there are many long loops, instead of tracking only the very longest.
   3. Whether there are clusters at certain timings.
   
   This should be backwards compatible with 9.x.
   
   As part of this work, the `Histogram` class is added. It is designed to log samples performantly and provides a decay mechanism to keep the data relevant. These call all be adjusted by tweaking various compile time constants.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] SolidWallOfCode commented on a diff in pull request #9114: Add event loop timing histogram data.

Posted by GitBox <gi...@apache.org>.
SolidWallOfCode commented on code in PR #9114:
URL: https://github.com/apache/trafficserver/pull/9114#discussion_r984771313


##########
proxy/http/HttpSM.cc:
##########
@@ -8457,5 +8454,7 @@ HttpSM::milestone_update_api_time()
       }
       milestones[TS_MILESTONE_PLUGIN_ACTIVE] += delta;
     }
+    this_ethread()->metrics._api_timing(
+      delta / std::chrono::duration_cast<std::chrono::nanoseconds>(EThread::Metrics::API_HISTOGRAM_BUCKET_SIZE).count());

Review Comment:
   Technically using a leading underscore for member variables is an ATS standard, which I try to promote.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] SolidWallOfCode commented on a diff in pull request #9114: Add event loop timing histogram data.

Posted by GitBox <gi...@apache.org>.
SolidWallOfCode commented on code in PR #9114:
URL: https://github.com/apache/trafficserver/pull/9114#discussion_r984771761


##########
iocore/eventsystem/UnixEThread.cc:
##########
@@ -289,26 +292,31 @@ EThread::execute_regular()
 
     // loop cleanup
     loop_finish_time = Thread::get_hrtime_updated();
-    delta            = loop_finish_time - loop_start_time;
-
-    // This can happen due to time of day adjustments (which apparently happen quite frequently). I
+    // @a delta can be negative due to time of day adjustments (which apparently happen quite frequently). I
     // tried using the monotonic clock to get around this but it was *very* stuttery (up to hundreds
     // of milliseconds), far too much to be actually used.
-    if (delta > 0) {
-      if (delta > current_metric->_loop_time._max) {
-        current_metric->_loop_time._max = delta;
-      }
-      if (delta < current_metric->_loop_time._min) {
-        current_metric->_loop_time._min = delta;
-      }
+    delta = std::max<ink_hrtime>(0, loop_finish_time - loop_start_time);
+
+    if (delta > metrics.current_slice->_duration._max) {
+      metrics.current_slice->_duration._max = delta;
+    }
+    if (delta < metrics.current_slice->_duration._min) {
+      metrics.current_slice->_duration._min = delta;
     }
-    if (ev_count < current_metric->_events._min) {
-      current_metric->_events._min = ev_count;
+    if (ev_count < metrics.current_slice->_events._min) {
+      metrics.current_slice->_events._min = ev_count;
     }
-    if (ev_count > current_metric->_events._max) {
-      current_metric->_events._max = ev_count;
+    if (ev_count > metrics.current_slice->_events._max) {
+      metrics.current_slice->_events._max = ev_count;
     }
-    current_metric->_events._total += ev_count;
+    metrics.current_slice->_events._total += ev_count;
+    // Take care of any data decay.
+    while (metrics._decay_count) {
+      metrics._loop_timing.decay();
+      metrics._api_timing.decay();
+      --metrics._decay_count;
+    }
+    metrics._loop_timing(delta / std::chrono::duration_cast<std::chrono::nanoseconds>(Metrics::LOOP_HISTOGRAM_BUCKET_SIZE).count());

Review Comment:
   Or add `Metric::decay`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] maskit commented on a diff in pull request #9114: Add event loop timing histogram data.

Posted by GitBox <gi...@apache.org>.
maskit commented on code in PR #9114:
URL: https://github.com/apache/trafficserver/pull/9114#discussion_r985331085


##########
include/tscpp/util/Histogram.h:
##########
@@ -0,0 +1,188 @@
+/** @file
+ *
+ * Fast small foot print histogram support.
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include <array>
+
+#if !defined(TS_VERSION_NS)
+#define TS_VERSION_NS _10_0_0
+#endif
+
+namespace ts
+{
+inline namespace TS_VERSION_NS

Review Comment:
   Why do we need versioning for this but not others?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] SolidWallOfCode commented on a diff in pull request #9114: Add event loop timing histogram data.

Posted by GitBox <gi...@apache.org>.
SolidWallOfCode commented on code in PR #9114:
URL: https://github.com/apache/trafficserver/pull/9114#discussion_r985930828


##########
include/tscpp/util/Histogram.h:
##########
@@ -0,0 +1,188 @@
+/** @file
+ *
+ * Fast small foot print histogram support.
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include <array>
+
+#if !defined(TS_VERSION_NS)
+#define TS_VERSION_NS _10_0_0
+#endif
+
+namespace ts
+{
+inline namespace TS_VERSION_NS

Review Comment:
   We want it for others, but I didn't want this PR to be a massive one. You can see all of the libswoc code is versioned that way, so as it replaces other core libraries those will gain this protection as well.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] SolidWallOfCode merged pull request #9114: Add event loop timing histogram data.

Posted by GitBox <gi...@apache.org>.
SolidWallOfCode merged PR #9114:
URL: https://github.com/apache/trafficserver/pull/9114


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] cmcfarlen commented on a diff in pull request #9114: Add event loop timing histogram data.

Posted by GitBox <gi...@apache.org>.
cmcfarlen commented on code in PR #9114:
URL: https://github.com/apache/trafficserver/pull/9114#discussion_r984723311


##########
iocore/eventsystem/UnixEThread.cc:
##########
@@ -289,26 +292,31 @@ EThread::execute_regular()
 
     // loop cleanup
     loop_finish_time = Thread::get_hrtime_updated();
-    delta            = loop_finish_time - loop_start_time;
-
-    // This can happen due to time of day adjustments (which apparently happen quite frequently). I
+    // @a delta can be negative due to time of day adjustments (which apparently happen quite frequently). I
     // tried using the monotonic clock to get around this but it was *very* stuttery (up to hundreds
     // of milliseconds), far too much to be actually used.
-    if (delta > 0) {
-      if (delta > current_metric->_loop_time._max) {
-        current_metric->_loop_time._max = delta;
-      }
-      if (delta < current_metric->_loop_time._min) {
-        current_metric->_loop_time._min = delta;
-      }
+    delta = std::max<ink_hrtime>(0, loop_finish_time - loop_start_time);
+
+    if (delta > metrics.current_slice->_duration._max) {
+      metrics.current_slice->_duration._max = delta;
+    }
+    if (delta < metrics.current_slice->_duration._min) {
+      metrics.current_slice->_duration._min = delta;
     }
-    if (ev_count < current_metric->_events._min) {
-      current_metric->_events._min = ev_count;
+    if (ev_count < metrics.current_slice->_events._min) {
+      metrics.current_slice->_events._min = ev_count;
     }
-    if (ev_count > current_metric->_events._max) {
-      current_metric->_events._max = ev_count;
+    if (ev_count > metrics.current_slice->_events._max) {
+      metrics.current_slice->_events._max = ev_count;
     }
-    current_metric->_events._total += ev_count;
+    metrics.current_slice->_events._total += ev_count;
+    // Take care of any data decay.
+    while (metrics._decay_count) {
+      metrics._loop_timing.decay();
+      metrics._api_timing.decay();
+      --metrics._decay_count;
+    }
+    metrics._loop_timing(delta / std::chrono::duration_cast<std::chrono::nanoseconds>(Metrics::LOOP_HISTOGRAM_BUCKET_SIZE).count());

Review Comment:
   Even though metrics is a inner class of EThread, it looks odd directly accessing privately-named variables here.  Perhaps this could just call a `loop_timing` method on Metrics that does this end of loop stuff?



##########
proxy/http/HttpSM.cc:
##########
@@ -8457,5 +8454,7 @@ HttpSM::milestone_update_api_time()
       }
       milestones[TS_MILESTONE_PLUGIN_ACTIVE] += delta;
     }
+    this_ethread()->metrics._api_timing(
+      delta / std::chrono::duration_cast<std::chrono::nanoseconds>(EThread::Metrics::API_HISTOGRAM_BUCKET_SIZE).count());

Review Comment:
   Perhaps `_api_timing` could just take the delta and the histogram stuff could be handled by the Metrics class?  That way the caller doesn't need to know its updating a histogram.  I'd drop the underscore as well.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] SolidWallOfCode commented on pull request #9114: Add event loop timing histogram data.

Posted by GitBox <gi...@apache.org>.
SolidWallOfCode commented on PR #9114:
URL: https://github.com/apache/trafficserver/pull/9114#issuecomment-1264013469

   I cleaned up the internal access quite a bit, as @cmcfarlen requested, and fixed a build error (I hope).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org