C++,python,热爱算法和机器学习
全部博文(1214)
分类: 架构设计与优化
2014-01-22 11:54:55
1
2
3
4
5
6
|
yum -y install zeromq
yum install gcc gcc-c++ libuuid-devel python-uuid uuid
wget
./configure
make
make install
|
1
|
pip install gevent
|
1
|
pip install zerorpc
|
1
2
3
4
5
6
7
8
9
|
import zerorpc
import time
class HelloRPC(object):
def hello(self, name):
print "this is %s %s" %(name,time.strftime('%Y-%m-%d %H-%m-%S',time.localtime(time.time())))
return "Hello, %s" %time.strftime('%Y-%m-%d %H-%m-%S',time.localtime(time.time()))
s = zerorpc.Server(HelloRPC())
s.bind("tcp://0.0.0.0:4242")
s.run()
|
1
2
3
4
5
|
import zerorpc
import os,sys
c = zerorpc.Client()
c.connect("tcp://127.0.0.1:4242")
print c.hello('')
|
1
|
zerorpc --client --connect tcp://127.0.0.1:4242 hello lllllllllllllllllllllllllll
|
1
2
3
4
|
xmlrpc client & server (single-threaded): 850 calls/sec
zerorpc client & server (single-threaded): 4500 calls/sec
xmlrpc client & server (multi-threaded): 1200 calls/sec
zerorpc client & server (multi-threaded): 11000 calls/sec
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
class Cooler:
def add_man(self, sentence):
"""return the result. """
return sentence + ", man!"
def add_42(self, n):
"""result. """
return n + 42
def boat(self, sentence):
""" because it's cooler. """
return "I'm on a boat!"
import zerorpc
s = zerorpc.Server(Cooler())
s.bind("tcp://0.0.0.0:4242")
s.run()
|
1
2
3
4
5
6
|
$ zerorpc -j tcp://:4242 add_42 1
43
$ zerorpc tcp://:4242 add_man 'I own a mint-condition Volkswagen Golf'
"I own a mint-condition Volkswagen Golf, man!"
$ zerorpc tcp://:4242 boat 'I own a mint-condition Volkswagen Golf, man!'
"I'm on a boat!"
|
1
2
3
4
5
6
7
8
|
haproxy.cfg的配置
$cat haproxy.cfg
listen zerorpc 0.0.0.0:1111
mode tcp
server backend_a localhost:2222 check
server backend_b localhost:3333 check
检测语法
$ haproxy -f haproxy.cfg
|