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

Elastic APM PHP Agent slows down PDO calls #1147

Open
vanilla-lake opened this issue Apr 2, 2024 · 0 comments
Open

Elastic APM PHP Agent slows down PDO calls #1147

vanilla-lake opened this issue Apr 2, 2024 · 0 comments
Labels
agent-php bug Something isn't working

Comments

@vanilla-lake
Copy link

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

declare(strict_types=1);

$pdo = new PDO(
    "pgsql:host={$_ENV["DB_HOST"]};dbname={$_ENV["DB_NAME"]}",
    $_ENV["DB_USER"],
    $_ENV["DB_PASSWORD"]
);

for ($i = 0; $i < 10000; $i++) {
    $pdo->exec("SELECT 1");
}
  1. Save the following code to Dockerfile inside the directory:
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"]
  1. Save the following code to docker-compose.yml inside the directory:
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
  1. Build and run the container image by running the following commands inside the directory:
docker compose build
docker compose run --rm php
  1. Comment out the following lines in 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
  1. Build and run the container image by running the following commands inside the directory:
docker compose build
docker compose run --rm php
  1. 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.

@vanilla-lake vanilla-lake added the bug Something isn't working label Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-php bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant