QpsSampler
class QpsSampler implements SamplerInterface
This implementation of the SamplerInterface uses a cache to limit sampling to the a certain number of queries per second. It requires a PSR-6 cache implementation.
Example using cache/memcached-adapter:
// This example uses the Memcached extension and requires the
// cache/memcached-adapter composer package
use OpenCensus\Trace\Sampler\QpsSampler;
use Cache\Adapter\Memcached\MemcachedCachePool;
use Cache\Adapter\Common\PhpCacheItem;
$client = new \Memcached();
$client->addServer('localhost', 11211);
$cache = new Memcached\MemcachedCachePool($client);
$sampler = new QpsSampler($cache, [
'cacheItemClass' => PhpCacheItem::class
]);
You can find a list of PSR-6 cache implementations here.
Constants
DEFAULT_CACHE_KEY |
|
DEFAULT_QPS_RATE |
|
Methods
Create a new QpsSampler. If the provided cache is shared between servers, the queries per second will be counted across servers. If the cache is shared between servers and you wish to sample independently on the servers, provide your own cache key that is different on each server.
Returns whether or not the request should be sampled.
Return the query-per-second rate
Details
at line 91
__construct(CacheItemPoolInterface $cache = null, array $options = [])
Create a new QpsSampler. If the provided cache is shared between servers, the queries per second will be counted across servers. If the cache is shared between servers and you wish to sample independently on the servers, provide your own cache key that is different on each server.
There may be race conditions between simultaneous requests where they may both (all) be sampled.
at line 121
bool
shouldSample()
Returns whether or not the request should be sampled.
at line 161
float
rate()
Return the query-per-second rate