写入S3

时间:2016-05-02 17:58:09

标签: python amazon-s3 boto boto3

使用boto3写入S3(可能还有所有操作)大约需要300毫秒,即使对于EC2实例上的少量数据也是如此。

分析显示时间由读数控制,例如_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)
        ...

3 个答案:

答案 0 :(得分:0)

您可以使用BASH完成此操作,您必须呼叫外部应用程序,例如AWS命令行界面(CLI)。

访问:http://docs.aws.amazon.com/cli/latest/reference/s3/

答案 1 :(得分:0)

您是否考虑过使用s3cmd?它是linux的命令行工具,非常有效,但我从未测量过它的性能。

答案 2 :(得分:0)

s3fs现在使用aiobotocore库支持asynchronous operations。这样可以重用连接并启用并发,因此可以在许多呼叫中分摊等待时间,从而大大降低了平均延迟。如果尚未建立SSL连接,则单个呼叫的总时间不会受到太大影响。