Spike https://github.com/slince/spikephp
以前因爲要與一個同事遠程協做開發一款 app 須要用到內網穿透服務,在網上找到了 frp 與 ngrok ;後來我在想能不能用 php 也寫出來一個這樣的服務軟件?你們都知道 php 多進程多線程不夠友好,在 window 上還不支持;寫服務確實很吃力;不過幸運的是有ReactPHP的存在,關於 ReactPHP 不作贅述有興趣的同窗能夠自行百度。git
基於 ReactPHP 的 IO 多路複用,使得 Spike 並無比 Frp 性能差太多;下面是我簡單作的一個 benchmark,基於 apache ab 檢驗 http 隧道的服務性能;客戶端與服務端都搭在本地,代理同事電腦上的 http 服務。不是特別符合應用場景,你們簡單看一下。github
從下面的信息能夠看出 Spike 性能彷佛是稍微好點的,不過這個地方有點不公平,我在作 spike 的測試時只開啓了服務端的日誌,客戶端的日誌是關閉的;而 FRP 的兩端日誌都是開啓的;我不知道怎麼關 frp 的日誌;apache
在這裏簡單提一點因爲 Spike 的日誌 IO 是同步的因此日誌的讀寫會耗掉部分性能,提高日誌等級減小日誌寫入能夠提高很多的性能;多線程
這個項目是我比較上心的一個做品,算是證實了一點,php 除了能夠作網站也能夠作服務,而且也沒有太差。 最後再次附上項目地址: https://github.com/slince/spike 歡迎 star,歡迎 forkapp
Spike:性能
Concurrency Level: 10 Time taken for tests: 37.727 seconds Complete requests: 100 Failed requests: 0 Total transferred: 2569900 bytes HTML transferred: 2514600 bytes Requests per second: 2.65 [#/sec] (mean) Time per request: 3772.747 [ms] (mean) Time per request: 377.275 [ms] (mean, across all concurrent requests) Transfer rate: 66.52 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.4 0 3 Processing: 533 3602 591.9 3714 4096 Waiting: 516 3587 592.3 3701 4076 Total: 534 3602 591.9 3715 4097 Percentage of the requests served within a certain time (ms) 50% 3715 66% 3791 75% 3822 80% 3844 90% 3970 95% 4015 98% 4053 99% 4097 100% 4097 (longest request)
Frp:測試
Concurrency Level: 10 Time taken for tests: 38.230 seconds Complete requests: 100 Failed requests: 0 Total transferred: 2569900 bytes HTML transferred: 2514600 bytes Requests per second: 2.62 [#/sec] (mean) Time per request: 3823.045 [ms] (mean) Time per request: 382.304 [ms] (mean, across all concurrent requests) Transfer rate: 65.65 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.2 0 1 Processing: 379 3650 644.4 3809 4140 Waiting: 360 3633 645.5 3789 4124 Total: 380 3650 644.4 3809 4140 Percentage of the requests served within a certain time (ms) 50% 3809 66% 3847 75% 3909 80% 3923 90% 4026 95% 4053 98% 4129 99% 4140 100% 4140 (longest request)