elastic / elastic/apm-agent-php

Elastic APM PHP Agent slows down PDO calls

Open
#1,147 1 comment 0 reactions 0 assignees View on GitHub
agent-php bug
Dominant language
PHP
Stars
268
Forks
86
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
PDO calls made with the Elastic APM PHP Agent extension installed are much slower than when it is not installed. In my tests, it was about three times slower with the Elastic APM PHP Agent installed.

**To Reproduce**
Steps to reproduce the behavior:
1. Create a new directory.
2. Save the following code to `test.php` inside the new directory:
```php
exec("SELECT 1");
}
```
3. Save the following code to `Dockerfile` inside the directory:
```Dockerfile
FROM --platform=amd64 php:8.1-apache

RUN curl -fsSL https://github.com/elastic/apm-agent-php/releases/download/v1.13.0/apm-agent-php_1.13.0_amd64.deb > /tmp/apm-agent-php.deb \
&& dpkg -i /tmp/apm-agent-php.deb \
&& rm /tmp/apm-agent-php.deb

RUN apt-get update && apt-get install -y \
libpq-dev \
time \
&& rm -rf /var/lib/apt/lists/*

RUN docker-php-ext-configure pdo_pgsql \
&& docker-php-ext-install -j$(nproc) pdo_pgsql

COPY test.php /opt/

CMD ["time", "-p", "php", "/opt/test.php"]
```
4. Save the following code to `docker-compose.yml` inside the directory:
```yaml
services:
php:
build: .
depends_on:
- postgres
environment:
DB_HOST: postgres
DB_NAME: postgres
DB_USER: postgres
DB_PASSWORD: 12345

postgres:
environment:
POSTGRES_PASSWORD: 12345
image: postgres
```
5. Build and run the container image by running the following commands inside the directory:
```shell
docker compose build
docker compose run --rm php
```
6. Comment out the following lines in `Dockerfile`:
```Dockerfile
#RUN curl -fsSL https://github.com/elastic/apm-agent-php/releases/download/v1.13.0/apm-agent-php_1.13.0_amd64.deb > /tmp/apm-agent-php.deb \
# && dpkg -i /tmp/apm-agent-php.deb \
# && rm /tmp/apm-agent-php.deb
```
7. Build and run the container image by running the following commands inside the directory:
```shell
docker compose build
docker compose run --rm php
```
8. Notice that the real execution time is much longer when the Elastic APM PHP Agent is installed.

**Expected behavior**
The Elastic APM PHP Agent should not have such a huge performance impact.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.