Skip to content

Commit

Permalink
feat: configurable limit of simultaneous connections (python/asyncio) (
Browse files Browse the repository at this point in the history
…OpenAPITools#3200)

* feat: configurable limit of simultaneous connections (python/asyncio)

* fix: remove unused import (python/asyncio)
  • Loading branch information
tomplus authored and wing328 committed Jun 25, 2019
1 parent f681764 commit 5b9283b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ class RESTResponse(io.IOBase):

class RESTClientObject(object):

def __init__(self, configuration, pools_size=4, maxsize=4):
def __init__(self, configuration, pools_size=4, maxsize=None):

# maxsize is number of requests to host that are allowed in parallel
if maxsize is None:
maxsize = configuration.connection_pool_maxsize

# ca_certs
if configuration.ssl_ca_cert:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ from __future__ import absolute_import

import copy
import logging
{{^asyncio}}
import multiprocessing
{{/asyncio}}
import sys
import urllib3

Expand Down Expand Up @@ -116,13 +118,21 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
"""Set this to True/False to enable/disable SSL hostname verification.
"""

{{#asyncio}}
self.connection_pool_maxsize = 100
"""This value is passed to the aiohttp to limit simultaneous connections.
Default values is 100, None means no-limit.
"""
{{/asyncio}}
{{^asyncio}}
self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
"""urllib3 connection pool's maximum number of connections saved
per pool. urllib3 uses 1 connection as default value, but this is
not the best value when you are making a lot of possibly parallel
requests to the same host, which is often the case here.
cpu_count * 5 is used as default value to increase performance.
"""
{{/asyncio}}

self.proxy = None
"""Proxy URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import copy
import logging
import multiprocessing
import sys
import urllib3

Expand Down Expand Up @@ -115,12 +114,9 @@ def __init__(self, host="http://petstore.swagger.io:80/v2",
"""Set this to True/False to enable/disable SSL hostname verification.
"""

self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
"""urllib3 connection pool's maximum number of connections saved
per pool. urllib3 uses 1 connection as default value, but this is
not the best value when you are making a lot of possibly parallel
requests to the same host, which is often the case here.
cpu_count * 5 is used as default value to increase performance.
self.connection_pool_maxsize = 100
"""This value is passed to the aiohttp to limit simultaneous connections.
Default values is 100, None means no-limit.
"""

self.proxy = None
Expand Down
5 changes: 4 additions & 1 deletion samples/client/petstore/python-asyncio/petstore_api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ def getheader(self, name, default=None):

class RESTClientObject(object):

def __init__(self, configuration, pools_size=4, maxsize=4):
def __init__(self, configuration, pools_size=4, maxsize=None):

# maxsize is number of requests to host that are allowed in parallel
if maxsize is None:
maxsize = configuration.connection_pool_maxsize

# ca_certs
if configuration.ssl_ca_cert:
Expand Down

0 comments on commit 5b9283b

Please sign in to comment.