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

Feat: Compact metrics #198

Merged
merged 6 commits into from
Feb 9, 2024
Merged

Feat: Compact metrics #198

merged 6 commits into from
Feb 9, 2024

Conversation

RikudouSage
Copy link
Collaborator

@RikudouSage RikudouSage commented Feb 7, 2024

Description

Instead of serializing the whole object to cache, a simple (and small) string which can be reconstructed to the metrics bucket object is serialized instead. Should massively lower the size of the metrics in the cache storage.

Fixes #197

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Unit tests

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@RikudouSage
Copy link
Collaborator Author

@vbartusevicius Does this work for you regarding #197?

@RikudouSage
Copy link
Collaborator Author

As another alternative, consider using a different cache adapter for metrics, for example APCu - metrics are non-critical, so if something gets lost because of a restarting process, nothing really important should be lost (or you can implement a procedure where the metrics bucket gets flushed to server in case of shutdown).

By using APCu you would cut the network overhead of Redis and it's not important to have a shared cache for metrics in particular. Alternatively take a look at all the Symfony adapters.

You can use something like this (if you use symfony/cache):

<?php

use Symfony\Component\Cache\Adapter\ApcuAdapter;
use Symfony\Component\Cache\Psr16Cache;
use Unleash\Client\UnleashBuilder;

$unleash = (new UnleashBuilder())
    ->withMetricsCacheHandler(new Psr16Cache(new ApcuAdapter()))
    // your other builder options
    ->build()
;

Copy link
Member

@sighphyre sighphyre left a comment

Choose a reason for hiding this comment

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

LGTM!

Would love to see the data on how much denser this is!

@RikudouSage
Copy link
Collaborator Author

Some quick tests I did today:

=== Toggle amount: 1 ===
Old serialization size: 1,538 bytes
New serialization size: 31 bytes
Saving: 97.98%

=== Toggle amount: 10 ===
Old serialization size: 11,016 bytes
New serialization size: 121 bytes
Saving: 98.90%

=== Toggle amount: 100 ===
Old serialization size: 105,967 bytes
New serialization size: 1,111 bytes
Saving: 98.95%

=== Toggle amount: 1,000 ===
Old serialization size: 1,057,268 bytes
New serialization size: 11,911 bytes
Saving: 98.87%

=== Toggle amount: 10,000 ===
Old serialization size: 10,588,269 bytes
New serialization size: 128,911 bytes
Saving: 98.78%

=== Toggle amount: 100,000 ===
Old serialization size: 106,078,270 bytes
New serialization size: 1,388,911 bytes
Saving: 98.69%

@RikudouSage RikudouSage merged commit f7e20c8 into main Feb 9, 2024
11 checks passed
@RikudouSage RikudouSage deleted the feat/compact-metrics branch February 9, 2024 22:17
@vbartusevicius
Copy link
Contributor

Thanks, @RikudouSage - these size savings are amazing. We are patiently waiting for the release, including this improvement!

@RikudouSage
Copy link
Collaborator Author

@vbartusevicius It was already released a while ago, I just forgot to do the release on GitHub, but composer should have picked up the new version already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Feat: Optimize Metrics cache structure to be resource-friendly on bigger usages
3 participants