我爱编程

服务化之通过ae::http请求使用coro协程建立snmp和t

2017-03-15  本文已影响0人  飞天神猫

利用forkmanager和anyevent-server实现类似nginx的surpervisor和worker模式

nginx启动后,会根据worker配置数量fork对应进程数,同时启动父进程作为surpervisor,当worker进程数减少时会自动补充对应worker,我们的目标是利用forkmanager实现该功能,提供给httpserver使用。

思路

实现

-bash-4.1# nohup perl anyevent-http-server.pl -t 5 &
[1] 3999
-bash-4.1# nohup: 忽略输入并把输出追加到"nohup.out"
-bash-4.1# ps -ef|grep anyevent-http-server.pl
root      3999 27832  5 15:24 pts/3    00:00:00 perl anyevent-http-server.pl -t 5
root      4000  3999  0 15:24 pts/3    00:00:00 perl anyevent-http-server.pl -t 5
root      4001  3999  0 15:24 pts/3    00:00:00 perl anyevent-http-server.pl -t 5
root      4002  3999  0 15:24 pts/3    00:00:00 perl anyevent-http-server.pl -t 5
root      4003  3999  0 15:24 pts/3    00:00:00 perl anyevent-http-server.pl -t 5
root      4004  3999  0 15:24 pts/3    00:00:00 perl anyevent-http-server.pl -t 5
root      4008 27832  0 15:24 pts/3    00:00:00 grep anyevent-http-server.pl
-bash-4.1# kill 4000
-bash-4.1# ps -ef|grep anyevent-http-server.pl
root      3999 27832  1 15:24 pts/3    00:00:00 perl anyevent-http-server.pl -t 5
root      4001  3999  0 15:24 pts/3    00:00:00 perl anyevent-http-server.pl -t 5
root      4002  3999  0 15:24 pts/3    00:00:00 perl anyevent-http-server.pl -t 5
root      4003  3999  0 15:24 pts/3    00:00:00 perl anyevent-http-server.pl -t 5
root      4004  3999  0 15:24 pts/3    00:00:00 perl anyevent-http-server.pl -t 5
root      4017  3999  0 15:24 pts/3    00:00:00 perl anyevent-http-server.pl -t 5
root      4021 27832  0 15:24 pts/3    00:00:00 grep anyevent-http-server.pl
-bash-4.1# kill 3999
-bash-4.1# ps -ef|grep anyevent-http-server.pl
root      4036 27832  0 15:24 pts/3    00:00:00 grep anyevent-http-server.pl
[1]+  Done                    nohup perl anyevent-http-server.pl -t 5

benchmark

并发100 5000连接

并发1 5000连接

打开keepalive 并发100 5000连接

Requests per second: 5357.12 [#/sec] (mean)

接收http请求后,利用coro-telnet和coro-snmp实现协程建立和设备交互session完成请求指标并返回

-bash-4.3$ time curl http://127.0.0.10:19999?pretty -d '{
>     "hostip": "1.1.1.1,2.2.2.2,3.3.3.3",
>     "items": "show users"
> }'
...
...
real    0m6.008s
user    0m0.002s
sys     0m0.003s
bash-4.1$ curl http://127.0.0.1:19999?pretty -d '{
    "hostip": "192.168.6.87,192.168.6.87,192.168.6.87",
    "items": "show users"
}'
show users
    Line       User       Host(s)              Idle       Location
 66 vty 0     aaa        idle                 00:00:00 192.168.6.150
  67 vty 1     aaa        idle                 00:00:03 192.168.6.150
  Interface    User               Mode         Idle     Peer Address
BJ-BJ-ZU-V-2.test
##################################0##################################
show users
    Line       User       Host(s)              Idle       Location
  66 vty 0     aaa        idle                 00:00:00 192.168.6.150
 67 vty 1     aaa        idle                 00:00:03 192.168.6.150
  Interface    User               Mode         Idle     Peer Address
BJ-BJ-ZU-V-2.test
##################################1##################################
show users
    Line       User       Host(s)              Idle       Location
  66 vty 0     aaa        idle                 00:00:00 192.168.6.150
  67 vty 1     aaa        idle                 00:00:00 192.168.6.150
 69 vty 3     aaa        idle                 00:00:00 192.168.6.150
  Interface    User               Mode         Idle     Peer Address
BJ-BJ-ZU-V-2.test
##################################2##################################
You have mail in /var/spool/mail/slview
bash-4.1$ 
bash-4.1$ time curl http://192.168.6.150:18888?pretty -d '{
>     "hostip": "192.168.6.87,192.168.6.87,192.168.6.87",
>     "items": "ifhcinoctets"
> }'
"192.168.6.87_1_ifhcinoctets": "12010862272"
"192.168.6.87_4_ifhcinoctets": "0"
"192.168.6.87_5_ifhcinoctets": "0"
...
...
##################################2##################################
real    0m3.014s
user    0m0.007s
sys     0m0.004s
上一篇 下一篇

猜你喜欢

热点阅读