Skip to content
Permalink
Browse files
performance compare
  • Loading branch information
JoeCao committed Apr 10, 2015
1 parent 6286c95 commit 8b97a1481ae803da5ac6fd0f1653d8a0a0b1e9a0
Showing 3 changed files with 34 additions and 15 deletions.
@@ -36,7 +36,7 @@ def call(self, method, *args, **kwargs):
if len(provides) == 0:
raise NoProvider('can not find provide', self.interface)
ip_port, service_url = random.choice(provides.items())
print service_url.location
# print service_url.location
client = HttpClient(url="http://{0}{1}".format(ip_port, service_url.path))
try:
return client.call(method, *args, **kwargs)
@@ -2,24 +2,27 @@
import timeit

from pyjsonrpc import HttpClient
from dubbo_client import ZookeeperRegistry, DubboClient


__author__ = 'caozupeng'

number = 1000

def test_client_every_new():
user_provider = HttpClient(url="http://{0}{1}".format('172.19.3.111:38081/', 'com.ofpay.demo.api.UserProvider'))
user_provider.getUser('A003')
user_provider.queryUser(
{u'age': 18, u'time': 1428463514153, u'sex': u'MAN', u'id': u'A003', u'name': u'zhangsan'})
# user_provider.queryAll()
user_provider.isLimit('MAN', 'Joe')
user_provider('getUser', 'A005')
for x in range(number):
user_provider = HttpClient(url="http://{0}{1}".format('172.19.3.111:38080/', 'com.ofpay.demo.api.UserProvider'))
user_provider.getUser('A003')
user_provider.queryUser(
{u'age': 18, u'time': 1428463514153, u'sex': u'MAN', u'id': u'A003', u'name': u'zhangsan'})
# user_provider.queryAll()
user_provider.isLimit('MAN', 'Joe')
user_provider('getUser', 'A005')


def test_client():
user_provider = HttpClient(url="http://{0}{1}".format('172.19.3.111:38081/', 'com.ofpay.demo.api.UserProvider'))
for x in range(10000):
user_provider = HttpClient(url="http://{0}{1}".format('172.19.3.111:38080/', 'com.ofpay.demo.api.UserProvider'))
for x in range(number):
user_provider.getUser('A003')
user_provider.queryUser(
{u'age': 18, u'time': 1428463514153, u'sex': u'MAN', u'id': u'A003', u'name': u'zhangsan'})
@@ -28,10 +31,24 @@ def test_client():
user_provider('getUser', 'A005')


def test_dubbo():
service_interface = 'com.ofpay.demo.api.UserProvider'
# 该对象较重,有zookeeper的连接,需要保存使用
registry = ZookeeperRegistry('172.19.65.33:2181')
user_provider = DubboClient(service_interface, registry, version='2.0')
for x in range(number):
user_provider.getUser('A003')
user_provider.queryUser(
{u'age': 18, u'time': 1428463514153, u'sex': u'MAN', u'id': u'A003', u'name': u'zhangsan'})
# user_provider.queryAll()
user_provider.isLimit('MAN', 'Joe')
user_provider('getUser', 'A005')

if __name__ == '__main__':
#test_client_every_new 运行10000次, 耗时220.188388109
#test_client 运行10000次, 耗时215.014229059
#说明每次new HttpClient和保持一个HttpClient的效率相差不大
number = 10000
print u'test_client_every_new 运行{0}次, 耗时{1}'.format(number, timeit.timeit(test_client_every_new, number=number))
print u'test_client 运行{0}次, 耗时{1}'.format(number, timeit.timeit(test_client, number=1))

print u'test_client_every_new 运行{0}次, 耗时{1}'.format(number, timeit.timeit(test_client_every_new, number=1))
print u'test_client 运行{0}次, 耗时{1}'.format(number, timeit.timeit(test_client, number=1))
print u'test_dubbo 运行{0}次, 耗时{1}'.format(number, timeit.timeit(test_dubbo, number=1))
@@ -10,13 +10,15 @@
service_interface = 'com.ofpay.demo.api.UserProvider'
# 该对象较重,有zookeeper的连接,需要保存使用
registry = ZookeeperRegistry('172.19.65.33:2181')
user_provider = DubboClient(service_interface, registry, version='3.0')
user_provider = DubboClient(service_interface, registry, version='2.0')
for i in range(1000):
try:
print user_provider.getUser('A003')
print user_provider.queryUser(
{u'age': 18, u'time': 1428463514153, u'sex': u'MAN', u'id': u'A003', u'name': u'zhangsan'})
print user_provider.queryAll()
datas = user_provider.queryAll()
for key, user in datas.items():
print user['name']
print user_provider.isLimit('MAN', 'Joe')
print user_provider('getUser', 'A005')

0 comments on commit 8b97a14

Please sign in to comment.