Fix high response latency with multiple API-requests targeting non-existent hosts or services#10883
Open
jschmidt-icinga wants to merge 3 commits into
Open
Fix high response latency with multiple API-requests targeting non-existent hosts or services#10883jschmidt-icinga wants to merge 3 commits into
jschmidt-icinga wants to merge 3 commits into
Conversation
f83e8c7 to
c14e5de
Compare
`DiagnosticInformation()` wasn't able to take a `std::exception_ptr` due to the missing conversion on older boost versions, so now everything uses the std::exception_ptr instead. There are still a few reasons to use `boost::exception` in some places, but for exception pointers, the standard one should be better in most cases and almost never requires to include an extra header.
c14e5de to
83f42f4
Compare
This was likely meant as a fallback for non-`std::exception` exception pointers, but it would never have been reached, because `(std|boost)::rethrow_exception()` would have thrown those out of the function scope. This fixes the fallback by making it a catch handler and also using the more direct way of getting this fallback diagnostic info inside a catch handler.
The `diagnostic_information` string will now generated if and when it is required (i.e. the "verbose" parameter is true).
83f42f4 to
1c40368
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes the high response latency observed in #10875 when multiple requests target non-existent hosts in parallel. The reason is that for almost all API endpoints that target config objects diagnostic information including a stack trace is generated, regardless if it is actually returned (which only happens when the "verbose" parameter is given). The solution is to pass the
exception_ptrintoSendJsonError()and only generate theDiagnosticInformationfrom it when needed.Solution
SendJsonError()now takes astd::exception_ptrargument instead of adagnosticInformationstring that is generated at the call site. This is cheap and doesn't cause any copies. Then, where the actual decision is made to include thediagnostic_information(i.e. dependent on the "verbose" parameter),DiagnosticInformation(<eptr>)is run. The overload already existed, so there wasn't even a need to rethrow the exception and process the string from the result.This is a clean solution, and the change makes sense even without the latency amplification in mind, since pointless work is avoided in any case.
However, some yak-shaving was required to feed
SendJsonError()with an exception pointer gathered withstd::current_exception()at the call-site. I had to make the entire code-base usestd::exception_ptrinstead ofboost::exception_ptr. On the newest boost version, this is just a typedef, on previous versions the boost one could be constructed from the std one, but there's also old versions we still support which didn't have that conversion. And that refactor in turn uncovered a small bug in theDiagnosticInformation(<eptr>)which had a dead-code fallback that then failed to compile and is now fixed.Testing
Using the test-script that was provided in #10875, the improvement is clearly observable:
Before
With existent host/service:
With non-existent host/service:
After
With existent host/service:
With non-existent host/service:
You can see that the error responses for non-existant targets are now actually much faster than successful requests, as one would expect.
Fixes #10875.