Skip to content

Commit

Permalink
Add some minor CPU performance improvements
Browse files Browse the repository at this point in the history
Replace 'if else' sentences by 'switch case' ones when proceeed.
Also, rename 'st' to 'benchmark' directory name.
  • Loading branch information
testillano authored and Eduardo Ramos Testillano (eramedu) committed Nov 29, 2023
1 parent 786ee13 commit 97e1199
Show file tree
Hide file tree
Showing 13 changed files with 343 additions and 104 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ src/version.cpp

# Test temporary files
tools/play-h2agent/*/.*
st/report*
st/last
benchmark/report*
benchmark/last

# Coverage report
coverage
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ COPY --from=builder /code/build/${build_type}/bin/udp-client /opt/
# We add curl & jq for helpers.src
# Ubuntu has bash already installed, but vim is missing
ARG base_os=ubuntu
RUN if [ "${base_os}" = "alpine" ] ; then apk update && apk add bash curl jq && rm -rf /var/cache/apk/* ; elif [ "${base_os}" = "ubuntu" ] ; then apt-get update && apt-get install -y vim curl jq && apt-get clean ; fi
RUN if [ "${base_os}" = "alpine" ] ; then apk update && apk add bash curl jq && rm -rf /var/cache/apk/* ; elif [ "${base_os}" = "ubuntu" ] ; then apt-get update && apt-get install -y vim curl jq valgrind && apt-get clean ; fi

ENTRYPOINT ["/opt/h2agent"]
CMD []
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,9 @@ Reference:



Load testing is done with both [h2load](https://nghttp2.org/documentation/h2load-howto.html) and [hermes](https://github.com/jgomezselles/hermes) utilities using the helper script `st/start.sh` (check `-h|--help` for more information). Client capabilities benchmarking is done towards the `h2agent` itself, so we also could select `h2agent` with a simple client provision to work as the former utilities.
Load testing is done with both [h2load](https://nghttp2.org/documentation/h2load-howto.html) and [hermes](https://github.com/jgomezselles/hermes) utilities using the helper script `benchmark/start.sh` (check `-h|--help` for more information). Client capabilities benchmarking is done towards the `h2agent` itself, so we also could select `h2agent` with a simple client provision to work as the former utilities.

Also, `st/repeat.sh` script repeats a previous execution (last by default) in headless mode.
Also, `benchmark/repeat.sh` script repeats a previous execution (last by default) in headless mode.

#### Considerations

Expand All @@ -533,7 +533,7 @@ $> docker run --rm -it --network=host -v $(pwd -P):$(pwd -P) ghcr.io/testillano/
In other shell we launch the benchmark test:

```bash
$> st/start.sh -y
$> benchmark/start.sh -y
Input Validate schemas (y|n)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion ct/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ then
cat << EOF
You may want to start a proxy to minikube Cluster IP, in order to use native utilities like:
$> st/start.sh -y # traffic load
$> benchmark/start.sh -y # traffic load
$> source tools/helpers.src # troubleshooting
etc.
Expand Down
31 changes: 17 additions & 14 deletions src/http2/MyTrafficHttp2Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,18 @@ ss << "TRAFFIC REQUEST RECEIVED"
normalizedUri += uriQueryNormalized;

h2agent::model::AdminServerMatchingData::UriPathQueryParametersFilterType uriPathQueryParametersFilterType = getAdminData()->getServerMatchingData().getUriPathQueryParametersFilter();
if (uriPathQueryParametersFilterType != h2agent::model::AdminServerMatchingData::Ignore) {
switch (uriPathQueryParametersFilterType) {
case h2agent::model::AdminServerMatchingData::PassBy:
classificationUri += "?";
if (uriPathQueryParametersFilterType == h2agent::model::AdminServerMatchingData::PassBy) {
classificationUri += uriQuery;
}
else if (uriPathQueryParametersFilterType == h2agent::model::AdminServerMatchingData::Sort) {
classificationUri += uriQueryNormalized;
}
classificationUri += uriQuery;
break;
case h2agent::model::AdminServerMatchingData::Sort:
classificationUri += "?";
classificationUri += uriQueryNormalized;
break;
case h2agent::model::AdminServerMatchingData::Ignore:
break;
}

}

LOGDEBUG(
Expand Down Expand Up @@ -260,15 +262,16 @@ ss << "TRAFFIC REQUEST RECEIVED"
}
);

if (algorithmType == h2agent::model::AdminServerMatchingData::FullMatching) {
switch (algorithmType) {
case h2agent::model::AdminServerMatchingData::FullMatching:
LOGDEBUG(
std::string msg = ert::tracing::Logger::asString("Searching 'FullMatching' provision for method '%s', classification uri '%s' and state '%s'", method.c_str(), classificationUri.c_str(), inState.c_str());
ert::tracing::Logger::debug(msg, ERT_FILE_LOCATION);
);
provision = provisionData.find(inState, method, classificationUri);
}
else if (algorithmType == h2agent::model::AdminServerMatchingData::FullMatchingRegexReplace) {
break;

case h2agent::model::AdminServerMatchingData::FullMatchingRegexReplace:
// In this case, our classification URI is pending to be transformed:
classificationUri = std::regex_replace (classificationUri, matchingData.getRgx(), matchingData.getFmt());
LOGDEBUG(
Expand All @@ -278,9 +281,8 @@ ss << "TRAFFIC REQUEST RECEIVED"
ert::tracing::Logger::debug(msg, ERT_FILE_LOCATION);
);
provision = provisionData.find(inState, method, classificationUri);
}
else if (algorithmType == h2agent::model::AdminServerMatchingData::RegexMatching) {

break;
case h2agent::model::AdminServerMatchingData::RegexMatching:
LOGDEBUG(
std::string msg = ert::tracing::Logger::asString("Searching 'RegexMatching' provision for method '%s', classification uri '%s' and state '%s'", method.c_str(), classificationUri.c_str(), inState.c_str());
ert::tracing::Logger::debug(msg, ERT_FILE_LOCATION);
Expand All @@ -289,6 +291,7 @@ ss << "TRAFFIC REQUEST RECEIVED"
// as provision key is built combining inState, method and uri fields, a regular expression could also be provided for inState
// (method is strictly checked). TODO could we avoid this rare and unpredictable usage ?
provision = provisionData.findRegexMatching(inState, method, classificationUri);
break;
}

// Fall back to possible default provision (empty URI):
Expand Down
Loading

0 comments on commit 97e1199

Please sign in to comment.