xp-framework / http

HTTP protocol support for the XP Framework
2 stars 2 forks source link

Connection: keep-alive #22

Open thekid opened 6 years ago

thekid commented 6 years ago

Improves performance of peer.http.SocketHttpTransport by implementing keep-alive semantics.

Performance

Same script as in #21, 100 queries using the Neo4J REST API:

Master Master with keep-alive This branch With keep-alive
0.561 seconds 🔴 (hangs) 0.518 seconds 0.185 seconds

Usage

Users need to pass the keep-alive header explicitely, for example as follows:

index 8aff954..bc132fa 100755
--- a/src/main/php/com/neo4j/HttpProtocol.class.php
+++ b/src/main/php/com/neo4j/HttpProtocol.class.php
@@ -38,6 +38,7 @@ class HttpProtocol extends Protocol {
     $req->setMethod('POST');
     $req->setTarget($this->base.'/transaction/commit');
     $req->setHeader('X-Stream', 'true');
+    $req->setHeader('Connection', 'keep-alive');
     $req->setHeader('Content-Type', 'application/json');
     $req->setParameters(new RequestData(Json::of($payload, $this->json)));
thekid commented 6 years ago

Saw this today in a header enumeration:

"Keep-Alive": "timeout=5, max=99"

https://tools.ietf.org/id/draft-thomson-hybi-http-timeout-01.html#rfc.section.2 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive

Non-standard, but seems to have widespread support; we should consider this in the future.

thekid commented 6 years ago

I think this is ready to get some real-life exposure; this could go into applications as:

"require" : {
  "xp-framework/http": "dev-feature/keep-alive as 9.1.0"
}