Skip to content

Commit

Permalink
update doc & news
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitc committed Nov 25, 2010
1 parent a2a63a0 commit 3f978d5
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 35 deletions.
21 changes: 21 additions & 0 deletions doc/news.rst
Expand Up @@ -3,6 +3,27 @@
News News
==== ====


2.3.0 / 2010-11-25
------------------
- Refactored Http Connections management (reuse connections).
restkit.pool is now replaced by restkit.conn module. SimplePool has
been replaced by TConnectionManager (threadsafe). Now by default all
connections are reusing connections using TConnectionManager (10
connections per route).
- Improved Gevent & Eventlet support
- Added an ``decompress`` option to ``request`` function and ``Resource``
instance to decompress the body or not. By default it's true.
- Added ``params_dict`` to keywords arguments of ``Resource`` instances
methods. Allows you to pass any argument to the query.
- Fix response 100-continue
- Fix compressed atatchments
- Fix body readline
- Fix basic authentication
- Stop when system exit or keyboard interrupt
- Fix oauth2

More details `here <https://github.com/benoitc/restkit/compare/2.1.1...2.1.3>`_ .

2.2.1 / 2010-09-18 2.2.1 / 2010-09-18
------------------ ------------------
- Fix readline `b7365155 <http://github.com/benoitc/restkit/commit/b7365155168cc9df7e48edabad79b2c478e8c5c7>`_ . - Fix readline `b7365155 <http://github.com/benoitc/restkit/commit/b7365155168cc9df7e48edabad79b2c478e8c5c7>`_ .
Expand Down
32 changes: 16 additions & 16 deletions doc/pool.rst
@@ -1,33 +1,33 @@
Reuses connections Reuses connections
================== ==================


Reusing connections is good. Restkit can maintain for you the http connections and reuse them if the server allows it. To do that you can pass to any object a pool instance inheriting :api:`reskit.pool.PoolInterface`. You can use our threadsafe pool in any application:: Reusing connections is good. Restkit can maintain for you the http connections and reuse them if the server allows it. To do that you can pass to any object a connection manager instance inheriting :api:`reskit.conn.base.ConnManager`. You can use our threadsafe pool in any application::




from restkit import Resource, SimplePool from restkit import Resource, TConnectionManager
pool = SimplePool(keepalive=2) manager = TConnectionManager(nb_connections=10)
res = Resource('http://friendpaste.com', pool_instance=pool) res = Resource('http://friendpaste.com', conn_manager=manager)

.. NOTE::

By default, restkit is using the threadsafe connections manager
and keep 10 connections alive.


Restkit provides also Pool working with `eventlet <http://eventlet.net>`_ or `gevent <http://gevent.net>`_. Restkit provides also Pool working with `eventlet <http://eventlet.net>`_ or `gevent <http://gevent.net>`_.


Example of usage with Gevent:: Example of usage with Gevent::


from restkit import * from restkit import request
from gevent import monkey; monkey.patch_socket() from restkit.conn.gevent_manager import GeventConnectionManager
from restkit.pool.rgevent import GeventPool manager = GeventConnectionManager(timeout=300, nb_connections=10)
pool = GeventPool(keepalive=2, timeout=300) r = request('http://friendpaste.com', conn_manager=manager)
r = request('http://friendpaste.com', pool_instance=pool)


This is likely the same with Eventlet:: This is likely the same with Eventlet::


import eventlet
eventlet.monkey_patch(all=False, socket=True, select=True)
from restkit import Resource from restkit import Resource
from restkit.pool.reventlet import EventletPool from restkit.conn.eventlet_manager import EventletConnectionManager
pool = EventletPool(keepalive=2, timeout=300) manager = EventletConnectionManager(timeout=300, nb_connections=300)
res = Resource('http://friendpaste.com', pool_instance=pool) res = Resource('http://friendpaste.com', conn_manager=manager)
Using `Eventlet` or `Gevent` pools is definitely better since it allows you to define a timeout for connections. When timeout is reached and the connection is still in the pool, it will be closed.
8 changes: 3 additions & 5 deletions doc/resource.rst
Expand Up @@ -19,19 +19,17 @@ Here is the snippet::
class TwitterSearch(Resource): class TwitterSearch(Resource):
def __init__(self, pool_instance=None, **kwargs): def __init__(self, **kwargs):
search_url = "http://search.twitter.com" search_url = "http://search.twitter.com"
super(TwitterSearch, self).__init__(search_url, follow_redirect=True, super(TwitterSearch, self).__init__(search_url, follow_redirect=True,
max_follow_redirect=10, max_follow_redirect=10, **kwargs)
pool_instance=pool_instance,
**kwargs)


def search(self, query): def search(self, query):
return self.get('search.json', q=query) return self.get('search.json', q=query)
def request(self, *args, **kwargs): def request(self, *args, **kwargs):
resp = super(TwitterSearch, self).request(*args, **kwargs) resp = super(TwitterSearch, self).request(*args, **kwargs)
return json.loads(resp.body) return json.loads(resp.body_string())
if __name__ == "__main__": if __name__ == "__main__":
s = TwitterSearch() s = TwitterSearch()
Expand Down
13 changes: 7 additions & 6 deletions doc/wsgi_proxy.rst
Expand Up @@ -16,11 +16,11 @@ use `webob <http://pythonpaste.org/webob/>`_ and `gunicorn
import urlparse import urlparse


from webob import Request from webob import Request
from restkit.pool.simple import SimplePool from restkit.conn import TConnectionManager
from restkit.ext.wsgi_proxy import HostProxy from restkit.ext.wsgi_proxy import HostProxy


pool = SimplePool(keepalive=10) mgr = TConnectionManager(nb_connections=10)
proxy = HostProxy("http://127.0.0.1:5984", pool=pool) proxy = HostProxy("http://127.0.0.1:5984", pool=mgr)




def application(environ, start_response): def application(environ, start_response):
Expand Down Expand Up @@ -59,11 +59,12 @@ distributed proxy. `/a/db` will proxify `http://a.mypool.org/db`::
import urlparse import urlparse


from webob import Request from webob import Request
from restkit.pool.simple import SimplePool from restkit.conn import TConnectionManager
from restkit.ext.wsgi_proxy import Proxy from restkit.ext.wsgi_proxy import Proxy


pool = SimplePool(keepalive=10) mgr = TConnectionManager(nb_connections=10)
proxy = Proxy(pool=pool, strip_script_name=True)
proxy = Proxy(pool=mgr, strip_script_name=True)




def application(environ, start_response): def application(environ, start_response):
Expand Down
16 changes: 8 additions & 8 deletions restkit/client/request.py
Expand Up @@ -50,7 +50,7 @@ def __init__(self,
decompress=True, decompress=True,
pool_instance=None, pool_instance=None,
response_class=None, response_class=None,
connection_manager=None, conn_manager=None,
**ssl_args): **ssl_args):


""" HttpRequest constructor """ HttpRequest constructor
Expand All @@ -63,8 +63,8 @@ def __init__(self,
the location. the location.
:param max_follow_redirect: max number of redirection. If max is reached :param max_follow_redirect: max number of redirection. If max is reached
the RedirectLimit exception is raised. the RedirectLimit exception is raised.
:param pool_instance: a pool instance inherited from :param conn_manager: a connectoin manager instance inherited from
`restkit.pool.PoolInterface` `restkit.conn.base.ConnectioManager`
:param ssl_args: ssl arguments. See http://docs.python.org/library/ssl.html :param ssl_args: ssl arguments. See http://docs.python.org/library/ssl.html
for more information. for more information.
""" """
Expand All @@ -89,11 +89,11 @@ def __init__(self,
self.ssl_args = ssl_args or {} self.ssl_args = ssl_args or {}


if pool_instance is not None: if pool_instance is not None:
self.connection_manager = pool_instance self.conn_manager = pool_instance
elif connection_manager is not None: elif conn_manager is not None:
self.connection_manager = connection_manager self.conn_manager = conn_manager
else: else:
self.connection_manager = get_default_manager() self.conn_manager = get_default_manager()


if response_class is not None: if response_class is not None:
self.response_class = response_class self.response_class = response_class
Expand Down Expand Up @@ -268,7 +268,7 @@ def do_send(self):
addr = (self.host, self.port) addr = (self.host, self.port)
is_ssl = (self.uri.scheme == "https") is_ssl = (self.uri.scheme == "https")
route = (addr, is_ssl, self.filters, self.ssl_args) route = (addr, is_ssl, self.filters, self.ssl_args)
self._pool = self.connection_manager.get_pool(route) self._pool = self.conn_manager.get_pool(route)
tries = 2 tries = 2
while True: while True:
try: try:
Expand Down

0 comments on commit 3f978d5

Please sign in to comment.