Browse Source

Add Nginx Njs (#7780)

* Add Nginx Njs
To check overhead

* Format js

* Unify and format nginx.conf
Joan Miquel 2 years ago
parent
commit
ecc0e25c46

+ 19 - 0
frameworks/C/nginx/benchmark_config.json

@@ -19,6 +19,25 @@
         "display_name": "Nginx",
         "display_name": "Nginx",
         "notes": "",
         "notes": "",
         "versus": ""
         "versus": ""
+      },
+      "njs": {
+        "plaintext_url": "/plaintext",
+        "json_url": "/json",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Platform",
+        "framework": "None",
+        "language": "C",
+        "flavor": "Njs",
+        "orm": "Raw",
+        "platform": "None",
+        "database": "none",
+        "webserver": "nginx",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "Nginx-njs",
+        "notes": "",
+        "versus": "nginx"
       }
       }
     }
     }
   ]
   ]

+ 7 - 0
frameworks/C/nginx/nginx-njs.dockerfile

@@ -0,0 +1,7 @@
+FROM nginx:mainline
+
+ADD ./ ./
+
+EXPOSE 8080
+
+CMD ["nginx", "-c", "/njs/nginx.conf"]

+ 6 - 6
frameworks/C/nginx/nginx.conf

@@ -1,5 +1,5 @@
 user www-data;
 user www-data;
-worker_processes  auto;
+worker_processes auto;
 worker_cpu_affinity auto;
 worker_cpu_affinity auto;
 error_log stderr error;
 error_log stderr error;
 #worker_rlimit_nofile 1024000;
 #worker_rlimit_nofile 1024000;
@@ -8,11 +8,11 @@ daemon off;
 
 
 events {
 events {
     worker_connections 32768;
     worker_connections 32768;
-	multi_accept off; #default
+    multi_accept off; #default
 }
 }
 
 
 http {
 http {
-    include       /etc/nginx/mime.types;
+    include /etc/nginx/mime.types;
     access_log off;
     access_log off;
     server_tokens off;
     server_tokens off;
     msie_padding off;
     msie_padding off;
@@ -25,10 +25,10 @@ http {
     keepalive_requests 300000; #default 100
     keepalive_requests 300000; #default 100
 
 
     server {
     server {
-        listen      8080 default_server reuseport deferred fastopen=4096;
-                    #8080 default_server reuseport deferred backlog=65535 fastopen=4096;
+        listen 8080 default_server reuseport deferred fastopen=4096;
+        #8080 default_server reuseport deferred backlog=65535 fastopen=4096;
         root /;
         root /;
-        
+
         location = /plaintext {
         location = /plaintext {
             default_type text/plain;
             default_type text/plain;
             return 200 "Hello, World!";
             return 200 "Hello, World!";

+ 2 - 7
frameworks/C/nginx/nginx.dockerfile

@@ -1,12 +1,7 @@
-FROM ubuntu:22.04
-
-ARG DEBIAN_FRONTEND=noninteractive
-
-RUN apt-get update -yqq
-RUN apt-get install -y nginx-light
+FROM nginx:mainline
 
 
 ADD ./ ./
 ADD ./ ./
 
 
 EXPOSE 8080
 EXPOSE 8080
 
 
-CMD nginx -c /nginx.conf
+CMD ["nginx", "-c", "/nginx.conf"]

+ 11 - 0
frameworks/C/nginx/njs/hello.js

@@ -0,0 +1,11 @@
+function hello(r) {
+  r.headersOut["Content-Type"] = "text/plain; charset=UTF-8";
+  r.return(200, "Hello, World!");
+}
+
+function json(r) {
+  r.headersOut["Content-Type"] = "application/json";
+  r.return(200, JSON.stringify({ message: "Hello, World!" }));
+}
+
+export default { hello, json };

+ 49 - 0
frameworks/C/nginx/njs/nginx.conf

@@ -0,0 +1,49 @@
+worker_processes auto;
+worker_cpu_affinity auto;
+error_log stderr error;
+#worker_rlimit_nofile 1024000;
+timer_resolution 1s;
+daemon off;
+
+load_module modules/ngx_http_js_module.so;
+
+events {
+   worker_connections 32768;
+   multi_accept off; #default
+}
+
+http {
+   include /etc/nginx/mime.types;
+   access_log off;
+   server_tokens off;
+   msie_padding off;
+
+   sendfile off; #default
+   tcp_nopush off; #default
+   tcp_nodelay on; #default
+   keepalive_timeout 65;
+   keepalive_disable none; #default msie6
+   keepalive_requests 300000; #default 100
+
+   js_path "/etc/nginx/njs/";
+
+   #js_import utils.js;
+   js_import main from /njs/hello.js;
+
+   server {
+      listen 8080 default_server reuseport deferred fastopen=4096;
+      #8080 default_server reuseport deferred backlog=65535 fastopen=4096;
+
+      location = /plaintext {
+         js_content main.hello;
+      }
+
+      location = /json {
+         js_content main.json;
+      }
+
+      #location = /version {
+      #   js_content utils.version;
+      #}
+   }
+}