Skip to content

Commit

Permalink
Remaining relay cached commands (#99)
Browse files Browse the repository at this point in the history
* Add SUNION, SDIFF, and SINTERCARD benchmarks.

* Add LINDEX benchmark and minor LRANGE refactor.
  • Loading branch information
michael-grunder authored Jul 20, 2023
1 parent ad6b142 commit 9b2086f
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 62 deletions.
48 changes: 48 additions & 0 deletions benchmarks/Cases/BenchmarkLindex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace CacheWerk\Relay\Benchmarks\Cases;

use CacheWerk\Relay\Benchmarks\Support\Benchmark;

class BenchmarkLINDEX extends Benchmark
{
/**
* @var array<int, string>
*/
protected array $keys;

public static function flags(): int
{
return self::LIST | self::READ;
}

public function setUp(): void
{
$this->flush();
$this->setUpClients();
$this->seed();
}

public function seed(): void
{
$this->keys = $this->seedSimpleKeys();
}

public function warmup(int $times, string $method): void {
if ($times == 0) {
return;
}

parent::warmup($times, $method);
$this->readSimpleKeys($this->keys);
}

protected function runBenchmark($client): int
{
foreach ($this->keys as $i => $key) {
$client->lindex($key, $i % 32);
}

return count($this->keys);
}
}
7 changes: 1 addition & 6 deletions benchmarks/Cases/BenchmarkLrange.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ public function setUp(): void

public function seed(): void
{
$redis = $this->createPredis();

foreach ($this->loadJsonFile('meteorites.json') as $item) {
$redis->rpush((string) $item['id'], $this->flattenArray($item));
$this->keys[] = $item['id'];
}
$this->keys = $this->seedSimpleKeys();
}

protected function runBenchmark($client): int
Expand Down
10 changes: 10 additions & 0 deletions benchmarks/Cases/BenchmarkSdiff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace CacheWerk\Relay\Benchmarks\Cases;

use CacheWerk\Relay\Benchmarks\Support\BenchmarkMultiSetCommand;

class BenchmarkSDIFF extends BenchmarkMultiSetCommand
{
//
}
59 changes: 3 additions & 56 deletions benchmarks/Cases/BenchmarkSinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,9 @@

namespace CacheWerk\Relay\Benchmarks\Cases;

use CacheWerk\Relay\Benchmarks\Support\Benchmark;
use CacheWerk\Relay\Benchmarks\Support\BenchmarkMultiSetCommand;

class BenchmarkSINTER extends Benchmark
class BenchmarkSINTER extends BenchmarkMultiSetCommand
{
const KeysPerCall = 8;

/**
* @var array<int, array<int, string>>
*/
protected array $keyChunks;

public static function flags(): int
{
return self::SET | self::READ;
}

public function setUp(): void
{
$this->flush();
$this->setUpClients();
$this->seed();
}

public function warmup(int $times, string $method): void
{
if ($times == 0) {
return;
}

parent::warmup($times, $method);

foreach ($this->keyChunks as $chunk) {
$this->readSimpleKeys($chunk);
}
}

public function seed(): void
{
$keys = [];

$redis = $this->createPredis();

foreach ($this->loadJsonFile('meteorites.json') as $item) {
$redis->sadd((string) $item['id'], array_keys($this->flattenArray($item)));
$keys[] = $item['id'];
}

$this->keyChunks = array_chunk($keys, self::KeysPerCall);
}

protected function runBenchmark($client): int
{
foreach ($this->keyChunks as $chunk) {
$client->sinter($chunk);
}

return count($this->keyChunks);
}
//
}
10 changes: 10 additions & 0 deletions benchmarks/Cases/BenchmarkSintercard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace CacheWerk\Relay\Benchmarks\Cases;

use CacheWerk\Relay\Benchmarks\Support\BenchmarkMultiSetCommand;

class BenchmarkSINTERCARD extends BenchmarkMultiSetCommand
{
//
}
10 changes: 10 additions & 0 deletions benchmarks/Cases/BenchmarkSunion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace CacheWerk\Relay\Benchmarks\Cases;

use CacheWerk\Relay\Benchmarks\Support\BenchmarkMultiSetCommand;

class BenchmarkSUNION extends BenchmarkMultiSetCommand
{
//
}
56 changes: 56 additions & 0 deletions benchmarks/Support/BenchmarkMultiSetCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace CacheWerk\Relay\Benchmarks\Support;

use CacheWerk\Relay\Benchmarks\Support\Benchmark;

class BenchmarkMultiSetCommand extends Benchmark
{
const KeysPerCall = 8;

/**
* @var array<int, array<int, string>>
*/
protected array $keyChunks;

public static function flags(): int
{
return self::SET | self::READ;
}

public function setUp(): void
{
$this->flush();
$this->setUpClients();
$this->seed();
}

public function warmup(int $times, string $method): void
{
if ($times == 0) {
return;
}

parent::warmup($times, $method);

foreach ($this->keyChunks as $chunk) {
$this->readSimpleKeys($chunk);
}
}

public function seed(): void
{
$this->keyChunks = array_chunk($this->seedSimpleKeys(), self::KeysPerCall);
}

protected function runBenchmark($client): int
{
$cmd = $this->command();

foreach ($this->keyChunks as $chunk) {
$client->$cmd($chunk);
}

return count($this->keyChunks);
}
}

0 comments on commit 9b2086f

Please sign in to comment.