Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add appsec benchmarks #2791

Merged
merged 27 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ebd0ab7
Add basic benchmarks skeleton
estringana Aug 14, 2024
c0e0ac5
Point to my ongoing branch on benchmarks
estringana Aug 22, 2024
24dab61
Add some changes so benchmarks can run
estringana Aug 22, 2024
a93a97d
tweak: Ensure that appsec and tracer benchmarks have separate filenames
ddyurchenko Sep 2, 2024
bd11d00
Install appsec extension and helper
estringana Sep 10, 2024
be9e053
Check debbuging logging files
estringana Sep 10, 2024
5883ce0
Output php modules installed
estringana Sep 10, 2024
3e88984
Enable appsec cli on benchmarks
estringana Sep 10, 2024
8ad0e7c
Update rules configuration
estringana Sep 11, 2024
e8b8547
Remove debug mode
estringana Sep 11, 2024
d2bffd1
Avoid failure when no logs generated
estringana Sep 11, 2024
71c27b9
Add 8.2 bookworm
estringana Sep 12, 2024
54c1fe7
Remove debugging line
estringana Sep 12, 2024
ebbef0f
Set appsec target benchmark tests
estringana Sep 13, 2024
9ecca43
Remove temporary stuff on PR
estringana Sep 16, 2024
7f15058
Point to temporary branch
estringana Sep 16, 2024
89c08fb
Fix tea tests
estringana Sep 17, 2024
620b5d4
Remove log files after printing them
estringana Sep 17, 2024
9122e08
Display php errors if any
estringana Sep 18, 2024
da4f67a
TEMP
estringana Sep 18, 2024
415a3ae
Generate logs
estringana Sep 18, 2024
f38dddc
Point benchmarks to the right version of Laravel
estringana Sep 19, 2024
339adfc
Fix wordpress database setup in benchmark tests
estringana Sep 19, 2024
aaec12b
Revert changes to makefile
estringana Sep 20, 2024
0b8f053
Avoid loading appsec mock on benchmarks
estringana Sep 20, 2024
ffb0d10
Fix namespaces on bootstrap files
estringana Sep 23, 2024
95aa3f3
Revert target benchmark branch
estringana Sep 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .gitlab/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,34 @@ benchmarks-tracer:
compare_to: "master"
when: on_success
- when: manual
artifacts:
name: "logs"
paths:
- candidate.tar.gz
- baseline.tar.gz
expire_in: 2 days
variables:
SCENARIO: "tracer"

benchmarks-appsec:
extends: .microbenchmarks
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
changes:
paths:
- appsec/src/**/*
compare_to: "master"
when: on_success
- when: manual
artifacts:
name: "logs"
paths:
- candidate.tar.gz
- baseline.tar.gz
expire_in: 2 days
variables:
SCENARIO: "appsec"


download_circle_ci_release:
stage: benchmarks
Expand Down
29 changes: 25 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ PROJECT_ROOT := ${PWD}
TRACER_SOURCE_DIR := $(PROJECT_ROOT)/src/
ASAN ?= $(shell ldd $(shell which php) 2>/dev/null | grep -q libasan && echo 1)
SHELL = /bin/bash
APPSEC_SOURCE_DIR = $(PROJECT_ROOT)/appsec/
BUILD_SUFFIX = extension
BUILD_DIR = $(PROJECT_ROOT)/tmp/build_$(BUILD_SUFFIX)
BUILD_DIR_APPSEC = $(BUILD_DIR)/appsec/
ZAI_BUILD_DIR = $(PROJECT_ROOT)/tmp/build_zai$(if $(ASAN),_asan)
TEA_BUILD_DIR = $(PROJECT_ROOT)/tmp/build_tea$(if $(ASAN),_asan)
TEA_INSTALL_DIR = $(TEA_BUILD_DIR)/opt
Expand All @@ -13,7 +15,8 @@ TEA_BUILD_BENCHMARKS ?= OFF
TEA_BENCHMARK_REPETITIONS ?= 10
# Note: If the tea benchmark format or output is changed, make changes to ./benchmark/runall.sh
TEA_BENCHMARK_FORMAT ?= json
TEA_BENCHMARK_OUTPUT ?= $(PROJECT_ROOT)/tea/benchmarks/reports/tea-bench-results.$(TEA_BENCHMARK_FORMAT)
TEA_BENCHMARK_OUTPUT ?= $(PROJECT_ROOT)/tea/benchmarks/reports/tracer-tea-bench-results.$(TEA_BENCHMARK_FORMAT)
BENCHMARK_EXTRA ?=
PROFeNoM marked this conversation as resolved.
Show resolved Hide resolved
COMPONENTS_BUILD_DIR = $(PROJECT_ROOT)/tmp/build_components
SO_FILE = $(BUILD_DIR)/modules/ddtrace.so
AR_FILE = $(BUILD_DIR)/modules/ddtrace.a
Expand Down Expand Up @@ -127,6 +130,24 @@ $(INI_FILE):

