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

Improve performance by skipping AccessLogHandler if it writes to /dev/null #248

Merged
merged 2 commits into from
Mar 4, 2024

Conversation

clue
Copy link
Owner

@clue clue commented Mar 4, 2024

This changeset improves performance noticeable by skipping the AccessLogHandler if it writes to /dev/null. This is commonly used when the access log is not needed, such as when running behind a reverse proxy or when benchmarking the raw application performance.

This can be easily reproduced by running a benchmark against any of the examples like this:

$ php public/index.php >/dev/null
$ docker run -it --rm --net=host jordi/ab -n100000 -c100 -k http://localhost:8080/

# old: 22678 requests per second
# new: 29232 requests per second

(Also posted in https://twitter.com/another_clue/status/1764649661749690540)

This builds on top of the recent access log path additions from #247. In particular, this optimization works both when explicitly configured to log to /dev/null or when implicitly logging to console output that is piped to /dev/null.

This is a pure performance optimization that comes with 100% code coverage and does not otherwise affect the public API, so it should be safe to apply. This currently focuses on Unix-based platforms (Linux / Mac) as the main deployment target, but similar optimizations should be possible on Windows (using nul instead of /dev/null).

You're looking at several days worth of work, especially for testing this across multiple platforms. If you enjoy this change and want to help us continue to ship more improvements, consider supporting this project, for example by becoming a sponsor ❤️

Builds on top of #247
Refs #169

@clue clue added the new feature New feature or request label Mar 4, 2024
@clue clue requested a review from SimonFrings March 4, 2024 14:12
Copy link
Collaborator

@SimonFrings SimonFrings left a comment

Choose a reason for hiding this comment

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

Nit: Just noticed two typos in test names

tests/AppTest.php Outdated Show resolved Hide resolved
tests/Io/LogStreamHandlerTest.php Outdated Show resolved Hide resolved
Copy link
Collaborator

@SimonFrings SimonFrings left a comment

Choose a reason for hiding this comment

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

Nice, pull request looks good to me 👍

@SimonFrings SimonFrings merged commit 73cb1cc into clue:main Mar 4, 2024
58 checks passed
@SimonFrings SimonFrings deleted the accesslog-null branch March 4, 2024 18:06
@SimonFrings SimonFrings added this to the v0.16.0 milestone Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants