Skip to content

PHPC-2337: Fix performance regression due to trace logging #1504

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

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Dec 20, 2023

PHPC-2337

Fixes #1501.

This adds a call to mongoc_log_trace_disable() in the extension's MINIT function. Since we always compile with trace-level logging (which is emitted when the mongodb.debug setting is enabled), libmongoc starts out with trace logging enabled. While we disable trace logging in phongo_log_sync_handlers(), this function is not called if mongodb.debug is not set, thus leaving trace logging enabled and causing significant overhead due to message preparation.

Now, trace logging starts out as disabled and will be enabled when phongo_log_sync_handlers() is called, either due to adding a log subscriber to a manager or due to the INI setting being enabled and us storing a file handle the debug log gets written to.

I've confirmed that the performance increases again - a bulk write that took 1.9 seconds without the change now completes in 0.02 seconds. However, due to the difficulty of measuring the performance in CI systems, I did not add the test. We will manually verify the improvements by observing the results of the performance test suite contained in PHPLIB.

@alcaeus alcaeus requested a review from jmikola December 20, 2023 14:51
@alcaeus alcaeus self-assigned this Dec 20, 2023
@@ -177,6 +177,10 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */
* a logger. */
mongoc_log_set_handler(NULL, NULL);

/* Disable trace logging. This will be enabled in phongo_log_sync_handlers()
* if the "mongodb.debug" INI option is set. */
mongoc_log_trace_disable();
Copy link
Member

Choose a reason for hiding this comment

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

I confirmed that MINIT is called before OnUpdateDebug, so this doesn't conflict with tracing enabled via INI files.

@jmikola jmikola merged commit a0d78fc into mongodb:v1.17 Dec 20, 2023
@alcaeus alcaeus deleted the phpc-2337-performance-regression branch December 20, 2023 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants