Remove gc_collect_cycles() and gc_mem_caches() from writeStatisticsToStatusFile() #1096
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title: Remove gc_collect_cycles() and gc_mem_caches() from writeStatisticsToStatusFile()
Description:
🛠️ What does this PR do?
This PR removes the calls to gc_collect_cycles() and gc_mem_caches() in the writeStatisticsToStatusFile() method.
📌 Why is this change needed?
When using pcntl_fork(), PHP relies on the Copy-on-Write (CoW) mechanism to share memory between the master process and worker processes. Calling garbage collection (GC) methods in child processes can cause the following issues:
Increased Memory Usage:
Triggering gc_collect_cycles() or gc_mem_caches() forces PHP to examine and potentially free memory that is shared via CoW. This breaks the shared memory model and results in unnecessary memory duplication, increasing the overall memory footprint.
Performance Degradation:
Frequent garbage collection cycles can negatively impact performance by adding overhead to memory management, especially in high-throughput environments.
Given that PHP's garbage collection works automatically under normal circumstances, explicitly forcing collection is unnecessary and counterproductive in forked environments.
✅ How does this change benefit the project?
Reduced Memory Usage: Prevents unnecessary memory duplication in forked processes.
Improved Performance: Avoids the overhead of unnecessary garbage collection.
Consistency: Aligns with best practices for managing memory in multi-process environments.
🔍 Testing & Compatibility
This change has been tested in a forked process environment and verified to reduce memory bloat without affecting the accuracy of worker statistics.
No breaking changes are introduced with this PR.