参照: CentOS 7 nodeJs环境相关安装.
npm install -g websocket-bench
①安装出现error
······
make: Entering directory `/home/vagrant/.npm-global/lib/node_modules/websocket-bench/node_modules/utf-8-validate/build'
CXX(target) Release/obj.target/validation/src/validation.o
make: g++: Command not found
make: *** [Release/obj.target/validation/src/validation.o] Error 127
······
安装 g++
sudo yum -y install gcc-c++
再次安装 OK
[vagrant@localhost vagrant]$ npm install -g websocket-bench
npm WARN deprecated extendable@0.0.6: This project has been renamed to extendible. This project will not receive any updates anymore
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
npm WARN deprecated hoek@0.7.6: The major version is no longer supported. Please update to 4.x or newer
/home/vagrant/.npm-global/bin/websocket-bench -> /home/vagrant/.npm-global/lib/node_modules/websocket-bench/bin/websocket-bench
> bufferutil@1.2.1 install /home/vagrant/.npm-global/lib/node_modules/websocket-bench/node_modules/bufferutil
> node-gyp rebuild
make: Entering directory `/home/vagrant/.npm-global/lib/node_modules/websocket-bench/node_modules/bufferutil/build'
CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
SOLINK_MODULE(target) Release/obj.target/bufferutil.node
COPY Release/bufferutil.node
make: Leaving directory `/home/vagrant/.npm-global/lib/node_modules/websocket-bench/node_modules/bufferutil/build'
> utf-8-validate@1.2.2 install /home/vagrant/.npm-global/lib/node_modules/websocket-bench/node_modules/utf-8-validate
> node-gyp rebuild
make: Entering directory `/home/vagrant/.npm-global/lib/node_modules/websocket-bench/node_modules/utf-8-validate/build'
CXX(target) Release/obj.target/validation/src/validation.o
SOLINK_MODULE(target) Release/obj.target/validation.node
COPY Release/validation.node
make: Leaving directory `/home/vagrant/.npm-global/lib/node_modules/websocket-bench/node_modules/utf-8-validate/build'
+ websocket-bench@0.2.0
added 5 packages from 9 contributors and updated 6 packages in 10.198s
②版本确认出现error
[vagrant@localhost vagrant]$ websocket-bench -V
bash: websocket-bench: command not found
PATH确认
[vagrant@localhost vagrant]$ echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/vagrant/.local/bin:/home/vagrant/bin
通过上面的安装信息可以看到,路径需要添加 /home/vagrant/.npm-global/bin
[vagrant@localhost vagrant]$ PATH=$PATH:/home/vagrant/.npm-global/bin
[vagrant@localhost vagrant]$ export PATH
版本确认
[vagrant@localhost vagrant]$ websocket-bench -V
0.0.3
默认是 1024,推荐 60000
确认当前设置;
[vagrant@localhost vagrant]$ ulimit -n
1024
修改
[vagrant@localhost etc]$ su
Password:
[root@localhost etc]# ulimit -n 60000
[root@localhost etc]# su vagrant
[vagrant@localhost etc]$
[vagrant@localhost etc]$ ulimit -n
60000
websocket-bench -a 2500 -c 200 http://localhost:3000
其他一些命令
Usage: websocket-bench [options]
Options:
-h, --help Output usage information
-V, --version Output the version number
-a, --amount Total number of persistent connection, Default to 100
-c, --concurency Concurent connection per second, Default to 20
-w, --worker Number of worker(s)
-g, --generator Js file for generate message or special event
-m, --message Number of message for a client. Default to 0
-o, --output Output file
-t, --type Type of websocket server to bench(socket.io, engine.io, faye, primus, wamp). Default to socket.io
-p, --transport Type of transport to websocket(engine.io, websockets, browserchannel, sockjs, socket.io). Default to websockets (Just for Primus)
-k, --keep-alive Keep alive connection
-v, --verbose Verbose Logging