Browse Source

Photon - a D programming language fiber based framework (#10114)

* Add photon-http benchmark source code

* Update readme

* Other files

* Two minor fixes

* s/Stripped/Realistic/

---------

Co-authored-by: Dmitry Olshansky <[email protected]>
Dmitry Olshansky 3 months ago
parent
commit
a9c8fdae48

+ 16 - 0
frameworks/D/photon-http/.gitignore

@@ -0,0 +1,16 @@
+.dub
+docs.json
+__dummy.html
+docs/
+/photon-http
+photon-http.so
+photon-http.dylib
+photon-http.dll
+photon-http.a
+photon-http.lib
+photon-http-test-*
+*.exe
+*.pdb
+*.o
+*.obj
+*.lst

+ 25 - 0
frameworks/D/photon-http/README.md

@@ -0,0 +1,25 @@
+# photon-http benchmark
+
+A benchmark for photon fiber scheduler for D running with minimalistic http server library photon-http.
+
+# photon-http Benchmarking Test
+
+### Test Type Implementation Source Code
+
+* [JSON](./source/app.d)
+* [PLAINTEXT](./source/app.d)
+
+## Important Libraries
+The tests were run with:
+* [photon](https://github.com/DmitryOlshansky/photon)
+* [photon-http][https://github.com/DmitryOlshansky/photon-http]
+
+## Test URLs
+
+### JSON
+
+http://localhost:8080/json
+
+### PLAINTEXT
+
+http://localhost:8080/plaintext

+ 26 - 0
frameworks/D/photon-http/benchmark_config.json

@@ -0,0 +1,26 @@
+{
+  "framework": "photon-http",
+  "tests": [
+    {
+      "default": {
+        "json_url": "/json",
+        "plaintext_url": "/plaintext",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Platform",
+        "database": "None",
+        "framework": "None",
+        "language": "D",
+        "flavor": "None",
+        "orm": "None",
+        "platform": "None",
+        "webserver": "None",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "photon-http",
+        "notes": "",
+        "versus": "None"
+      }
+    }
+  ]
+}

+ 14 - 0
frameworks/D/photon-http/dub.json

@@ -0,0 +1,14 @@
+{
+	"authors": [
+		"Dmitry Olshansky"
+	],
+	"copyright": "Copyright © 2025, Dmitry Olshansky",
+	"dependencies": {
+		"asdf": "~>0.7.17",
+		"photon": "~>0.14.3",
+		"photon-http": "~>0.5.5"
+	},
+	"description": "Benchmark of photon-http",
+	"license": "BSL-1.0",
+	"name": "photon-http-benchmark"
+}

+ 13 - 0
frameworks/D/photon-http/photon-http.dockerfile

@@ -0,0 +1,13 @@
+FROM dlangdockerized/ldc
+
+
+WORKDIR /app
+
+COPY . .
+
+RUN dub build -b release --compiler=ldc2
+
+EXPOSE 8080
+
+CMD ["/app/photon-http-benchmark"]
+

+ 75 - 0
frameworks/D/photon-http/source/app.d

@@ -0,0 +1,75 @@
+import std.stdio;
+import std.socket;
+import std.array;
+
+import asdf.serialization;
+
+import photon, photon.http;
+
+struct Message
+{
+    string message;
+}
+
+class BenchmarkProcessor : HttpProcessor {
+    HttpHeader[] plainText = [HttpHeader("Content-Type", "text/plain; charset=utf-8")];
+    HttpHeader[] json = [HttpHeader("Content-Type", "application/json")];
+    Appender!(char[]) jsonBuf;
+    this(Socket sock) {
+		super(sock);
+		jsonBuf = appender!(char[]);
+	}
+
+    override void handle(HttpRequest req) {
+		if (req.uri == "/plaintext") {
+			respondWith("Hello, world!", 200, plainText);
+		} else if(req.uri == "/json") {
+			jsonBuf.clear();
+			Message("Hello, World!").serializeToJsonPretty!""(jsonBuf);
+			respondWith(jsonBuf.data, 200, json);
+		} else {
+			respondWith("Not found", 404, plainText);
+		}
+    }
+}
+
+void server_worker(Socket client) {
+    scope processor =  new BenchmarkProcessor(client);
+    try {
+        processor.run();
+    }
+    catch(Exception e) {
+        debug stderr.writeln(e);
+    }
+}
+
+void server() {
+    Socket server = new TcpSocket();
+    server.setOption(SocketOptionLevel.SOCKET, SocketOption.REUSEADDR, true);
+    server.bind(new InternetAddress("0.0.0.0", 8080));
+    server.listen(1000);
+
+    debug writeln("Started server");
+
+    void processClient(Socket client) {
+        go(() => server_worker(client));
+    }
+
+    while(true) {
+        try {
+            debug writeln("Waiting for server.accept()");
+            Socket client = server.accept();
+            debug writeln("New client accepted");
+            processClient(client);
+        }
+        catch(Exception e) {
+            writefln("Failure to accept %s", e);
+        }
+    }
+}
+
+void main() {
+    startloop();
+    go(() => server());
+    runFibers();
+}