Skip to content

Commit

Permalink
Improve benchmarking instructions and dangling memory references
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Apr 10, 2021
1 parent 7aa08f0 commit 84fbe78
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
13 changes: 10 additions & 3 deletions examples/99-server-benchmark-download.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<?php

// A simple HTTP web server that can be used to benchmark requests per second and download speed
//
// $ php examples/99-server-benchmark-download.php 8080
//
// This example runs the web server on a single CPU core in order to measure the
// per core performance.
//
// $ curl http://localhost:8080/10g.bin > /dev/null
// $ wget http://localhost:8080/10g.bin -O /dev/null
// $ ab -n10 -c10 http://localhost:8080/1g.bin
// $ docker run -it --rm --net=host jordi/ab -n100000 -c10 http://localhost:8080/
// $ docker run -it --rm --net=host jordi/ab -n10 -c10 http://localhost:8080/1g.bin
// $ ab -n10 -c10 -k http://localhost:8080/1g.bin
// $ docker run -it --rm --net=host jordi/ab -n100000 -c10 -k http://localhost:8080/
// $ docker run -it --rm --net=host jordi/ab -n10 -c10 -k http://localhost:8080/1g.bin
// $ docker run -it --rm --net=host skandyla/wrk -t8 -c10 -d20 http://localhost:8080/

use Evenement\EventEmitter;
use Psr\Http\Message\ServerRequestInterface;
Expand Down
4 changes: 0 additions & 4 deletions src/Io/RequestHeaderParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ public function handle(ConnectionInterface $conn)
$stream->close();
}
});

$conn->on('close', function () use (&$buffer, &$fn) {
$fn = $buffer = null;
});
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Io/StreamingServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ public function handleResponse(ConnectionInterface $connection, ServerRequestInt
if ($persist) {
$body->pipe($connection, array('end' => false));
$parser = $this->parser;
$body->on('end', function () use ($connection, $parser) {
$body->on('end', function () use ($connection, $parser, $body) {
$connection->removeListener('close', array($body, 'close'));
$parser->handle($connection);
});
} else {
Expand Down
2 changes: 2 additions & 0 deletions tests/Io/StreamingServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3001,7 +3001,9 @@ public function testNewConnectionWillInvokeParserTwiceAfterInvokingRequestHandle
// pretend parser just finished parsing
$server->handleRequest($this->connection, $request);

$this->assertCount(2, $this->connection->listeners('close'));
$body->end();
$this->assertCount(1, $this->connection->listeners('close'));
}

private function createGetRequest()
Expand Down

0 comments on commit 84fbe78

Please sign in to comment.