-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.html
100 lines (82 loc) · 24.4 KB
/
benchmark.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
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Benchmark | Pinatra</title>
<meta name="description" content="A PHP verison of Sinatra: a DSL for quickly creating web applications in PHP with minimal effort.">
<link rel="preload" href="/assets/css/0.styles.73742341.css" as="style"><link rel="preload" href="/assets/js/app.35633900.js" as="script"><link rel="preload" href="/assets/js/5.ad87e3bc.js" as="script"><link rel="prefetch" href="/assets/js/4.dd1ee4a1.js"><link rel="prefetch" href="/assets/js/2.9834f0cc.js"><link rel="prefetch" href="/assets/js/3.2b86a6bc.js"><link rel="prefetch" href="/assets/js/6.7a49fda2.js"><link rel="prefetch" href="/assets/js/7.490e94d8.js"><link rel="prefetch" href="/assets/js/8.3b2a41b2.js"><link rel="prefetch" href="/assets/js/9.cfda04a6.js"><link rel="prefetch" href="/assets/js/10.20f55d86.js"><link rel="prefetch" href="/assets/js/11.fbd446e0.js"><link rel="prefetch" href="/assets/js/12.7418dee3.js"><link rel="prefetch" href="/assets/js/13.111e6ced.js"><link rel="prefetch" href="/assets/js/14.78258348.js"><link rel="prefetch" href="/assets/js/15.73297d5e.js"><link rel="prefetch" href="/assets/js/16.63b4556e.js"><link rel="prefetch" href="/assets/js/17.c9391c34.js"><link rel="prefetch" href="/assets/js/18.584449ed.js"><link rel="prefetch" href="/assets/js/19.c8dececa.js"><link rel="prefetch" href="/assets/js/vendors~docsearch.41d79f37.js">
<link rel="stylesheet" href="/assets/css/0.styles.73742341.css">
</head>
<body>
<div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">Pinatra</span></a> <div class="links" style="max-width:nullpx;"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="https://github.com/Pinatra/Pinatra" target="_blank" rel="noopener noreferrer" class="nav-link external">
Source
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">Languages</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/benchmark.html" class="nav-link router-link-exact-active router-link-active">English</a></li><li class="dropdown-item"><!----> <a href="/zh/benchmark.html" class="nav-link">简体中文</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="https://github.com/Pinatra/Pinatra" target="_blank" rel="noopener noreferrer" class="nav-link external">
Source
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">Languages</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/benchmark.html" class="nav-link router-link-exact-active router-link-active">English</a></li><li class="dropdown-item"><!----> <a href="/zh/benchmark.html" class="nav-link">简体中文</a></li></ul></div></div> <!----></nav> <ul class="sidebar-links"><li><div class="sidebar-group first"><p class="sidebar-heading open"><span>Guide</span> <!----></p> <ul class="sidebar-group-items"><li><a href="/" class="sidebar-link">Introduction</a></li><li><a href="/install.html" class="sidebar-link">Installation</a></li><li><a href="/routing.html" class="sidebar-link">Routing</a></li><li><a href="/controller.html" class="sidebar-link">Controller</a></li><li><a href="/view.html" class="sidebar-link">Views</a></li><li><a href="/model.html" class="sidebar-link">Model</a></li><li><a href="/kernel.html" class="sidebar-link">Kernel details</a></li><li><a href="/benchmark.html" class="active sidebar-link">Benchmark</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/benchmark.html#environment" class="sidebar-link">Environment</a></li><li class="sidebar-sub-header"><a href="/benchmark.html#testing-framework-and-version" class="sidebar-link">Testing framework and version</a></li><li class="sidebar-sub-header"><a href="/benchmark.html#testing-process" class="sidebar-link">Testing process</a></li><li class="sidebar-sub-header"><a href="/benchmark.html#hello-world" class="sidebar-link">Hello World</a></li><li class="sidebar-sub-header"><a href="/benchmark.html#simple-api-test" class="sidebar-link">Simple api test</a></li></ul></li></ul></div></li></ul> </div> <div class="page"> <div class="content"><h1 id="benchmark"><a href="#benchmark" aria-hidden="true" class="header-anchor">#</a> Benchmark</h1> <h2 id="environment"><a href="#environment" aria-hidden="true" class="header-anchor">#</a> Environment</h2> <table><thead><tr><th style="text-align:center">Name</th> <th style="text-align:center">Value</th></tr></thead> <tbody><tr><td style="text-align:center">Operating System</td> <td style="text-align:center">CentOS Linux release 7.5.1804</td></tr> <tr><td style="text-align:center">Linux Kernel</td> <td style="text-align:center">3.10.0-862.11.6.el7.x86_64</td></tr> <tr><td style="text-align:center">CPU</td> <td style="text-align:center">( 6-Core Intel Xeon X5650 2.66GHz ) x 2 = 12 Cores, 24 Threads</td></tr> <tr><td style="text-align:center">Memory</td> <td style="text-align:center">( DDR3 1333MHz 4GB ) x 12 = 48GB</td></tr> <tr><td style="text-align:center">Disk</td> <td style="text-align:center">SSD 6.15/111.79 GiB (5.5%)</td></tr> <tr><td style="text-align:center">Test Software</td> <td style="text-align:center">ApacheBench, Version 2.3 with mod_php72w</td></tr> <tr><td style="text-align:center">Operating Environment</td> <td style="text-align:center">Apache/2.4.6</td></tr> <tr><td style="text-align:center">Database</td> <td style="text-align:center">MariaDB 10.3.9 x86_64</td></tr> <tr><td style="text-align:center">PHP Version</td> <td style="text-align:center">PHP 7.2.8 <br> Zend Engine v3.2.0 <br> Zend OPcache v7.2.8</td></tr> <tr><td style="text-align:center">PHP plugin</td> <td style="text-align:center">bz2 calendar Core ctype curl date dom exif fileinfo filter <br> ftp gd gettext gmp hash iconv igbinary json libxml mbstring <br> mysqli openssl pcntl pcre PDO pdo_mysql pdo_sqlite Phar <br> posix readline redis Reflection session shmop SimpleXML SPL <br> sockets sqlite3 standard sysvmsg sysvsem sysvshm tokenizer <br> wddx xml xmlreader xmlwriter xsl Zend OPcache zip zlib Zend <br> OPcache</td></tr></tbody></table> <h2 id="testing-framework-and-version"><a href="#testing-framework-and-version" aria-hidden="true" class="header-anchor">#</a> Testing framework and version</h2> <ol><li>Laravel 5.7.2</li> <li>Pinatra 0.0.2</li> <li>CodeIgniter 3.1.9</li></ol> <h2 id="testing-process"><a href="#testing-process" aria-hidden="true" class="header-anchor">#</a> Testing process</h2> <p>Test using the ab tool that comes with httpd. The test points are as follows:</p> <ol><li>All sites are placed in subdirectory under the Apache default Document Root (/var/www/html) with a URL of 127.0.0.1/* and no changes to the Apache configuration file.</li> <li>Each test completes 5000 requests, and sends 1, 5, and 20 each time. The minimum value of <code>Time per request: *[ms] (mean, across all concurrent requests)</code> is the result of the concurrent</li> <li>Each test ensures that the memory is not full to ensure fairness.</li> <li>The ab command and MariaDB both run on this server.</li> <li>Only compare requests time-consuming, do not compare memory usage.</li></ol> <h2 id="hello-world"><a href="#hello-world" aria-hidden="true" class="header-anchor">#</a> Hello World</h2> <div class="warning custom-block"><p class="custom-block-title">Definition</p> <p>Hello World test: The normal flow of using a framework, in addition to "do not call the model" (do not connect to the database), use the normal Controller -> View process, print out the test of "Hello World!" several strings.</p></div> <h3 id="test-results"><a href="#test-results" aria-hidden="true" class="header-anchor">#</a> Test Results</h3> <p>The average time spent per request, in milliseconds (ms).</p> <table><thead><tr><th style="text-align:center">Concurrent Numbers</th> <th style="text-align:center">Laravel</th> <th style="text-align:center">CodeIgniter</th> <th style="text-align:center">Pinatra</th></tr></thead> <tbody><tr><td style="text-align:center">1</td> <td style="text-align:center">8.163</td> <td style="text-align:center">1.164</td> <td style="text-align:center">0.814</td></tr> <tr><td style="text-align:center">5</td> <td style="text-align:center">3.513</td> <td style="text-align:center">0.218</td> <td style="text-align:center">0.143</td></tr> <tr><td style="text-align:center">20</td> <td style="text-align:center">1.546</td> <td style="text-align:center">0.089</td> <td style="text-align:center">0.087</td></tr></tbody></table> <br> <p><img src="/assets/img/1.c06f289d.png" alt="Average time spent per request"></p> <h2 id="simple-api-test"><a href="#simple-api-test" aria-hidden="true" class="header-anchor">#</a> Simple api test</h2> <p>In order to test the performance of the framework and minimize the impact of the database on performance, we installed MariaDB 10.3.9 and added the users table in the test library. There are three rows of data:</p> <p><img src="/assets/img/6.d1bad87c.jpg" alt="database"></p> <div class="warning custom-block"><p class="custom-block-title">Definition</p> <p>Simple api test: Using the normal flow of a framework, complete the entire process of Controller -> Model -> View, where CodeIgniter and Laravel use their own ORM, Pinatra uses Laravel's ORM component [illuminate/database] (https://packagist. Org/packages/illuminate/database).</p></div> <h3 id="test-results-2"><a href="#test-results-2" aria-hidden="true" class="header-anchor">#</a> Test Results</h3> <h4 id="test-code"><a href="#test-code" aria-hidden="true" class="header-anchor">#</a> Test code</h4> <p>Laravel:</p> <div class="language-php extra-class"><pre class="language-php"><code># app/User.php
<span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">namespace</span> <span class="token package">App</span><span class="token punctuation">;</span>
<span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Database<span class="token punctuation">\</span>Eloquent<span class="token punctuation">\</span>Model</span><span class="token punctuation">;</span>
<span class="token keyword">class</span> <span class="token class-name">User</span> <span class="token keyword">extends</span> <span class="token class-name">Model</span>
<span class="token punctuation">{</span>
<span class="token comment">//</span>
<span class="token punctuation">}</span>
<span class="token shell-comment comment"># app/Http/Controllers/HomeController.php</span>
<span class="token delimiter important"><?php</span>
<span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Controllers</span><span class="token punctuation">;</span>
<span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Request</span><span class="token punctuation">;</span>
<span class="token keyword">class</span> <span class="token class-name">HomeController</span> <span class="token keyword">extends</span> <span class="token class-name">Controller</span>
<span class="token punctuation">{</span>
<span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function">home</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">return</span> <span class="token function">json_encode</span><span class="token punctuation">(</span>\<span class="token package">App<span class="token punctuation">\</span>User</span><span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">all</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">toArray</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</span></code></pre></div><p>CodeIgniter:</p> <div class="language-php extra-class"><pre class="language-php"><code># application/models/User.php
<span class="token php language-php"><span class="token delimiter important"><?php</span> <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token operator">!</span> <span class="token function">defined</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'BASEPATH'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token function">exit</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'No direct script access allowed'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">class</span> <span class="token class-name">User</span> <span class="token keyword">extends</span> <span class="token class-name">CI_Model</span> <span class="token punctuation">{</span>
<span class="token keyword">function</span> <span class="token function">__construct</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
<span class="token keyword">parent</span><span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">__construct</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token variable">$this</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">load</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">database</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function">getAll</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
<span class="token variable">$query</span> <span class="token operator">=</span> <span class="token variable">$this</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">db</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">query</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'SELECT * FROM users'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">return</span> <span class="token variable">$query</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">result_array</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token shell-comment comment"># application/controllers/Welcome.php</span>
<span class="token delimiter important"><?php</span>
<span class="token function">defined</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'BASEPATH'</span><span class="token punctuation">)</span> <span class="token keyword">OR</span> <span class="token function">exit</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'No direct script access allowed'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">class</span> <span class="token class-name">Welcome</span> <span class="token keyword">extends</span> <span class="token class-name">CI_Controller</span> <span class="token punctuation">{</span>
<span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function">index</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
<span class="token variable">$this</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">load</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">model</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'user'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">echo</span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">user</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">getAll</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</span></code></pre></div><p>Pinatra:</p> <div class="language-php extra-class"><pre class="language-php"><code># model/User.php
<span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">namespace</span> <span class="token package">Model</span><span class="token punctuation">;</span>
<span class="token keyword">class</span> <span class="token class-name">Article</span> <span class="token keyword">extends</span> <span class="token class-name"><span class="token punctuation">\</span>Pinatra<span class="token punctuation">\</span>Model<span class="token punctuation">\</span>Model</span>
<span class="token punctuation">{</span>
<span class="token punctuation">}</span>
<span class="token shell-comment comment"># controllers/HomeController.php</span>
<span class="token delimiter important"><?php</span>
<span class="token keyword">namespace</span> <span class="token package">Controllers</span><span class="token punctuation">;</span>
<span class="token keyword">class</span> <span class="token class-name">HomeController</span>
<span class="token punctuation">{</span>
<span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function">home</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
<span class="token keyword">return</span> <span class="token function">json_encode</span><span class="token punctuation">(</span>\<span class="token package">Model<span class="token punctuation">\</span>User</span><span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">all</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">toArray</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</span></code></pre></div><h4 id="expected-output"><a href="#expected-output" aria-hidden="true" class="header-anchor">#</a> Expected Output</h4> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token property">"id"</span><span class="token operator">:</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token property">"name"</span><span class="token operator">:</span><span class="token string">"John"</span><span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token punctuation">{</span><span class="token property">"id"</span><span class="token operator">:</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token property">"name"</span><span class="token operator">:</span><span class="token string">"Mike"</span><span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token punctuation">{</span><span class="token property">"id"</span><span class="token operator">:</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token property">"name"</span><span class="token operator">:</span><span class="token string">"Tony"</span><span class="token punctuation">}</span><span class="token punctuation">]</span>
</code></pre></div><p>The average time spent per request, in milliseconds (ms).</p> <table><thead><tr><th style="text-align:center">Concurrents</th> <th style="text-align:center">Laravel</th> <th style="text-align:center">CodeIgniter</th> <th style="text-align:center">Pinatra</th></tr></thead> <tbody><tr><td style="text-align:center">1</td> <td style="text-align:center">10.631</td> <td style="text-align:center">2.033</td> <td style="text-align:center">3.942</td></tr> <tr><td style="text-align:center">5</td> <td style="text-align:center">2.715</td> <td style="text-align:center">0.443</td> <td style="text-align:center">0.727</td></tr> <tr><td style="text-align:center">20</td> <td style="text-align:center">1.285</td> <td style="text-align:center">0.146</td> <td style="text-align:center">0.636</td></tr></tbody></table> <br> <p><img src="/assets/img/2.bcbf16ab.png" alt="平均每次请求消耗的时间"></p></div> <div class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">9/20/2018, 4:32:21 PM</span></div></div> <div class="page-nav"><p class="inner"><span class="prev">
←
<a href="/kernel.html" class="prev">
Kernel details
</a></span> <!----></p></div> </div> <!----></div></div>
<script src="/assets/js/5.ad87e3bc.js" defer></script><script src="/assets/js/app.35633900.js" defer></script>
</body>
</html>