Skip to content

Commit 3c5d07b

Browse files
authored
Merge pull request #27 from 2530901689/master
连接池优化
2 parents 1405004 + 068139f commit 3c5d07b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

ufile/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
UCLOUD_DOWNLOAD_SUFFIX = '.cn-bj.ufileos.com'
1313
UCLOUD_API_URL = 'http://api.ucloud.cn'
1414
BLOCKSIZE = 1024 * 1024 * 4
15+
CONNECTION_POOL_SIZE = 10
1516

1617
_config = {
1718
'connection_timeout': None,

ufile/httprequest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22

33
import re
44

5-
import requests
5+
from requests import Session, RequestException
6+
from requests.adapters import HTTPAdapter
67

78
from . import config
89
from .logger import logger
910

11+
requests = Session()
12+
requests.mount("http://",
13+
HTTPAdapter(pool_connections=config.CONNECTION_POOL_SIZE, pool_maxsize=config.CONNECTION_POOL_SIZE))
14+
requests.mount("https://",
15+
HTTPAdapter(pool_connections=config.CONNECTION_POOL_SIZE, pool_maxsize=config.CONNECTION_POOL_SIZE))
16+
1017

1118
def __return_wraper(response, content_consumed=False):
1219
"""

0 commit comments

Comments
 (0)