forked from benoitc/restkit
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
benoitc
committed
Nov 25, 2010
1 parent
a2a63a0
commit 3f978d5
Showing
5 changed files
with
55 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters