Unleash/unleash-client-php

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

Closed this issue · 1 comments

Is there an existing issue for this?

  • I have searched the existing issues

Describe the new feature

Currently, it is unfeasible to enable Feature Metrics for large-scale applications.
Whenever a metric change is triggered, this is what generally happens:

  1. fetch serialized PHP object from the cache
  2. deserialize the object
  3. do some filtering
  4. generally, increment some counter
  5. serialize object
  6. save it to the cache

If we have hundreds of users per second, it gets heavy on the CPU and the network to store metric information if, i.e., Redis is used.
In a real-world application we tried, only the Metric I/O consumes 100Mb/s of network traffic to Redis. This is 10x more than the whole application itself.

To make it more resource-friendly:

  • store plain values to avoid serialization
  • make use of metric keys to avoid the need for PHP objects
  • etc.

Is your feature request related to a problem? (optional)

Unable to use the Metrics feature on more significant projects

Describe alternatives you've considered (optional)

No response

Additional context (optional)

No response

Thanks for the report! I'll be taking a look at what is possible. In the meantime, as a workaround, you can create your own MetricsHandler implementation.