Skip to content

Commit

Permalink
Benchmarks (#62)
Browse files Browse the repository at this point in the history
* #benchmark: Add Benchmark for send()

* #benchmark: Add Benchmark for send()
  • Loading branch information
arthurkushman authored Jan 21, 2022
1 parent 46e9295 commit f9b884d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,23 @@ phpunit --bootstrap ./tests/_bootstrap.php ./tests/WebSocketClientTest.php

PHP7 support since version 1.3 - with types, returns and better function implementations.

Benchmarks:


| iter | benchmark | subject | set | revs | mem_peak | time_avg | comp_z_value | comp_deviation |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 0 | MaxConnectionsBench | benchConnect | | 10000 | 1,547,496b | 4.831μs | +1.41σ | +6.35% |
| 1 | MaxConnectionsBench | benchConnect | | 10000 | 1,547,496b | 4.372μs | -0.83σ | -3.76% |
| 2 | MaxConnectionsBench | benchConnect | | 10000 | 1,547,496b | 4.425μs | -0.57σ | -2.59% |


| benchmark | subject | revs | its | mem_peak | mode | rstdev |
| --- | --- | --- | --- | --- | --- | --- |
| MaxConnectionsBench | benchConnect | 10000 | 3 | 1.547mb | 4.427μs | ±4.51% |

As you may have been noticed, average time to send msg is `4.427μs` which is roughly rounded to `4` microseconds
within 10 000 have been sent 3 times in a row.

PS U'll see the processes increase named "php-wss" as CPP (Connections Per-Process) will grow and decrease while stack will lessen.
For instance, if set 100 CPP and there are 128 connections - You will be able to see 2 "php-wss" processes with for ex.: `ps aux | grep php-wss`

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"require-dev": {
"phpunit/phpunit": "^9",
"monolog/monolog": "^1.24",
"phpstan/phpstan": "^1.4"
"phpstan/phpstan": "^1.4",
"phpbench/phpbench": "^1.2"
}
}
39 changes: 39 additions & 0 deletions tests/Benchmark/MaxConnectionsBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace WSSCTEST\Benchmark;

require_once __DIR__ . '/../../vendor/autoload.php';

use Exception;
use WSSC\Components\ClientConfig;
use WSSC\WebSocketClient;

class MaxConnectionsBench
{
private const WS_SCHEME = 'ws://';
private const WS_HOST = 'localhost';
private const WS_PORT = ':8000';
private const WS_URI = '/notifications/messanger/vkjsndfvjn23243';

private string $url = self::WS_SCHEME . self::WS_HOST . self::WS_PORT . self::WS_URI;
private WebSocketClient $client;

/**
* @throws \WSSC\Exceptions\BadUriException
* @throws \WSSC\Exceptions\ConnectionException
*/
public function __construct()
{
$this->client = new WebSocketClient($this->url, new ClientConfig());
}

/**
* @Revs(10000)
* @Iterations(3)
* @throws Exception
*/
public function benchConnect(): void
{
$this->client->send('{"user_id" : 123}');
}
}
2 changes: 1 addition & 1 deletion tests/WebSocketClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class WebSocketClientTest extends TestCase
private const WS_PORT = ':8000';
private const WS_URI = '/notifications/messanger/vkjsndfvjn23243';

private $url;
private string $url = self::WS_SCHEME . self::WS_HOST . self::WS_PORT . self::WS_URI;

public function setUp(): void
{
Expand Down

0 comments on commit f9b884d

Please sign in to comment.