install_ini: $(INI_FILE)

delete_ini:
$(SUDO) rm $(INI_FILE)

install_appsec:
cmake -S $(APPSEC_SOURCE_DIR) -B $(BUILD_DIR_APPSEC)
cd $(BUILD_DIR_APPSEC);make extension ddappsec-helper
cp $(BUILD_DIR_APPSEC)/ddappsec.so $(PHP_EXTENSION_DIR)/ddappsec.so
cp $(BUILD_DIR_APPSEC)/libddappsec-helper.so $(PHP_EXTENSION_DIR)/libddappsec-helper.so
cp $(APPSEC_SOURCE_DIR)/recommended.json /tmp/recommended.json
$(Q) echo "extension=ddappsec.so" | $(SUDO) tee -a $(INI_FILE)
$(Q) echo "datadog.appsec.cli_start_on_rinit=true" | $(SUDO) tee -a $(INI_FILE)
$(Q) echo "datadog.appsec.helper_path=$(PHP_EXTENSION_DIR)/libddappsec-helper.so" | $(SUDO) tee -a $(INI_FILE)
$(Q) echo "datadog.appsec.rules=/tmp/recommended.json" | $(SUDO) tee -a $(INI_FILE)
$(Q) echo "datadog.appsec.helper_socket_path=/tmp/ddappsec.sock" | $(SUDO) tee -a $(INI_FILE)
$(Q) echo "datadog.appsec.helper_lock_path=/tmp/ddappsec.lock" | $(SUDO) tee -a $(INI_FILE)
$(Q) echo "datadog.appsec.log_file=/tmp/logs/appsec.log" | $(SUDO) tee -a $(INI_FILE)
$(Q) echo "datadog.appsec.helper_log_file=/tmp/logs/helper.log" | $(SUDO) tee -a $(INI_FILE)

install_all: install install_ini

run_tests: $(TEST_FILES) $(TEST_STUB_FILES) $(BUILD_DIR)/run-tests.php
Expand Down Expand Up @@ -1037,11 +1058,11 @@ endef


define run_benchmarks
$(ENV_OVERRIDE) php -d extension=redis-5.3.7.so $(TEST_EXTRA_INI) $(TRACER_SOURCES_INI) $(PHPBENCH) --config=$(1) --filter=$(FILTER) --report=all --output=file --output=console
$(ENV_OVERRIDE) php -d extension=redis-5.3.7.so $(TEST_EXTRA_INI) $(TRACER_SOURCES_INI) $(PHPBENCH) --config=$(1) --filter=$(FILTER) --report=all --output=file --output=console $(BENCHMARK_EXTRA)
endef

define run_benchmarks_with_ddprof
$(ENV_OVERRIDE) ddprof -S $(DDPROF_IDENTIFIER) php -d extension=redis-5.3.7.so $(TEST_EXTRA_INI) $(REQUEST_INIT_HOOK) $(PHPBENCH) --config=$(1) --filter=$(FILTER) --report=all --output=file --output=console
$(ENV_OVERRIDE) ddprof -S $(DDPROF_IDENTIFIER) php -d extension=redis-5.3.7.so $(TEST_EXTRA_INI) $(REQUEST_INIT_HOOK) $(PHPBENCH) --config=$(1) --filter=$(FILTER) --report=all --output=file --output=console $(BENCHMARK_EXTRA)
endef

define run_composer_with_lock
Expand Down Expand Up @@ -1112,7 +1133,7 @@ test_distributed_tracing_coverage:
test_metrics: global_test_run_dependencies
$(call run_tests,--testsuite=metrics $(TESTS))

benchmarks_run_dependencies: global_test_run_dependencies tests/Frameworks/Symfony/Version_5_2/composer.lock-php$(PHP_MAJOR_MINOR) tests/Frameworks/Laravel/Version_8_x/composer.lock-php$(PHP_MAJOR_MINOR) tests/Benchmarks/composer.lock-php$(PHP_MAJOR_MINOR)
benchmarks_run_dependencies: global_test_run_dependencies tests/Frameworks/Symfony/Version_5_2/composer.lock-php$(PHP_MAJOR_MINOR) tests/Frameworks/Laravel/Version_10_x/composer.lock-php$(PHP_MAJOR_MINOR) tests/Benchmarks/composer.lock-php$(PHP_MAJOR_MINOR)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the reason why Laravel performance has increased. Basically, the autoloader didn't exists and all responses were fast because they were 500x

php tests/Frameworks/Symfony/Version_5_2/bin/console cache:clear --no-warmup --env=prod

call_benchmarks:
Expand Down
14 changes: 13 additions & 1 deletion benchmark/runall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,17 @@ elif [ "$SCENARIO" = "tracer" ]; then

## Request Startup/Shutdown Benchmarks
make benchmarks_tea
cp tea/benchmarks/reports/tea-bench-results.json "$ARTIFACTS_DIR/tracer-tea-bench-results.json"
cp tea/benchmarks/reports/tracer-tea-bench-results.json "$ARTIFACTS_DIR/tracer-tea-bench-results.json"
elif [ "$SCENARIO" = "appsec" ]; then
# Run Appsec Benchmarks
cd ..
make composer_tests_update
make benchmarks_run_dependencies
make install_appsec

## Non-OPCache Benchmarks
BENCHMARK_EXTRA="--group=frameworks" make call_benchmarks
cp tests/Benchmarks/reports/tracer-bench-results.csv "$ARTIFACTS_DIR/appsec-bench-results.csv"

make delete_ini
fi
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ services:
'8.3-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.3_buster' }
'php-master-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-master_buster' }
# --- Bookworm ---
'8.2-bookworm': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.2_bookworm-3' }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really needed but I added it here because that's the image I use to test benchmarks. Appsec is not compiling on buster versions

'8.3-bookworm': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.3_bookworm-3' }
# --- CentOS 6 ---
'7.0-centos7': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-7.0_centos-7' }
Expand Down
21 changes: 4 additions & 17 deletions tests/Benchmarks/Integrations/EmptyFileBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

use DDTrace\Tests\Common\WebFrameworkTestCase;
use DDTrace\Tests\Frameworks\Util\Request\GetSpec;
use Benchmarks\Integrations\FrameworkBenchmarksCase;

class EmptyFileBench extends WebFrameworkTestCase
class EmptyFileBench extends FrameworkBenchmarksCase
{
/**
* @BeforeMethods("disabledTracing")
* @BeforeMethods("disableDatadog")
* @AfterMethods("afterMethod")
* @Revs(10)
* @Iterations(10)
Expand All @@ -27,7 +28,7 @@ public function benchEmptyFileBaseline()
}

/**
* @BeforeMethods("enableTracing")
* @BeforeMethods("enableDatadog")
* @AfterMethods("afterMethod")
* @Revs(10)
* @Iterations(10)
Expand All @@ -48,22 +49,8 @@ public static function getAppIndexScript()
return __DIR__ . '/../../Frameworks/Custom/Version_Not_Autoloaded/index.php';
}

public function disabledTracing()
{
$this->setUpWebServer([
'DD_TRACE_ENABLED' => 0,
]);
}

public function afterMethod()
{
$this->TearDownAfterClass();
}

public function enableTracing()
{
$this->setUpWebServer([
'DD_TRACE_ENABLED' => 1,
]);
}
}
36 changes: 36 additions & 0 deletions tests/Benchmarks/Integrations/FrameworkBenchmarksCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Benchmarks\Integrations;

use DDTrace\Tests\Common\WebFrameworkTestCase;
use DDTrace\Tests\Frameworks\Util\Request\GetSpec;

abstract class FrameworkBenchmarksCase extends WebFrameworkTestCase
{
protected function getClassName()
{
$fullyQualified = get_class($this);
$tokens = explode('\\', $fullyQualified);
return end($tokens);
}

public function disableDatadog()
{
$name = $this->getClassName();
$this->setUpWebServer([
'DD_TRACE_ENABLED' => 0,
'DD_APPSEC_ENABLED' => 0,
], ['error_log' => "/tmp/logs/$name.log"]);
}

public function enableDatadog()
{
$name = $this->getClassName();
$this->setUpWebServer([
'DD_TRACE_ENABLED' => 1,
'DD_APPSEC_ENABLED' => 1,
], ['error_log' => "/tmp/logs/$name.log"]);
}
}
23 changes: 6 additions & 17 deletions tests/Benchmarks/Integrations/LaravelBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
use DDTrace\Tests\Common\WebFrameworkTestCase;
use DDTrace\Tests\Frameworks\Util\Request\GetSpec;

class LaravelBench extends WebFrameworkTestCase
/**
* @Groups({"frameworks"})
*/
class LaravelBench extends FrameworkBenchmarksCase
{
/**
* @BeforeMethods("disableLaravelTracing")
* @BeforeMethods("disableDatadog")
* @AfterMethods("afterMethod")
* @Revs(10)
* @Iterations(10)
Expand All @@ -27,7 +30,7 @@ public function benchLaravelBaseline()
}

/**
* @BeforeMethods("enableLaravelTracing")
* @BeforeMethods("enableDatadog")
* @AfterMethods("afterMethod")
* @Revs(10)
* @Iterations(10)
Expand All @@ -48,22 +51,8 @@ public static function getAppIndexScript()
return __DIR__ . '/../../Frameworks/Laravel/Version_10_x/public/index.php';
}

public function disableLaravelTracing()
{
$this->setUpWebServer([
'DD_TRACE_ENABLED' => 0,
]);
}

public function afterMethod()
{
$this->TearDownAfterClass();
}

public function enableLaravelTracing()
{
$this->setUpWebServer([
'DD_TRACE_ENABLED' => 1,
]);
}
}
23 changes: 6 additions & 17 deletions tests/Benchmarks/Integrations/SymfonyBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
use DDTrace\Tests\Common\WebFrameworkTestCase;
use DDTrace\Tests\Frameworks\Util\Request\GetSpec;

class SymfonyBench extends WebFrameworkTestCase
/**
* @Groups({"frameworks"})
*/
class SymfonyBench extends FrameworkBenchmarksCase
{
/**
* @BeforeMethods("disableSymfonyTracing")
* @BeforeMethods("disableDatadog")
* @AfterMethods("afterMethod")
* @Revs(10)
* @Iterations(10)
Expand All @@ -27,7 +30,7 @@ public function benchSymfonyBaseline()
}

/**
* @BeforeMethods("enableSymfonyTracing")
* @BeforeMethods("enableDatadog")
* @AfterMethods("afterMethod")
* @Revs(10)
* @Iterations(10)
Expand All @@ -48,22 +51,8 @@ public static function getAppIndexScript()
return __DIR__ . '/../../Frameworks/Symfony/Version_5_2/public/index.php';
}

public function disableSymfonyTracing()
{
$this->setUpWebServer([
'DD_TRACE_ENABLED' => 0,
]);
}

public function afterMethod()
{
$this->TearDownAfterClass();
}

public function enableSymfonyTracing()
{
$this->setUpWebServer([
'DD_TRACE_ENABLED' => 1,
]);
}
}
21 changes: 7 additions & 14 deletions tests/Benchmarks/Integrations/WordPressBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
use DDTrace\Tests\Common\WebFrameworkTestCase;
use DDTrace\Tests\Frameworks\Util\Request\GetSpec;

class WordPressBench extends WebFrameworkTestCase
/**
* @Groups({"frameworks"})
*/
class WordPressBench extends FrameworkBenchmarksCase
{
/**
* @BeforeMethods("enableWordPressTracing")
* @BeforeMethods({"enableDatadog", "createDatabase"})
* @AfterMethods("afterMethod")
* @Revs(10)
* @Iterations(10)
Expand All @@ -31,30 +34,20 @@ public static function getAppIndexScript()
return __DIR__ . '/../../Frameworks/WordPress/Version_6_1/index.php';
}

public function disableWordPressTracing()
public function createDatabase(): void
{
$pdo = new \PDO('mysql:host=mysql_integration', 'test', 'test');
$pdo->exec('CREATE DATABASE IF NOT EXISTS wp61');
$pdo->exec(file_get_contents(__DIR__ . '/../../Frameworks/WordPress/Version_6_1/scripts/wp_initdb.sql'));
$this->setUpWebServer([
'DD_TRACE_ENABLED' => 0,
]);
}

public function afterMethod()
{
$this->TearDownAfterClass();
}

public function enableWordPressTracing()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed this so now we ensure the database is created before any test

{
$this->setUpWebServer([
'DD_TRACE_ENABLED' => 1
]);
}

/**
* @BeforeMethods("disableWordPressTracing")
* @BeforeMethods({"disableDatadog", "createDatabase"})
* @AfterMethods("afterMethod")
* @Revs(10)
* @Iterations(10)
Expand Down
5 changes: 5 additions & 0 deletions tests/Benchmarks/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"phpbench/phpbench": "^1.0",
"phpunit/phpunit": "<10",
"symfony/process": "<5"
},
"autoload-dev": {
"psr-4": {
"Benchmarks\\": "./"
}
}
}
Loading
Loading