generated from worksome/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from worksome/memory
feat(memory): JIRA-5517 Peak memory usage per job
- Loading branch information
Showing
7 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Worksome\HorizonTelemetry\Listeners; | ||
|
||
use Illuminate\Queue\Events\JobProcessed; | ||
use OpenTelemetry\API\Metrics\ObserverInterface; | ||
use Worksome\HorizonTelemetry\Enums\MeterName; | ||
use Worksome\HorizonTelemetry\Enums\MeterUnit; | ||
use Worksome\HorizonTelemetry\MeterProvider; | ||
|
||
readonly class ProcessedJobsPeakMemoryUsageListener | ||
{ | ||
public function __construct( | ||
private MeterProvider $meterProvider, | ||
) { | ||
} | ||
|
||
public function __invoke(JobProcessed $event): void | ||
{ | ||
$meter = $this->meterProvider->getMeter(MeterName::ProcessedJobsPeakMemoryUsage); | ||
|
||
$histogram = $meter->createHistogram( | ||
MeterName::ProcessedJobsPeakMemoryUsage->value, | ||
MeterUnit::Bytes->value, | ||
'The memory usage per job', | ||
); | ||
|
||
|
||
$histogram->record( | ||
memory_get_peak_usage(), | ||
[ | ||
'name' => $event->job->resolveName(), | ||
'queue' => $event->job->getQueue(), | ||
] | ||
); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Listeners/ProcessedJobsPeakMemoryUsagePreparationListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Worksome\HorizonTelemetry\Listeners; | ||
|
||
use Illuminate\Queue\Events\JobProcessed; | ||
use OpenTelemetry\API\Metrics\ObserverInterface; | ||
use Worksome\HorizonTelemetry\Enums\MeterName; | ||
use Worksome\HorizonTelemetry\Enums\MeterUnit; | ||
use Worksome\HorizonTelemetry\MeterProvider; | ||
|
||
/** | ||
* Needed for cleaning the peak memory usage variable inside PHP between jobs. | ||
*/ | ||
readonly class ProcessedJobsPeakMemoryUsagePreparationListener | ||
{ | ||
public function __invoke(JobProcessed $event): void | ||
{ | ||
memory_reset_peak_usage(); | ||
} | ||
} |