即使對於EC2實例上的少量數據,使用boto3寫入S3(也許是所有操作)需要大約300ms。寫入S3的消息時間
分析表明時間以閱讀爲主,例如_SSLSocket.read()
- 可能在建立安全連接時或僅僅是爲了服務器響應時。
有什麼辦法可以減少手術時間嗎?也許有一個可以使用的較低級別的API調用?
%prun -s time client.put_object(Bucket='MDtemp', Key='temporary2', Body=b'Hello')
2197 function calls (2188 primitive calls) in 0.094 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.045 0.045 0.045 0.045 {built-in method select}
26 0.045 0.002 0.045 0.002 {method 'read' of '_ssl._SSLSocket' objects}
2 0.000 0.000 0.000 0.000 {method 'write' of '_ssl._SSLSocket' objects}
26 0.000 0.000 0.045 0.002 socket.py:364(readinto)
2 0.000 0.000 0.000 0.000 socket.py:200(makefile)
26 0.000 0.000 0.045 0.002 ssl.py:737(recv_into)
27 0.000 0.000 0.000 0.000 message.py:463(get)
1 0.000 0.000 0.001 0.001 awsrequest.py:195(_handle_expect_response)
2 0.000 0.000 0.000 0.000 {method 'readline' of '_io._IOBase' objects}
8/6 0.000 0.000 0.001 0.000 hooks.py:175(_emit)
2 0.000 0.000 0.000 0.000 socket.py:352(__init__)
245 0.000 0.000 0.000 0.000 {method 'lower' of 'str' objects}
1 0.000 0.000 0.092 0.092 connectionpool.py:317(_make_request)
1 0.000 0.000 0.093 0.093 sessions.py:539(send)
26 0.000 0.000 0.045 0.002 ssl.py:611(read)
3 0.000 0.000 0.000 0.000 _collections_abc.py:575(update)
8 0.000 0.000 0.045 0.006 {method 'readline' of '_io.BufferedReader' objects}
2 0.000 0.000 0.000 0.000 feedparser.py:217(_parsegen)
150 0.000 0.000 0.000 0.000 {built-in method isinstance}
1 0.000 0.000 0.000 0.000 parsers.py:639(_parse_non_payload_attrs)
8 0.000 0.000 0.000 0.000 client.py:1092(putheader)
1 0.000 0.000 0.000 0.000 feedparser.py:470(_parse_headers)
1 0.000 0.000 0.000 0.000 client.py:284(parse_headers)
7 0.000 0.000 0.000 0.000 parse.py:286(urlparse)
23 0.000 0.000 0.000 0.000 parse.py:98(_coerce_args)
27 0.000 0.000 0.000 0.000 socket.py:405(readable)
1 0.000 0.000 0.094 0.094 {built-in method exec}
40 0.000 0.000 0.000 0.000 _policybase.py:269(_sanitize_header)
1 0.000 0.000 0.046 0.046 awsrequest.py:146(_send_output)
1 0.000 0.000 0.000 0.000 auth.py:532(canonical_standard_headers)
1 0.000 0.000 0.045 0.045 client.py:347(_read_status)
...
大時間食客將成爲SSL握手。在其他環境中(這裏不是python用戶),HTTP keep-alives幫助我通過重用連接來緩解跨多個請求的安裝成本...但是從S3內的同一區域內的EC2內部,300毫秒仍然有點呆滯。我會看看我有沒有什麼可比較的,這可能有助於將S3本身作爲一個重要的貢獻者。我知道我可以使用異步I/O寫入的工具之一在〜2秒內發送和接收1000個HEAD請求,但現在我不記得它是否是HTTPS。 –
您的實例與存儲桶位於同一區域嗎?事實證明,在一個區域內SSL握手的時間可以忽略不計,因爲往返時間非常短(ping時間<0.2ms,使用彈性IP)。跨區域,測試us-west-2(客戶端)到us-east-1(桶)我在第一個請求(容易歸因於SSL協商)下獲得〜380ms的時間,活着的連接。 –
所以我們每次都必須建立一個新的連接。你如何建立一個保持連接的連接? – mdurant