Skip to content

Conversation

@zwoop
Copy link
Contributor

@zwoop zwoop commented Mar 1, 2023

This calls the clear() method ~230 times otherwise, which may seem benign, but it actually shows up as a significant CPU user in perf top. This patch added an extra 50K RPS (give or take) on my benchmark road trip.

@zwoop zwoop added this to the 10.0.0 milestone Mar 1, 2023
@zwoop zwoop requested a review from bryancall March 1, 2023 17:19
@zwoop zwoop self-assigned this Mar 1, 2023
@zwoop zwoop requested a review from bneradt March 1, 2023 17:20
h.clear();
if (m_hooks_p) {
for (auto &h : m_hooks) {
if (!h.is_empty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you check this in APIHooks::clear()? I guess clean() could just return without doing anything if it's empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of the "problem" is that APIHOoks as we did it can not be inlined, so it calls it 28 times for no good reason :/

bryancall
bryancall previously approved these changes Mar 6, 2023
@bryancall
Copy link
Contributor

Can you add a comment in the code about the change.

@zwoop
Copy link
Contributor Author

zwoop commented Mar 7, 2023

Can you add a comment in the code about the change.

Added a comment.

@zwoop
Copy link
Contributor Author

zwoop commented Mar 7, 2023

This is actually worse than I first expected, there's about 230 calls to this function. However, upon inspecting this, the problem is that

class HttpAPIHooks : public FeatureAPIHooks<TSHttpHookID, TS_HTTP_LAST_HOOK>

Creates (give or take) 180 or so APIHook objects which can never be used. There's a big gap between the last HTTP Hook (TS_HTTP_REQUEST_CLIENT_HOOK) and the first SSL hook (TS_SSL_FIRST_HOOK=201). I'm thinking that we need to move the last HTTP hook to be something like

TS_HTTP_LAST_HOOK = TS_HTTP_REQUEST_CLIENT_HOOK,

So not only do we call APIHooks::clear() ~180 times for no reason, it also allocates roughly 3KB of memory which is never used (but initialized). For every transaction.

@zwoop zwoop merged commit c54a2e2 into apache:master Mar 15, 2023
@zwoop zwoop deleted the APIHooksPerf branch March 15, 2023 21:48
zwoop added a commit that referenced this pull request Mar 15, 2023
@zwoop
Copy link
Contributor Author

zwoop commented Mar 15, 2023

Cherry-picked to v9.2.x

@zwoop zwoop modified the milestones: 10.0.0, 9.2.1 Mar 15, 2023
masaori335 pushed a commit to masaori335/trafficserver that referenced this pull request Jul 24, 2023
* Slight performance improvements before calling APIHooks::clear (apache#9480)

(cherry picked from commit c54a2e2)
(cherry picked from commit 782fbfd)

* Fix compile warning on BoringSSL build (apache#9525)

(cherry picked from commit 0bd8816)
(cherry picked from commit c31b062)

Co-authored-by: Leif Hedstrom <zwoop@apache.org>
Co-authored-by: Masakazu Kitajo <maskit@apache.org>
masaori335 pushed a commit to masaori335/trafficserver that referenced this pull request Jul 24, 2023
cmcfarlen pushed a commit to cmcfarlen/trafficserver that referenced this pull request Jun 3, 2024
cmcfarlen pushed a commit to cmcfarlen/trafficserver that referenced this pull request Jun 3, 2024
* commit 'c54a2e2b77151869ff014fbdc4c82cec0afcbb8c': (37 commits)
  Slight performance improvements before calling APIHooks::clear (apache#9480)
  libswoc: Update to 1.4.5 (apache#9522)
  CryptoContext: Clean up to avoid compiler problem. (apache#9521)
  Add TLSCertSwitchSupport (apache#9322)
  Add clang-format-tests to clang-format target (apache#9456)
  Adds the AR env variable to config.nice (apache#9515)
  Fix .asf.yaml (apache#9519)
  Hugepage config cleanup (apache#9479)
  Separate io_uring into a separate library. AIO in io_uring mode uses new io_uring lib. (apache#9462)
  Avoid memory allocation in CryptoHash (apache#9474)
  UnitParser: add unit parser support. (apache#9485)
  autest - Minor fix on the verifier_client test ext to allow setting only the http3 ports. (apache#9517)
  Remove support for port event polling (apache#9476)
  QUIC: Add support to configure UDP max payload limit. (apache#9486)
  Reduce the size of the APIHooks, eliminating enum gap (apache#9509)
  Add support for CMCD-Request header nor field to prefetch plugin (apache#9232)
  Eliminates padding from some common structs (apache#9481)
  Enable external file loading for sni.yaml. (apache#9501)
  Remove inactive include of IpMapConf.h (apache#9512)
  Cleanup: Remove RecModeT from the code. (apache#9487)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants