具有保持活动功能的异步http客户端
async_keepalive_httpc的Python项目详细描述
现阶段的介绍文档请参见:https://github.com/tly1980/async-keep alive-httpc;
:作者:tom tang<;tly1980@gmail.com>;
:日期:…|日期
:描述:异步保持活动http客户端
keep-alive是一种众所周知的流行技术,它可以减少延迟并加快资源检索速度。
(请参见http://chimera.labs.oreilly.com/books/1230000000545/ch11.html keepalive的优点>;)
连接以请求多个资源,这可以避免建立和关闭http连接所带来的损失,对于https连接也非常重要。
tornado_u是一个高效的python异步web框架和网络库。
我非常喜欢使用它来构建高性能的Web应用程序。
然而,Tornado廑目前还没有一个支持开箱即用的HttpClient(2013年10月1日3.1.1版)。
rts的keep alive特性。
这个客户机基本上是tornado httpclient和httpconnection的黑客,所以api非常相似,
这意味着它可以使用tornado httprequest和原始客户机的大部分特性
(如gzip、代理等-warrning:需要进一步测试从0.13版开始,就包含了代理功能。代理实现使用pycurl,因此keep alive特性将被禁用。
除此之外,libaray还为一些aws服务提供了队列功能有限的支持:sqs和dyanmodb。
最后但并非最不重要的是,还提供了一个简单的资源池。
_龙卷风:http://www.tornado web.org/en/stable
…_保持活力:http://en.wikipedia.org/wiki/http_persistent_connection
…技术:http://chimera.labs.oreilly.com/books/1230000000545/ch11.html"Keepalive的优点"
…_代理服务器:http://en.wikipedia.org/wiki/proxy_server
示例
=代码块::python
from async_keep alive_httpc.keepalive_client import simplekeepalivehttpclient
st有一个简单的文本"a a a"。因此,b.txt有一个简单的文本
"bbb",c.txt中的"ccc"也有
ska_client.fetch('http://localhost/a.txt'),
ska_client.fetch('http://localhost/b.txt'),
ska_client.fetch('http://localhost/c.txt'),
断言a.body中的"aaa"r/>在b.body中断言"bbb"
在c.body中断言"ccc"
/>sqs
===
…代码块::python
from async_keepalive_httpc.aws.sqs import sqsqsqqueue
io_loop,
'aws_access_key',
'aws_secret_key',
'https://ap-souttheast-2.queue.amazonaws.com/your_account_number/your_queue_name',
endpoints=-ap-southeast-2')
r1=yield q.send('abc')
r2=yield q.send('cde')
r3=yield q.send('fgh')
assert r1.code==200
assert r2.code==200
assert r3.code==200
ODB
=
…代码块::python
{
‘用户id':{'s':'eeb750f4-c589-4c0a-95c3-c1b572a0cc3e'},
},
要获取的属性=['name']
)
aws的打印结果
代码块::python
{
"项":{
"数据":{
"s":"tom cruse"
}
}
}
代码块::python
from tornado.testing导入asynctestcase,gen-test
from async_keepalive_httpc.keepalive_client导入simplekeepalivehttpclient
from async_keepalive_httpc.pool导入resourcepool
class resourcepooltestcase(asynctcase):
@gen_test
def test_basic(self):
create_func=lambda:simplekeepalivehttpclient(self.io_loop)
pool=resourcepool(create_func,init_count=2,max_count=3)
self.assertequal(len(pool.pool),2
ska_client1=pool.get()
skaient1.fetch('http://www.google.com')
ska_client2=pool.get()
ska_client2.fetch('http://www.google.com')
ska_client3.fetch('http://www.google.com')
self.assertnotequal(ska_client1,ska_client3)
self.assertnotequal(ska_client2,ska_client3)
ska_client3.fetch('http://www.google.com')
ska_client4=pool.get()
self.assertequal(ska_client1,ska_client4)
使用代理
==
……代码块::python
from async_keepalive_httpc.aws.sqs import sqsqsqqueue
proxy_config={
'proxy_host':'localhost',
'proxy_port':3128,
}
q_url,
access_key=self.access_key,
secret_key=self.secret_key,
proxy_config=proxy_config)
yield sqs.send('my msg via proxy')
:作者:tom tang<;tly1980@gmail.com>;
:日期:…|日期
:描述:异步保持活动http客户端
keep-alive是一种众所周知的流行技术,它可以减少延迟并加快资源检索速度。
(请参见http://chimera.labs.oreilly.com/books/1230000000545/ch11.html keepalive的优点>;)
连接以请求多个资源,这可以避免建立和关闭http连接所带来的损失,对于https连接也非常重要。
tornado_u是一个高效的python异步web框架和网络库。
我非常喜欢使用它来构建高性能的Web应用程序。
然而,Tornado廑目前还没有一个支持开箱即用的HttpClient(2013年10月1日3.1.1版)。
rts的keep alive特性。
这个客户机基本上是tornado httpclient和httpconnection的黑客,所以api非常相似,
这意味着它可以使用tornado httprequest和原始客户机的大部分特性
(如gzip、代理等-warrning:需要进一步测试从0.13版开始,就包含了代理功能。代理实现使用pycurl,因此keep alive特性将被禁用。
除此之外,libaray还为一些aws服务提供了队列功能有限的支持:sqs和dyanmodb。
最后但并非最不重要的是,还提供了一个简单的资源池。
_龙卷风:http://www.tornado web.org/en/stable
…_保持活力:http://en.wikipedia.org/wiki/http_persistent_connection
…技术:http://chimera.labs.oreilly.com/books/1230000000545/ch11.html"Keepalive的优点"
…_代理服务器:http://en.wikipedia.org/wiki/proxy_server
示例
=代码块::python
from async_keep alive_httpc.keepalive_client import simplekeepalivehttpclient
st有一个简单的文本"a a a"。因此,b.txt有一个简单的文本
"bbb",c.txt中的"ccc"也有
ska_client.fetch('http://localhost/a.txt'),
ska_client.fetch('http://localhost/b.txt'),
ska_client.fetch('http://localhost/c.txt'),
断言a.body中的"aaa"r/>在b.body中断言"bbb"
在c.body中断言"ccc"
/>sqs
===
…代码块::python
from async_keepalive_httpc.aws.sqs import sqsqsqqueue
io_loop,
'aws_access_key',
'aws_secret_key',
'https://ap-souttheast-2.queue.amazonaws.com/your_account_number/your_queue_name',
endpoints=-ap-southeast-2')
r1=yield q.send('abc')
r2=yield q.send('cde')
r3=yield q.send('fgh')
assert r1.code==200
assert r2.code==200
assert r3.code==200
ODB
=
…代码块::python
{
‘用户id':{'s':'eeb750f4-c589-4c0a-95c3-c1b572a0cc3e'},
},
要获取的属性=['name']
)
aws的打印结果
代码块::python
{
"项":{
"数据":{
"s":"tom cruse"
}
}
}
代码块::python
from tornado.testing导入asynctestcase,gen-test
from async_keepalive_httpc.keepalive_client导入simplekeepalivehttpclient
from async_keepalive_httpc.pool导入resourcepool
class resourcepooltestcase(asynctcase):
@gen_test
def test_basic(self):
create_func=lambda:simplekeepalivehttpclient(self.io_loop)
pool=resourcepool(create_func,init_count=2,max_count=3)
self.assertequal(len(pool.pool),2
ska_client1=pool.get()
skaient1.fetch('http://www.google.com')
ska_client2=pool.get()
ska_client2.fetch('http://www.google.com')
ska_client3.fetch('http://www.google.com')
self.assertnotequal(ska_client1,ska_client3)
self.assertnotequal(ska_client2,ska_client3)
ska_client4=pool.get()
self.assertequal(ska_client1,ska_client4)
使用代理
==
……代码块::python
from async_keepalive_httpc.aws.sqs import sqsqsqqueue
proxy_config={
'proxy_host':'localhost',
'proxy_port':3128,
}
access_key=self.access_key,
secret_key=self.secret_key,
proxy_config=proxy_config)
yield sqs.send('my msg via proxy')