-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
615 lines (483 loc) · 29.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<title>Trusterd - HTTP/2 Web Server scripting with mruby by trusterd</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="stylesheets/normalize.css" media="screen">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/github-light.css" media="screen">
</head>
<body>
<section class="page-header">
<h1 class="project-name">Trusterd - HTTP/2 Web Server scripting with mruby</h1>
<h2 class="project-tagline"></h2>
<a href="https://github.com/trusterd/trusterd" class="btn">View on GitHub</a>
<a href="https://github.com/trusterd/trusterd/zipball/master" class="btn">Download .zip</a>
<a href="https://github.com/trusterd/trusterd/tarball/master" class="btn">Download .tar.gz</a>
</section>
<section class="main-content">
<p><img src="https://raw.githubusercontent.com/trusterd/trusterd/master/images/logo_full_white.png" alt="logo"></p>
<blockquote>
<p>Special thanks to <a href="https://github.com/maybehelpy" class="user-mention">@maybehelpy</a> for creating trusterd logo!!</p>
</blockquote>
<h1>
<a id="trusterd-http2-web-server" class="anchor" href="#trusterd-http2-web-server" aria-hidden="true"><span class="octicon octicon-link"></span></a>Trusterd HTTP/2 Web Server</h1>
<p><a href="https://gitter.im/trusterd/trusterd?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"><img src="https://badges.gitter.im/Join%20Chat.svg" alt="Gitter"></a>
<a href="https://travis-ci.org/trusterd/trusterd"><img src="https://travis-ci.org/trusterd/trusterd.svg?branch=master" alt="Build Status"></a>
<a href="https://app.wercker.com/project/bykey/d389a8a05b263e469d51f40d532af04f"><img src="https://app.wercker.com/status/d389a8a05b263e469d51f40d532af04f/s" alt="wercker status" title="wercker status"></a></p>
<p><a href="https://github.com/trusterd/trusterd">Trusterd</a> is a high performance HTTP/2 Web Server scripting with <a href="https://github.com/mruby/mruby">mruby</a> using <a href="https://github.com/tatsuhiro-t/nghttp2">nghttp2</a> and <a href="https://github.com/trusterd/mruby-http2">mruby-http2</a>. You can get HTTP/2 Web Server quickly which is high performance and customizable with mruby. The HTTP/2 server and client function are pluggable. So, <a href="https://github.com/trusterd/trusterd/blob/master/README.md#embed-into-your-c-application">you can embed these functions into your C applications</a>.</p>
<h2>
<a id="todo" class="anchor" href="#todo" aria-hidden="true"><span class="octicon octicon-link"></span></a>TODO</h2>
<p>This is a very early version, please test and report errors. Wellcome pull-request.</p>
<ul>
<li>Server Push</li>
</ul>
<h2>
<a id="requirements" class="anchor" href="#requirements" aria-hidden="true"><span class="octicon octicon-link"></span></a>Requirements</h2>
<ul>
<li><a href="https://github.com/tatsuhiro-t/nghttp2#requirements">nghttp2 Requirements</a></li>
<li><a href="https://github.com/trusterd/mruby-http2/blob/master/mrbgem.rake#L6">mruby-http2 Requirements</a></li>
<li>Trusterd Requirements
<ul>
<li>libjemalloc-dev</li>
<li><a href="https://github.com/h2o/qrintf">qrintf-gcc</a></li>
<li>If you don't have jemalloc and qrintf-gcc, comment out these lines on <a href="https://github.com/trusterd/trusterd/blob/master/build_config.rb#L34-L62">build_config.rb</a>
</li>
</ul>
</li>
<li>If you use prefork mode, linux kernel need to support <code>SO_REUSEPORT</code>.</li>
</ul>
<p>After reading <a href="https://github.com/trusterd/trusterd/blob/master/.travis.yml">.travis.yml</a>, you might easy to understand the install</p>
<h2>
<a id="quick-install" class="anchor" href="#quick-install" aria-hidden="true"><span class="octicon octicon-link"></span></a>Quick install</h2>
<h3>
<a id="manual-build" class="anchor" href="#manual-build" aria-hidden="true"><span class="octicon octicon-link"></span></a>Manual Build</h3>
<h4>
<a id="1-install-qrintf-optional-but-recommended" class="anchor" href="#1-install-qrintf-optional-but-recommended" aria-hidden="true"><span class="octicon octicon-link"></span></a>1. Install qrintf (Optional, but recommended)</h4>
<p>Please see <a href="https://github.com/h2o/qrintf">qrintf-gcc</a></p>
<p>or commet out this line in <code>build_config.rb</code></p>
<pre><code>cc.command = ENV['CC'] || 'qrintf-gcc'
</code></pre>
<h4>
<a id="2-install-jemalloc-optional-but-recommended" class="anchor" href="#2-install-jemalloc-optional-but-recommended" aria-hidden="true"><span class="octicon octicon-link"></span></a>2. Install jemalloc (Optional, but recommended)</h4>
<h5>
<a id="ubuntu" class="anchor" href="#ubuntu" aria-hidden="true"><span class="octicon octicon-link"></span></a>Ubuntu</h5>
<pre><code>sudo apt-get install libjemalloc-dev
</code></pre>
<p>or comment out this line in <code>build_config.rb</code></p>
<pre><code>linker.flags_after_libraries << '-ljemalloc'
</code></pre>
<h4>
<a id="3-download-trusterd" class="anchor" href="#3-download-trusterd" aria-hidden="true"><span class="octicon octicon-link"></span></a>3. Download trusterd</h4>
<pre><code>git clone https://github.com/trusterd/trusterd.git
cd trusterd
</code></pre>
<h4>
<a id="4-build-trusterd" class="anchor" href="#4-build-trusterd" aria-hidden="true"><span class="octicon octicon-link"></span></a>4. Build trusterd</h4>
<div class="highlight highlight-bash"><pre>make</pre></div>
<h4>
<a id="5-install" class="anchor" href="#5-install" aria-hidden="true"><span class="octicon octicon-link"></span></a>5. Install</h4>
<div class="highlight highlight-bash"><pre>make install INSTALL_PREFIX=/usr/local/trusterd</pre></div>
<h4>
<a id="6-write-config-install_prefixconftrusterdconfrb" class="anchor" href="#6-write-config-install_prefixconftrusterdconfrb" aria-hidden="true"><span class="octicon octicon-link"></span></a>6. Write config <code>$(INSTALL_PREFIX)/conf/trusterd.conf.rb</code>
</h4>
<div class="highlight highlight-ruby"><pre><span class="pl-c1">SERVER_NAME</span> <span class="pl-k">=</span> <span class="pl-s"><span class="pl-pds">"</span>Trusterd<span class="pl-pds">"</span></span>
<span class="pl-c1">SERVER_VERSION</span> <span class="pl-k">=</span> <span class="pl-s"><span class="pl-pds">"</span>0.0.1<span class="pl-pds">"</span></span>
<span class="pl-c1">SERVER_DESCRIPTION</span> <span class="pl-k">=</span> <span class="pl-s"><span class="pl-pds">"</span><span class="pl-pse">#{</span><span class="pl-s1"><span class="pl-c1">SERVER_NAME</span></span><span class="pl-pse"><span class="pl-s1">}</span></span>/<span class="pl-pse">#{</span><span class="pl-s1"><span class="pl-c1">SERVER_VERSION</span></span><span class="pl-pse"><span class="pl-s1">}</span></span><span class="pl-pds">"</span></span>
root_dir <span class="pl-k">=</span> <span class="pl-s"><span class="pl-pds">"</span>/usr/local/trusterd<span class="pl-pds">"</span></span>
s <span class="pl-k">=</span> <span class="pl-c1">HTTP2</span>::<span class="pl-c1">Server</span>.<span class="pl-k">new</span>({
<span class="pl-c">#</span>
<span class="pl-c"># required config</span>
<span class="pl-c">#</span>
<span class="pl-c1">:port</span> => <span class="pl-c1">8080</span>,
<span class="pl-c1">:document_root</span> => <span class="pl-s"><span class="pl-pds">"</span><span class="pl-pse">#{</span><span class="pl-s1">root_dir</span><span class="pl-pse"><span class="pl-s1">}</span></span>/htdocs<span class="pl-pds">"</span></span>,
<span class="pl-c1">:server_name</span> => <span class="pl-c1">SERVER_DESCRIPTION</span>,
<span class="pl-c"># support prefork only when linux kernel supports SO_REUSEPORT</span>
<span class="pl-c"># :worker => 4,</span>
<span class="pl-c"># detect cpu thread automatically</span>
<span class="pl-c"># If don't support SO_REUSEPORT of Linux, the number of worker is 0</span>
<span class="pl-c1">:worker</span> => <span class="pl-s"><span class="pl-pds">"</span>auto<span class="pl-pds">"</span></span>,
<span class="pl-c"># required when tls option is true.</span>
<span class="pl-c"># tls option is true by default.</span>
<span class="pl-c">#:key => "#{root_dir}/ssl/server.key",</span>
<span class="pl-c">#:crt => "#{root_dir}/ssl/server.crt",</span>
<span class="pl-c">#:dh_params_file => "#{root_dir}/ssl/dh.pem",</span>
<span class="pl-c"># listen ip address</span>
<span class="pl-c"># default value is 0.0.0.0</span>
<span class="pl-c"># :server_host => "127.0.0.1",</span>
<span class="pl-c">#</span>
<span class="pl-c"># optional config</span>
<span class="pl-c">#</span>
<span class="pl-c"># debug default: false</span>
<span class="pl-c"># :debug => true,</span>
<span class="pl-c"># tls default: true</span>
<span class="pl-c1">:tls</span> => <span class="pl-c1">false</span>,
<span class="pl-c"># damone default: false</span>
<span class="pl-c"># :daemon => true,</span>
<span class="pl-c"># callback default: false</span>
<span class="pl-c"># :callback => true,</span>
<span class="pl-c"># connection_record defualt: true</span>
<span class="pl-c"># :connection_record => false,</span>
<span class="pl-c"># runngin user, start server with root and change to run_user</span>
<span class="pl-c"># :run_user => "daemon",</span>
<span class="pl-c"># Tuning RLIMIT_NOFILE, start server with root and must set run_user instead of root</span>
<span class="pl-c"># :rlimit_nofile => 65535,</span>
<span class="pl-c"># Set TCP_NOPUSH (TCP_CORK) option</span>
<span class="pl-c"># :tcp_nopush => true,</span>
<span class="pl-c"># expand buffer size before writing packet. decreace the number of small packets. That may be usefull for TLS session</span>
<span class="pl-c"># :write_packet_buffer_expand_size => 4096 * 4,</span>
<span class="pl-c"># limit buffer size before writing packet. write packet beyond the value. That may be usefull for TLS session</span>
<span class="pl-c"># :write_packet_buffer_limit_size => 4096,</span>
<span class="pl-c"># measuring server status: default false</span>
<span class="pl-c"># :server_status => true,</span>
<span class="pl-c"># use reverse proxy methods: default false</span>
<span class="pl-c"># :upstream => true,</span>
})
<span class="pl-c">#</span>
<span class="pl-c"># when :callback option is true,</span>
<span class="pl-c">#</span>
<span class="pl-c"># # custom request headers</span>
<span class="pl-c"># # getter</span>
<span class="pl-c"># s.r.headers_in[":method"] #=> GET</span>
<span class="pl-c"># s.r.request_headers[":method"] #=> GET</span>
<span class="pl-c">#</span>
<span class="pl-c"># # custom response headers</span>
<span class="pl-c"># # setter</span>
<span class="pl-c"># s.r.headers_out["hoge"] = fuga</span>
<span class="pl-c"># s.r.response_headers["hoge"] = fuga</span>
<span class="pl-c">#</span>
<span class="pl-c"># # getter</span>
<span class="pl-c"># s.r.headers_out["hoge] #=> fuga</span>
<span class="pl-c"># s.r.response_headers["hoge] #=> fuga</span>
<span class="pl-c">#</span>
<span class="pl-c">#</span>
<span class="pl-c"># s.set_map_to_storage_cb {</span>
<span class="pl-c">#</span>
<span class="pl-c"># p "callback bloack at set_map_to_storage_cb"</span>
<span class="pl-c"># p s.filename #=> /path/to/index.html</span>
<span class="pl-c"># p s.uri #=> /index.html</span>
<span class="pl-c"># p s.unparsed_uri #=> /index.html?a=1&b=2</span>
<span class="pl-c"># p s.percent_encode_uri #=> /index.html?id=%E3%83%9F%E3</span>
<span class="pl-c"># p s.args #=> ?a=1&b=2</span>
<span class="pl-c"># p s.body #=> "post data"</span>
<span class="pl-c"># p s.method #=> "GET"</span>
<span class="pl-c"># p s.scheme #=> "https"</span>
<span class="pl-c"># p s.authority #=> "matsumoto-r.jp"</span>
<span class="pl-c"># p s.host #=> "matsumoto-r.jp"</span>
<span class="pl-c"># p s.hostname #=> "matsumoto-r.jp"</span>
<span class="pl-c"># p s.client_ip #=> "192.168.12.5"</span>
<span class="pl-c"># p s.document_root #=> "/path/to/htdocs"</span>
<span class="pl-c"># p s.user_agent #=> "trusterd_client"</span>
<span class="pl-c">#</span>
<span class="pl-c"># p "if :server_status is true, use server status method"</span>
<span class="pl-c"># p "the number of total requesting stream #{s.total_stream_request}"</span>
<span class="pl-c"># p "the number of total requesting session #{s.total_session_request}"</span>
<span class="pl-c"># p "the number of current connected sessions #{s.connected_sessions}"</span>
<span class="pl-c"># p "the number of current processing streams #{s.active_stream}"</span>
<span class="pl-c">#</span>
<span class="pl-c"># # location setting</span>
<span class="pl-c"># if s.request.uri == "/index.html"</span>
<span class="pl-c"># s.request.filename = "#{root_dir}/htdocs/hoge"</span>
<span class="pl-c"># end</span>
<span class="pl-c"># p s.request.filename</span>
<span class="pl-c">#</span>
<span class="pl-c"># # you can use regexp if you link regexp mrbgem.</span>
<span class="pl-c"># # Or, you can use KVS like mruby-redis or mruby-</span>
<span class="pl-c"># # vedis and so on.</span>
<span class="pl-c">#</span>
<span class="pl-c"># # reverse proxy config</span>
<span class="pl-c"># # reciev front end with HTTP/2 and proxy upstream server with HTTP/1.x</span>
<span class="pl-c"># # TODO: don't support connection with TLS to upstream server</span>
<span class="pl-c"># #</span>
<span class="pl-c"># # need :upstream => true</span>
<span class="pl-c">#</span>
<span class="pl-c"># if s.request.uri =~ /^/$/</span>
<span class="pl-c"># # upstream request uri default: /</span>
<span class="pl-c"># s.upstream_uri = s.percent_encode_uri</span>
<span class="pl-c"># s.upstream_host = "127.0.0.1"</span>
<span class="pl-c">#</span>
<span class="pl-c"># # upstream port default: 80</span>
<span class="pl-c"># #s.upstream_port = 8080</span>
<span class="pl-c">#</span>
<span class="pl-c"># # upstream connection timeout default: 600 sec</span>
<span class="pl-c"># #s.upstream_timeout = 100</span>
<span class="pl-c">#</span>
<span class="pl-c"># # use keepalive deault: true</span>
<span class="pl-c"># #s.upstream_keepalive = false</span>
<span class="pl-c">#</span>
<span class="pl-c"># # use HTTP/1.0 protocol default: HTTP/1.1</span>
<span class="pl-c"># #s.upstream_proto_major = 1</span>
<span class="pl-c"># #s.upstream_proto_minor = 0</span>
<span class="pl-c"># end</span>
<span class="pl-c">#</span>
<span class="pl-c"># # dynamic content with mruby</span>
<span class="pl-c"># if s.request.filename =~ /^.*\.rb$/</span>
<span class="pl-c"># s.enable_mruby</span>
<span class="pl-c"># end</span>
<span class="pl-c">#</span>
<span class="pl-c"># # dynamic content with mruby sharing mrb_state</span>
<span class="pl-c"># if s.request.filename =~ /^.*\_shared.rb$/</span>
<span class="pl-c"># s.enable_shared_mruby</span>
<span class="pl-c"># end</span>
<span class="pl-c">#</span>
<span class="pl-c"># if s.request.uri =~ /hellocb/</span>
<span class="pl-c"># s.set_content_cb {</span>
<span class="pl-c"># s.rputs "hello trusterd world from cb"</span>
<span class="pl-c"># s.echo "+ hello trusterd world from cb with \n"</span>
<span class="pl-c"># }</span>
<span class="pl-c"># end</span>
<span class="pl-c">#</span>
<span class="pl-c"># }</span>
<span class="pl-c"># extend response just before send response</span>
<span class="pl-c"># s.set_fixups_cb {</span>
<span class="pl-c"># s.r.response_headers["server"] = "other server"</span>
<span class="pl-c">#}</span>
<span class="pl-c"># #If define set_content_cb this scope, callback only once</span>
<span class="pl-c"># s.set_content_cb {</span>
<span class="pl-c"># s.rputs "hello trusterd world from cb"</span>
<span class="pl-c"># s.echo "+ hello trusterd world from cb with \n"</span>
<span class="pl-c"># }</span>
<span class="pl-c">#</span>
<span class="pl-c"># f = File.open "#{root_dir}/logs/access.log", "a"</span>
<span class="pl-c">#</span>
<span class="pl-c"># s.set_logging_cb {</span>
<span class="pl-c">#</span>
<span class="pl-c"># p "callback block after send response"</span>
<span class="pl-c">#</span>
<span class="pl-c"># f.write "client_ip:'#{s.conn.client_ip}' date:'#{s.r.date}' status:#{s.r.status} content_length:#{s.r.content_length} uri:'#{s.r.uri}' filename:'#{s.r.filename}' user_agent:'#{s.r.user_agent}'\n"</span>
<span class="pl-c">#</span>
<span class="pl-c"># }</span>
<span class="pl-c">#</span>
<span class="pl-c"># or use access logging methods</span>
<span class="pl-c">#s.setup_access_log({</span>
<span class="pl-c"># :file => "/usr/local/trusterd/logs/access.log",</span>
<span class="pl-c">#</span>
<span class="pl-c"># # :default or :custom</span>
<span class="pl-c"># # if using :custom, set logging format to write_access_log mehtod arg</span>
<span class="pl-c"># # s.write_access_log "client_ip: #{s.client_ip}"</span>
<span class="pl-c"># :format => :default,</span>
<span class="pl-c">#</span>
<span class="pl-c"># # :plain or :json if using :default</span>
<span class="pl-c"># :type => :plain,</span>
<span class="pl-c">#})</span>
<span class="pl-c">#</span>
<span class="pl-c">#s.set_logging_cb {</span>
<span class="pl-c"># s.write_access_log</span>
<span class="pl-c">#}</span>
<span class="pl-c">#</span>
s.run</pre></div>
<h4>
<a id="7-run-trusterd" class="anchor" href="#7-run-trusterd" aria-hidden="true"><span class="octicon octicon-link"></span></a>7. Run trusterd</h4>
<div class="highlight highlight-bash"><pre>make start INSTALL_PREFIX=/usr/local/trusterd</pre></div>
<p>or</p>
<div class="highlight highlight-bash"><pre><span class="pl-s"><span class="pl-pds">$(</span>INSTALL_PREFIX<span class="pl-pds">)</span></span>/bin/trusterd <span class="pl-s"><span class="pl-pds">$(</span>INSTALL_PREFIX<span class="pl-pds">)</span></span>/conf/trusterd.conf.rb</pre></div>
<h4>
<a id="8-check-by-nghttp" class="anchor" href="#8-check-by-nghttp" aria-hidden="true"><span class="octicon octicon-link"></span></a>8. Check by nghttp</h4>
<p><a href="https://github.com/tatsuhiro-t/nghttp2#nghttp---client">nghttp</a> is a client tool for HTTP/2.</p>
<pre><code>$ ${GIT_CLONE_DIR}/mruby/build/host/mrbgems/mruby-http2/nghttp2/src/nghttp -v http://127.0.0.1:8080/index.html
hello trusterd world.
</code></pre>
<h4>
<a id="clean" class="anchor" href="#clean" aria-hidden="true"><span class="octicon octicon-link"></span></a>Clean</h4>
<pre><code>make clean
</code></pre>
<hr>
<h3>
<a id="using-docker" class="anchor" href="#using-docker" aria-hidden="true"><span class="octicon octicon-link"></span></a>Using Docker</h3>
<h4>
<a id="using-docker-image" class="anchor" href="#using-docker-image" aria-hidden="true"><span class="octicon octicon-link"></span></a>Using Docker image</h4>
<h5>
<a id="pulling" class="anchor" href="#pulling" aria-hidden="true"><span class="octicon octicon-link"></span></a>Pulling</h5>
<pre><code>docker pull matsumotory/trusterd
</code></pre>
<h5>
<a id="running" class="anchor" href="#running" aria-hidden="true"><span class="octicon octicon-link"></span></a>Running</h5>
<pre><code>docker run -d -p 8080:8080 matsumotory/trusterd
</code></pre>
<h5>
<a id="access" class="anchor" href="#access" aria-hidden="true"><span class="octicon octicon-link"></span></a>Access</h5>
<pre><code>nghttp -v http://127.0.0.1:8080/index.html
</code></pre>
<h4>
<a id="docker-image-build" class="anchor" href="#docker-image-build" aria-hidden="true"><span class="octicon octicon-link"></span></a>Docker Image Build</h4>
<h5>
<a id="building" class="anchor" href="#building" aria-hidden="true"><span class="octicon octicon-link"></span></a>Building</h5>
<pre><code>docker build -t local/trusterd .
</code></pre>
<h5>
<a id="runing" class="anchor" href="#runing" aria-hidden="true"><span class="octicon octicon-link"></span></a>Runing</h5>
<p>You can run trusted directly.</p>
<pre><code>$ docker run --rm local/trusterd --help
Usage: ./bin/trusterd [switches] programfile
switches:
-b load and execute RiteBinary (mrb) file
-c check syntax only
-e 'command' one line of script
-v print version number, then run in verbose mode
--verbose run in verbose mode
--version print the version
--copyright print the copyright
</code></pre>
<p>Run with default configration. (<a href="./docker/conf/trusterd.conf.rb">docker/conf/trusterd.conf.rb</a>)</p>
<pre><code>docker run -d -p 8080:8080 local/trusterd
</code></pre>
<p>Run with your configration.</p>
<pre><code>mkdir localconf
vi localconf/your_config.rb ## Write your configration.
$ docker run -d -v `pwd`/localconf:/usr/local/trusterd/localconf -p 8080:8080 local/trusterd ./localconf/your_config.rb
</code></pre>
<h5>
<a id="access-1" class="anchor" href="#access-1" aria-hidden="true"><span class="octicon octicon-link"></span></a>Access</h5>
<pre><code>nghttp -v http://127.0.0.1:8080/index.html
</code></pre>
<h2>
<a id="embed-into-your-c-application" class="anchor" href="#embed-into-your-c-application" aria-hidden="true"><span class="octicon octicon-link"></span></a>Embed into your C application</h2>
<h3>
<a id="http2-server-fucntion" class="anchor" href="#http2-server-fucntion" aria-hidden="true"><span class="octicon octicon-link"></span></a>HTTP/2 Server fucntion</h3>
<p>See <a href="https://github.com/trusterd/trusterd/blob/master/src/mini_trusterd.c">src/mini_trusterd.c</a></p>
<h3>
<a id="http2-client-function" class="anchor" href="#http2-client-function" aria-hidden="true"><span class="octicon octicon-link"></span></a>HTTP/2 Client function</h3>
<p>See <a href="https://github.com/trusterd/trusterd/blob/master/src/mini_trusterd_client.c">src/mini_trusterd_client.c</a></p>
<h2>
<a id="peformance" class="anchor" href="#peformance" aria-hidden="true"><span class="octicon octicon-link"></span></a>Peformance</h2>
<h3>
<a id="machine" class="anchor" href="#machine" aria-hidden="true"><span class="octicon octicon-link"></span></a>Machine</h3>
<ul>
<li>Ubuntu14.04 on VMWare</li>
<li>Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz 4core</li>
<li>Memory 8GB</li>
</ul>
<h3>
<a id="config" class="anchor" href="#config" aria-hidden="true"><span class="octicon octicon-link"></span></a>Config</h3>
<h4>
<a id="trusterdconfrb" class="anchor" href="#trusterdconfrb" aria-hidden="true"><span class="octicon octicon-link"></span></a>trusterd.conf.rb</h4>
<div class="highlight highlight-ruby"><pre><span class="pl-c1">SERVER_NAME</span> <span class="pl-k">=</span> <span class="pl-s"><span class="pl-pds">"</span>Trusterd<span class="pl-pds">"</span></span>
<span class="pl-c1">SERVER_VERSION</span> <span class="pl-k">=</span> <span class="pl-s"><span class="pl-pds">"</span>0.0.1<span class="pl-pds">"</span></span>
<span class="pl-c1">SERVER_DESCRIPTION</span> <span class="pl-k">=</span> <span class="pl-s"><span class="pl-pds">"</span><span class="pl-pse">#{</span><span class="pl-s1"><span class="pl-c1">SERVER_NAME</span></span><span class="pl-pse"><span class="pl-s1">}</span></span>/<span class="pl-pse">#{</span><span class="pl-s1"><span class="pl-c1">SERVER_VERSION</span></span><span class="pl-pse"><span class="pl-s1">}</span></span><span class="pl-pds">"</span></span>
root_dir <span class="pl-k">=</span> <span class="pl-s"><span class="pl-pds">"</span>/usr/local/trusterd<span class="pl-pds">"</span></span>
s <span class="pl-k">=</span> <span class="pl-c1">HTTP2</span>::<span class="pl-c1">Server</span>.<span class="pl-k">new</span>({
<span class="pl-c1">:port</span> => <span class="pl-c1">8081</span>,
<span class="pl-c1">:document_root</span> => <span class="pl-s"><span class="pl-pds">"</span><span class="pl-pse">#{</span><span class="pl-s1">root_dir</span><span class="pl-pse"><span class="pl-s1">}</span></span>/htdocs<span class="pl-pds">"</span></span>,
<span class="pl-c1">:server_name</span> => <span class="pl-c1">SERVER_DESCRIPTION</span>,
<span class="pl-c1">:tls</span> => <span class="pl-c1">false</span>,
})
s.run</pre></div>
<h3>
<a id="benchmarks" class="anchor" href="#benchmarks" aria-hidden="true"><span class="octicon octicon-link"></span></a>Benchmarks</h3>
<p><a href="https://github.com/tatsuhiro-t/nghttp2#benchmarking-tool">h2load</a> is a benchmark tool for HTTP/2.</p>
<ul>
<li>use <a href="https://github.com/h2o/h2o#benchmarks">h2o/h2o benchmark parameter</a>
</li>
</ul>
<h4>
<a id="4-worker-mode-benchmark-demo" class="anchor" href="#4-worker-mode-benchmark-demo" aria-hidden="true"><span class="octicon octicon-link"></span></a>4 worker mode benchmark demo</h4>
<p>500,000 reqeuat/sec is very fater!!
<img src="https://raw.githubusercontent.com/trusterd/trusterd/master/images/bench.png" alt=""></p>
<h4>
<a id="4-worker-mode-cpu-usage-by-top-demo" class="anchor" href="#4-worker-mode-cpu-usage-by-top-demo" aria-hidden="true"><span class="octicon octicon-link"></span></a>4 worker mode cpu usage by top demo</h4>
<p>trusterd worker processes use cpu resources of full core mostly.
<img src="https://raw.githubusercontent.com/trusterd/trusterd/master/images/top.png" alt=""></p>
<h4>
<a id="http2" class="anchor" href="#http2" aria-hidden="true"><span class="octicon octicon-link"></span></a>HTTP/2</h4>
<table>
<thead>
<tr>
<th>Server \ size of content</th>
<th align="right">6 bytes</th>
<th align="right">4,096 bytes</th>
</tr>
</thead>
<tbody>
<tr>
<td>nghttpd (<a href="https://github.com/tatsuhiro-t/nghttp2/">nghttpd @ a08ce38</a>) single thread</td>
<td align="right">148,841</td>
<td align="right">73,812</td>
</tr>
<tr>
<td>nghttpd (<a href="https://github.com/tatsuhiro-t/nghttp2/">nghttpd @ a08ce38</a>) multi thread</td>
<td align="right">347,152</td>
<td align="right">104,244</td>
</tr>
<tr>
<td>tiny-nghttpd (<a href="https://github.com/tatsuhiro-t/nghttp2/">nghttpd @ a08ce38</a>) single thread</td>
<td align="right">190,223</td>
<td align="right">82,047</td>
</tr>
<tr>
<td>
<a href="https://github.com/trusterd/trusterd">Trusterd @ 2432cc5</a> single process</td>
<td align="right">204,769</td>
<td align="right">92,068</td>
</tr>
<tr>
<td>
<a href="https://github.com/trusterd/trusterd">Trusterd @ 2432cc5</a> multi process</td>
<td align="right">509,059</td>
<td align="right">134,542</td>
</tr>
<tr>
<td>
<a href="https://github.com/h2o/h2o">H2O @ 529be4e</a> single thread</td>
<td align="right">216,453</td>
<td align="right">112,356</td>
</tr>
<tr>
<td>
<a href="https://github.com/h2o/h2o">H2O @ 529be4e</a> multi thread</td>
<td align="right">379,623</td>
<td align="right">146,343</td>
</tr>
</tbody>
</table>
<p><code>h2load -c 500 -m 100 -n 2000000</code></p>
<h4>
<a id="ref-http11-on-same-benchmark-environment" class="anchor" href="#ref-http11-on-same-benchmark-environment" aria-hidden="true"><span class="octicon octicon-link"></span></a>Ref: HTTP/1.1 on same benchmark environment</h4>
<table>
<thead>
<tr>
<th>Server \ size of content</th>
<th align="right">6 bytes</th>
<th align="right">4,096 bytes</th>
</tr>
</thead>
<tbody>
<tr>
<td>nginx single process</td>
<td align="right">21,708</td>
<td align="right">22,366</td>
</tr>
<tr>
<td>nginx multi process</td>
<td align="right">67,349</td>
<td align="right">56,203</td>
</tr>
</tbody>
</table>
<p><code>weighttp -k -c 500 -n 200000</code></p>
<h2>
<a id="memory" class="anchor" href="#memory" aria-hidden="true"><span class="octicon octicon-link"></span></a>Memory</h2>
<h4>
<a id="startup" class="anchor" href="#startup" aria-hidden="true"><span class="octicon octicon-link"></span></a>Startup</h4>
<pre><code>USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 62085 0.0 0.0 46668 2288 pts/4 S+ 16:41 0:00 | \_ /usr/local/trusterd/bin/trusterd /usr/local/trusterd/conf/trusterd.conf.rb
</code></pre>
<h4>
<a id="after-processing-ten-million-request" class="anchor" href="#after-processing-ten-million-request" aria-hidden="true"><span class="octicon octicon-link"></span></a>After processing ten million request</h4>
<pre><code>USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 62085 63.3 0.0 49200 5144 pts/4 S+ 16:41 0:47 | \_ /usr/local/trusterd/bin/trusterd /usr/local/trusterd/conf/trusterd.conf.rb
</code></pre>
<h2>
<a id="license" class="anchor" href="#license" aria-hidden="true"><span class="octicon octicon-link"></span></a>License</h2>
<p>under the MIT License:</p>
<ul>
<li><a href="http://www.opensource.org/licenses/mit-license.php">http://www.opensource.org/licenses/mit-license.php</a></li>
</ul>
<footer class="site-footer">
<span class="site-footer-owner"><a href="https://github.com/trusterd/trusterd">Trusterd - HTTP/2 Web Server scripting with mruby</a> is maintained by <a href="https://github.com/trusterd">trusterd</a>.</span>
<span class="site-footer-credits">This page was generated by <a href="https://pages.github.com">GitHub Pages</a> using the <a href="https://github.com/jasonlong/cayman-theme">Cayman theme</a> by <a href="https://twitter.com/jasonlong">Jason Long</a>.</span>
</footer>
</section>
</body>
</html>