Kaynağa Gözat

增加Benchmark性能测试脚本

walkor 11 yıl önce
ebeveyn
işleme
f11137e085

+ 36 - 0
applications/Benchmark/Benchmark.php

@@ -0,0 +1,36 @@
+<?php 
+/**
+ * Benchmark 
+ * 方法1:ab -n 100000 -c200 127.0.0.1:56789/
+ * 方法2:使用workerman自带的benchmark软件,只支持64位linux系统
+ * ①:./benchmark -n10000 -h1 -c400 -p56789 127.0.0.1    // 命令含义是400并发线程,连接127.0.0.1:56789端口发送一个hello\n扥带服务端返回一个hello\n后断开连接,这样运行10000次
+ * ②:./benchmark -n1 -h10000 -c1000 -p56789 127.0.0.1    // 命令含义是1000并发线程,连接127.0.0.1:56789端口连续发送10000个hello\n
+ * @author walkor <workerman.net>
+ */
+class Benchmark extends Man\Core\SocketWorker
+{
+    /**
+     * @see Worker::dealInput()
+     */
+    public function dealInput($buffer)
+    {
+       // 由于请求包都小于一个MTU,不会有分包,这里直接返回0
+       return 0;
+    }
+    
+    /**
+     * 处理业务
+     * @see Worker::dealProcess()
+     */
+    public function dealProcess($buffer)
+    {
+        // 是HTTP协议
+        if('H' == $buffer[0] )
+        {
+            return $this->sendToClient("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\nhello");
+        }
+        // 是benchmark脚本
+        return $buffer;
+    }
+    
+} 

+ 8 - 0
applications/Benchmark/README.md

@@ -0,0 +1,8 @@
+Benchmark 
+=========
+
+方法一:ab -n 100000 -c200 127.0.0.1:56789/  
+
+方法二:使用workerman自带的benchmark软件,只支持64位linux系统  
+1: ./benchmark -n10000 -h1 -c400 -p56789 127.0.0.1    // 命令含义是400并发线程,连接127.0.0.1:56789端口发送一个hello\n扥带服务端返回一个hello\n后断开连接,这样运行10000次  
+2:./benchmark -n1 -h10000 -c1000 -p56789 127.0.0.1    // 命令含义是1000并发线程,连接127.0.0.1:56789端口连续发送10000个hello\n  

BIN
applications/Benchmark/benchmark


+ 5 - 0
workerman/conf/conf.d/Benchmark.conf

@@ -0,0 +1,5 @@
+worker_file = ../applications/Benchmark/Benchmark.php
+listen = tcp://0.0.0.0:56789
+start_workers = 48
+user = root
+preread_length = 65535