Skip to content

Cache locations to improve list_images performance#544

Closed
relaxdiego wants to merge 1 commit intoapache:trunkfrom
relaxdiego:optimize_list_images
Closed

Cache locations to improve list_images performance#544
relaxdiego wants to merge 1 commit intoapache:trunkfrom
relaxdiego:optimize_list_images

Conversation

@relaxdiego
Copy link
Copy Markdown
Contributor

This change caches the locations in a private attribute to avoid
repeated calls for the same result set. The number of calls made is
directly proportional to the number of images returned. For a 223
result set, this can reach as high as 99.990 seconds. Caching the
locations reduces it to around 2.001 seconds. The risk of stale location
data during execution is negligible.

This change caches the locations in a private attribute to avoid
repeated calls for the same result set. The number of calls made is
directly proportional to the number of images returned. For a 223
result set, this can reach as high as 99.990 seconds. Caching the
locations reduces it to around 2.001 seconds. The risk of stale location
data during execution is negligible.
@relaxdiego
Copy link
Copy Markdown
Contributor Author

cProfile output of the code:

Driver = get_driver(Provider.DIMENSIONDATA)
conn = Driver(username, password)

import cProfile
cProfile.run('conn.list_images()')

BEFORE:

         860470 function calls (860021 primitive calls) in 99.990 seconds

   Ordered by: standard name

     ncalls  tottime  percall  cumtime  percall filename:lineno(function)
          1    0.000    0.000   99.990   99.990 <string>:1(<module>)
       6246    0.002    0.000    0.002    0.000 ElementPath.py:239(__init__)
       6246    0.016    0.000    0.018    0.000 ElementPath.py:247(iterfind)
        224    0.002    0.000    0.006    0.000 ElementPath.py:292(findall)
       6022    0.016    0.000    0.059    0.000 ElementPath.py:298(findtext)
         40    0.000    0.000    0.000    0.000 ElementPath.py:73(xpath_tokenizer)
         20    0.000    0.000    0.000    0.000 ElementPath.py:96(prepare_child)
14275/13829    0.022    0.000    0.029    0.000 ElementPath.py:98(select)
        225    0.002    0.000    0.415    0.002 ElementTree.py:1297(XML)
        225    0.001    0.000    0.001    0.000 ElementTree.py:1367(__init__)
        225    0.000    0.000    0.000    0.000 ElementTree.py:1383(close)
      24578    0.042    0.000    0.047    0.000 ElementTree.py:1388(_flush)
      24352    0.012    0.000    0.019    0.000 ElementTree.py:1406(data)
      12289    0.038    0.000    0.106    0.000 ElementTree.py:1417(start)
      12289    0.017    0.000    0.043    0.000 ElementTree.py:1433(end)
        225    0.011    0.000    0.012    0.000 ElementTree.py:1457(__init__)
      26387    0.014    0.000    0.048    0.000 ElementTree.py:1508(_fixtext)
      24578    0.024    0.000    0.029    0.000 ElementTree.py:1515(_fixname)
      12289    0.019    0.000    0.149    0.000 ElementTree.py:1535(_start_list)
      24352    0.024    0.000    0.086    0.000 ElementTree.py:1545(_data)
      12289    0.012    0.000    0.060    0.000 ElementTree.py:1548(_end)
        450    0.002    0.000    0.002    0.000 ElementTree.py:1567(_default)
        225    0.001    0.000    0.399    0.002 ElementTree.py:1638(feed)
        225    0.001    0.000    0.002    0.000 ElementTree.py:1650(close)
      12289    0.018    0.000    0.031    0.000 ElementTree.py:207(__init__)
      27439    0.007    0.000    0.007    0.000 ElementTree.py:265(__getitem__)
      12064    0.006    0.000    0.010    0.000 ElementTree.py:300(append)
       6022    0.004    0.000    0.064    0.000 ElementTree.py:377(findtext)
        224    0.000    0.000    0.007    0.000 ElementTree.py:389(findall)
        225    0.001    0.000    0.001    0.000 UserDict.py:58(get)
        225    0.000    0.000    0.000    0.000 UserDict.py:70(__contains__)
        225    0.004    0.000    0.015    0.000 __init__.py:11(_dnsname_match)
        225    0.002    0.000    0.017    0.000 __init__.py:64(match_hostname)
        225    0.001    0.000    0.001    0.000 base.py:143(success)
        225    0.001    0.000    0.002    0.000 base.py:155(_decompress_response)
        225    0.001    0.000    0.416    0.002 base.py:206(parse_body)
        223    0.001    0.000    0.001    0.000 base.py:356(__init__)
       1115    0.002    0.000    0.002    0.000 base.py:393(__init__)
        225    0.000    0.000    0.000    0.000 base.py:518(reset_context)
        225    0.003    0.000    0.035    0.000 base.py:548(connect)
        225    0.001    0.000    0.001    0.000 base.py:608(_user_agent)
        225    0.007    0.000   99.868    0.444 base.py:633(request)
        225    0.000    0.000    0.000    0.000 base.py:764(morph_action_hook)
        225    0.000    0.000    0.000    0.000 base.py:767(add_default_params)
        225    0.000    0.000    0.000    0.000 base.py:785(pre_connect_hook)
        225    0.005    0.000    1.930    0.009 base.py:86(__init__)
        223    0.000    0.000    0.000    0.000 base.py:87(__init__)
        225    0.001    0.000    0.001    0.000 base64.py:42(b64encode)
        225    0.002    0.000    0.005    0.000 dimensiondata.py:156(add_default_headers)
          2    0.000    0.000    2.406    1.203 dimensiondata.py:162(request)
        223    0.003    0.000   97.949    0.439 dimensiondata.py:171(request_with_orgId)
        223    0.001    0.000    0.484    0.002 dimensiondata.py:180(get_resource_path)
        223    0.000    0.000    0.483    0.002 dimensiondata.py:189(_get_orgId)
          1    0.000    0.000   99.989   99.989 dimensiondata.py:388(list_images)
        223    0.001    0.000   98.013    0.440 dimensiondata.py:410(list_locations)
          1    0.000    0.000   98.066   98.066 dimensiondata.py:435(_to_base_images)
        223    0.004    0.000   98.065    0.440 dimensiondata.py:442(_to_base_image)
        223    0.001    0.000   98.016    0.440 dimensiondata.py:530(ex_get_location_by_id)
       1115    0.000    0.000    0.000    0.000 dimensiondata.py:542(<lambda>)
        223    0.002    0.000    0.063    0.000 dimensiondata.py:573(_to_locations)
       1115    0.005    0.000    0.052    0.000 dimensiondata.py:580(_to_location)
       1350    0.004    0.000    0.017    0.000 genericpath.py:15(exists)
        225    0.001    0.000    0.002    0.000 genericpath.py:26(isfile)
        225    0.004    0.000   57.861    0.257 httplib.py:1014(_send_request)
        225    0.004    0.000   40.026    0.178 httplib.py:1031(getresponse)
        225    0.001    0.000    0.004    0.000 httplib.py:1182(__init__)
       1125    0.002    0.000    0.002    0.000 httplib.py:220(addheader)
        225    0.011    0.000    0.270    0.001 httplib.py:234(readheaders)
        225    0.001    0.000    0.005    0.000 httplib.py:335(__init__)
        225    0.004    0.000   39.729    0.177 httplib.py:363(_read_status)
        225    0.005    0.000   40.015    0.178 httplib.py:402(begin)
        225    0.001    0.000    0.001    0.000 httplib.py:488(_check_close)
        225    0.002    0.000    0.909    0.004 httplib.py:518(close)
        225    0.001    0.000    1.501    0.007 httplib.py:534(read)
        225    0.005    0.000    1.500    0.007 httplib.py:579(_read_chunked)
        488    0.002    0.000    0.566    0.001 httplib.py:637(_safe_read)
        225    0.000    0.000    0.001    0.000 httplib.py:673(getheaders)
        225    0.002    0.000    0.002    0.000 httplib.py:691(__init__)
        225    0.000    0.000    0.000    0.000 httplib.py:737(_get_hostport)
        225    0.001    0.000    0.001    0.000 httplib.py:792(close)
        225    0.003    0.000   57.846    0.257 httplib.py:802(send)
       1350    0.001    0.000    0.001    0.000 httplib.py:822(_output)
        225    0.002    0.000   57.848    0.257 httplib.py:829(_send_output)
        225    0.001    0.000    0.002    0.000 httplib.py:850(putrequest)
       1125    0.003    0.000    0.005    0.000 httplib.py:967(putheader)
        225    0.001    0.000   57.849    0.257 httplib.py:978(endheaders)
        225    0.001    0.000   57.862    0.257 httplib.py:993(request)
        225    0.001    0.000    0.002    0.000 httplib.py:997(_set_content_length)
        225    0.002    0.000    0.030    0.000 httplib_ssl.py:202(__init__)
        225    0.001    0.000    0.024    0.000 httplib_ssl.py:216(_setup_verify)
        225    0.004    0.000    0.023    0.000 httplib_ssl.py:231(_setup_ca_cert)
        225    0.010    0.000   57.826    0.257 httplib_ssl.py:252(connect)
        225    0.003    0.000    0.279    0.001 mimetools.py:24(__init__)
        225    0.002    0.000    0.003    0.000 mimetools.py:33(parsetype)
        225    0.000    0.000    0.000    0.000 mimetools.py:50(parseplist)
        225    0.002    0.000    0.003    0.000 misc.py:244(lowercase_keys)
       1350    0.001    0.000    0.001    0.000 misc.py:245(<genexpr>)
      24352    0.013    0.000    0.099    0.000 pyexpat.c:441(CharacterData)
      12289    0.009    0.000    0.158    0.000 pyexpat.c:566(StartElement)
      12289    0.006    0.000    0.066    0.000 pyexpat.c:618(EndElement)
        450    0.001    0.000    0.002    0.000 pyexpat.c:839(DefaultHandlerExpand)
        225    0.000    0.000    0.002    0.000 re.py:188(compile)
        450    0.005    0.000    0.005    0.000 re.py:204(escape)
        225    0.001    0.000    0.002    0.000 re.py:226(_compile)
       1125    0.002    0.000    0.003    0.000 rfc822.py:197(isheader)
       1350    0.001    0.000    0.001    0.000 rfc822.py:209(islast)
       1350    0.000    0.000    0.000    0.000 rfc822.py:219(iscomment)
       1350    0.001    0.000    0.003    0.000 rfc822.py:285(getheader)
        225    0.000    0.000    0.001    0.000 rfc822.py:454(items)
        225    0.001    0.000    0.271    0.001 rfc822.py:88(__init__)
        450    0.009    0.000    0.014    0.000 socket.py:185(__init__)
        225    0.014    0.000    0.015    0.000 socket.py:192(close)
        675    0.005    0.000   16.954    0.025 socket.py:223(meth)
        225    0.002    0.000    0.002    0.000 socket.py:246(__init__)
        450    0.003    0.000    0.905    0.002 socket.py:276(close)
        225    0.002    0.000    0.003    0.000 socket.py:285(__del__)
        225    0.000    0.000    0.000    0.000 socket.py:292(flush)
        488    0.005    0.000    0.563    0.001 socket.py:336(read)
       2269    0.148    0.000   39.994    0.018 socket.py:406(readline)
        225    0.006    0.000   17.393    0.077 socket.py:537(create_connection)
        2/1    0.000    0.000    0.000    0.000 sre_compile.py:32(_compile)
          1    0.000    0.000    0.000    0.000 sre_compile.py:354(_simple)
          1    0.000    0.000    0.000    0.000 sre_compile.py:359(_compile_info)
          2    0.000    0.000    0.000    0.000 sre_compile.py:472(isstring)
          1    0.000    0.000    0.000    0.000 sre_compile.py:478(_code)
          1    0.000    0.000    0.000    0.000 sre_compile.py:493(compile)
          4    0.000    0.000    0.000    0.000 sre_parse.py:126(__len__)
          6    0.000    0.000    0.000    0.000 sre_parse.py:130(__getitem__)
          1    0.000    0.000    0.000    0.000 sre_parse.py:134(__setitem__)
         21    0.000    0.000    0.000    0.000 sre_parse.py:138(append)
        3/2    0.000    0.000    0.000    0.000 sre_parse.py:140(getwidth)
          1    0.000    0.000    0.000    0.000 sre_parse.py:178(__init__)
         28    0.000    0.000    0.000    0.000 sre_parse.py:182(__next)
          4    0.000    0.000    0.000    0.000 sre_parse.py:195(match)
         26    0.000    0.000    0.000    0.000 sre_parse.py:201(get)
          4    0.000    0.000    0.000    0.000 sre_parse.py:257(_escape)
          1    0.000    0.000    0.000    0.000 sre_parse.py:301(_parse_sub)
          1    0.000    0.000    0.000    0.000 sre_parse.py:379(_parse)
          1    0.000    0.000    0.000    0.000 sre_parse.py:67(__init__)
          1    0.000    0.000    0.000    0.000 sre_parse.py:677(parse)
          2    0.000    0.000    0.000    0.000 sre_parse.py:90(__init__)
        225    0.016    0.000   40.380    0.179 ssl.py:107(__init__)
      47288    0.034    0.000   40.277    0.001 ssl.py:159(read)
        225    0.001    0.000    0.019    0.000 ssl.py:179(getpeercert)
        225    0.001    0.000    0.016    0.000 ssl.py:195(send)
        225    0.001    0.000    0.017    0.000 ssl.py:225(sendall)
      47288    0.037    0.000   40.314    0.001 ssl.py:240(recv)
        450    0.888    0.002    0.903    0.002 ssl.py:299(close)
        225    0.002    0.000   36.056    0.160 ssl.py:306(do_handshake)
        225    0.002    0.000    0.004    0.000 ssl.py:368(makefile)
        225    0.006    0.000   40.387    0.179 ssl.py:381(wrap_socket)
        225    0.000    0.000    0.000    0.000 stat.py:24(S_IFMT)
        225    0.000    0.000    0.001    0.000 stat.py:49(S_ISREG)
        225    0.000    0.000    0.001    0.000 utf_8.py:15(decode)
       6246    0.015    0.000    0.020    0.000 xml.py:24(fixxpath)
       6022    0.008    0.000    0.091    0.000 xml.py:32(findtext)
        225    0.001    0.000    0.001    0.000 {_codecs.utf_8_decode}
        225    0.442    0.002    0.442    0.002 {_socket.getaddrinfo}
          1    0.000    0.000    0.000    0.000 {_sre.compile}
         19    0.000    0.000    0.000    0.000 {_sre.getlower}
        225    4.284    0.019    4.284    0.019 {_ssl.sslwrap}
        225    0.001    0.000    0.001    0.000 {binascii.b2a_base64}
        450    0.073    0.000    0.398    0.001 {built-in method Parse}
        225   36.055    0.160   36.055    0.160 {built-in method do_handshake}
        225    0.000    0.000    0.000    0.000 {built-in method fromkeys}
        225    0.018    0.000    0.018    0.000 {built-in method peer_certificate}
      47288   40.243    0.001   40.243    0.001 {built-in method read}
        225    0.014    0.000    0.014    0.000 {built-in method write}
       2982    0.002    0.000    0.002    0.000 {cStringIO.StringIO}
       1350    0.001    0.000    0.001    0.000 {delattr}
        223    0.001    0.000    0.001    0.000 {filter}
       4050    0.004    0.000    0.004    0.000 {getattr}
       1800    0.003    0.000    0.003    0.000 {hasattr}
        234    0.000    0.000    0.000    0.000 {isinstance}
         18    0.000    0.000    0.000    0.000 {iter}
50112/50111    0.008    0.000    0.008    0.000 {len}
        488    0.000    0.000    0.000    0.000 {max}
      54022    0.014    0.000    0.014    0.000 {method 'append' of 'list' objects}
        225   16.936    0.075   16.936    0.075 {method 'connect' of '_socket.socket' objects}
      12289    0.007    0.000    0.007    0.000 {method 'copy' of 'dict' objects}
        225    0.000    0.000    0.000    0.000 {method 'count' of 'str' objects}
        225    0.001    0.000    0.002    0.000 {method 'decode' of 'str' objects}
          1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
      26387    0.034    0.000    0.034    0.000 {method 'encode' of 'unicode' objects}
        225    0.000    0.000    0.000    0.000 {method 'extend' of 'list' objects}
      47832    0.028    0.000    0.028    0.000 {method 'find' of 'str' objects}
         18    0.000    0.000    0.000    0.000 {method 'findall' of '_sre.SRE_Pattern' objects}
       3156    0.002    0.000    0.002    0.000 {method 'get' of 'dict' objects}
        225    0.008    0.000    0.008    0.000 {method 'getpeername' of '_socket.socket' objects}
        225    0.004    0.000    0.004    0.000 {method 'getsockopt' of '_socket.socket' objects}
       2512    0.001    0.000    0.001    0.000 {method 'getvalue' of 'cStringIO.StringO' objects}
        451    0.000    0.000    0.000    0.000 {method 'items' of 'dict' objects}
        225    0.000    0.000    0.000    0.000 {method 'iteritems' of 'dict' objects}
      34011    0.007    0.000    0.007    0.000 {method 'join' of 'str' objects}
       5400    0.003    0.000    0.003    0.000 {method 'lower' of 'str' objects}
        225    0.001    0.000    0.001    0.000 {method 'match' of '_sre.SRE_Pattern' objects}
        225    0.000    0.000    0.000    0.000 {method 'pop' of 'dict' objects}
      12289    0.005    0.000    0.005    0.000 {method 'pop' of 'list' objects}
       5026    0.003    0.000    0.003    0.000 {method 'seek' of 'cStringIO.StringO' objects}
       6921    0.006    0.000    0.006    0.000 {method 'split' of 'str' objects}
        675    0.001    0.000    0.001    0.000 {method 'startswith' of 'str' objects}
       2025    0.001    0.000    0.001    0.000 {method 'strip' of 'str' objects}
       5026    0.001    0.000    0.001    0.000 {method 'tell' of 'cStringIO.StringO' objects}
      13414    0.007    0.000    0.007    0.000 {method 'update' of 'dict' objects}
        225    0.000    0.000    0.000    0.000 {method 'upper' of 'str' objects}
      49312    0.048    0.000    0.048    0.000 {method 'write' of 'cStringIO.StringO' objects}
        492    0.001    0.000    0.001    0.000 {min}
         19    0.000    0.000    0.000    0.000 {ord}
       1575    0.014    0.000    0.014    0.000 {posix.stat}
        225    0.001    0.000    0.001    0.000 {pyexpat.ParserCreate}
        225    0.000    0.000    0.000    0.000 {range}
       4050    0.004    0.000    0.004    0.000 {setattr}

AFTER

         153844 function calls (153395 primitive calls) in 2.779 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    2.779    2.779 <string>:1(<module>)
     2694    0.001    0.000    0.001    0.000 ElementPath.py:239(__init__)
     2694    0.005    0.000    0.006    0.000 ElementPath.py:247(iterfind)
        2    0.000    0.000    0.000    0.000 ElementPath.py:292(findall)
     2692    0.006    0.000    0.027    0.000 ElementPath.py:298(findtext)
       40    0.000    0.000    0.000    0.000 ElementPath.py:73(xpath_tokenizer)
       20    0.000    0.000    0.000    0.000 ElementPath.py:96(prepare_child)
6283/5837    0.012    0.000    0.015    0.000 ElementPath.py:98(select)
        3    0.000    0.000    0.095    0.032 ElementTree.py:1297(XML)
        3    0.000    0.000    0.000    0.000 ElementTree.py:1367(__init__)
        3    0.000    0.000    0.000    0.000 ElementTree.py:1383(close)
     6374    0.010    0.000    0.011    0.000 ElementTree.py:1388(_flush)
     6370    0.003    0.000    0.004    0.000 ElementTree.py:1406(data)
     3187    0.009    0.000    0.025    0.000 ElementTree.py:1417(start)
     3187    0.004    0.000    0.010    0.000 ElementTree.py:1433(end)
        3    0.000    0.000    0.007    0.002 ElementTree.py:1457(__init__)
     6407    0.003    0.000    0.011    0.000 ElementTree.py:1508(_fixtext)
     6374    0.003    0.000    0.003    0.000 ElementTree.py:1515(_fixname)
     3187    0.004    0.000    0.030    0.000 ElementTree.py:1535(_start_list)
     6370    0.006    0.000    0.021    0.000 ElementTree.py:1545(_data)
     3187    0.003    0.000    0.014    0.000 ElementTree.py:1548(_end)
        6    0.000    0.000    0.000    0.000 ElementTree.py:1567(_default)
        3    0.000    0.000    0.087    0.029 ElementTree.py:1638(feed)
        3    0.000    0.000    0.000    0.000 ElementTree.py:1650(close)
     3187    0.005    0.000    0.007    0.000 ElementTree.py:207(__init__)
    17227    0.004    0.000    0.004    0.000 ElementTree.py:265(__getitem__)
     3184    0.002    0.000    0.002    0.000 ElementTree.py:300(append)
     2692    0.002    0.000    0.029    0.000 ElementTree.py:377(findtext)
        2    0.000    0.000    0.000    0.000 ElementTree.py:389(findall)
        3    0.000    0.000    0.000    0.000 UserDict.py:58(get)
        3    0.000    0.000    0.000    0.000 UserDict.py:70(__contains__)
        3    0.000    0.000    0.001    0.000 __init__.py:11(_dnsname_match)
        3    0.000    0.000    0.001    0.000 __init__.py:64(match_hostname)
        3    0.000    0.000    0.000    0.000 base.py:143(success)
        3    0.000    0.000    0.000    0.000 base.py:155(_decompress_response)
        3    0.000    0.000    0.095    0.032 base.py:206(parse_body)
      223    0.001    0.000    0.001    0.000 base.py:356(__init__)
        5    0.000    0.000    0.000    0.000 base.py:393(__init__)
        3    0.000    0.000    0.000    0.000 base.py:518(reset_context)
        3    0.000    0.000    0.000    0.000 base.py:548(connect)
        3    0.000    0.000    0.000    0.000 base.py:608(_user_agent)
        3    0.000    0.000    2.736    0.912 base.py:633(request)
        3    0.000    0.000    0.000    0.000 base.py:764(morph_action_hook)
        3    0.000    0.000    0.000    0.000 base.py:767(add_default_params)
        3    0.000    0.000    0.000    0.000 base.py:785(pre_connect_hook)
        3    0.000    0.000    0.468    0.156 base.py:86(__init__)
      223    0.000    0.000    0.000    0.000 base.py:87(__init__)
        3    0.000    0.000    0.000    0.000 base64.py:42(b64encode)
        3    0.000    0.000    0.000    0.000 dimensiondata.py:156(add_default_headers)
        2    0.000    0.000    2.337    1.169 dimensiondata.py:162(request)
        1    0.000    0.000    0.807    0.807 dimensiondata.py:171(request_with_orgId)
        1    0.000    0.000    0.408    0.408 dimensiondata.py:180(get_resource_path)
        1    0.000    0.000    0.408    0.408 dimensiondata.py:189(_get_orgId)
        1    0.000    0.000    2.779    2.779 dimensiondata.py:388(list_images)
        1    0.000    0.000    0.807    0.807 dimensiondata.py:410(list_locations)
        1    0.000    0.000    0.849    0.849 dimensiondata.py:435(_to_base_images)
      223    0.002    0.000    0.849    0.004 dimensiondata.py:439(_to_base_image)
      223    0.000    0.000    0.808    0.004 dimensiondata.py:527(ex_get_location_by_id)
     1115    0.000    0.000    0.000    0.000 dimensiondata.py:542(<lambda>)
        1    0.000    0.000    0.000    0.000 dimensiondata.py:573(_to_locations)
        5    0.000    0.000    0.000    0.000 dimensiondata.py:580(_to_location)
       18    0.000    0.000    0.000    0.000 genericpath.py:15(exists)
        3    0.000    0.000    0.000    0.000 genericpath.py:26(isfile)
        3    0.000    0.000    1.430    0.477 httplib.py:1014(_send_request)
        3    0.000    0.000    0.837    0.279 httplib.py:1031(getresponse)
        3    0.000    0.000    0.000    0.000 httplib.py:1182(__init__)
       15    0.000    0.000    0.000    0.000 httplib.py:220(addheader)
        3    0.000    0.000    0.005    0.002 httplib.py:234(readheaders)
        3    0.000    0.000    0.000    0.000 httplib.py:335(__init__)
        3    0.000    0.000    0.832    0.277 httplib.py:363(_read_status)
        3    0.000    0.000    0.837    0.279 httplib.py:402(begin)
        3    0.000    0.000    0.000    0.000 httplib.py:488(_check_close)
        3    0.000    0.000    0.012    0.004 httplib.py:518(close)
        3    0.000    0.000    0.373    0.124 httplib.py:534(read)
        3    0.000    0.000    0.373    0.124 httplib.py:579(_read_chunked)
       44    0.000    0.000    0.359    0.008 httplib.py:637(_safe_read)
        3    0.000    0.000    0.000    0.000 httplib.py:673(getheaders)
        3    0.000    0.000    0.000    0.000 httplib.py:691(__init__)
        3    0.000    0.000    0.000    0.000 httplib.py:737(_get_hostport)
        3    0.000    0.000    0.000    0.000 httplib.py:792(close)
        3    0.000    0.000    1.430    0.477 httplib.py:802(send)
       18    0.000    0.000    0.000    0.000 httplib.py:822(_output)
        3    0.000    0.000    1.430    0.477 httplib.py:829(_send_output)
        3    0.000    0.000    0.000    0.000 httplib.py:850(putrequest)
       15    0.000    0.000    0.000    0.000 httplib.py:967(putheader)
        3    0.000    0.000    1.430    0.477 httplib.py:978(endheaders)
        3    0.000    0.000    1.430    0.477 httplib.py:993(request)
        3    0.000    0.000    0.000    0.000 httplib.py:997(_set_content_length)
        3    0.000    0.000    0.000    0.000 httplib_ssl.py:202(__init__)
        3    0.000    0.000    0.000    0.000 httplib_ssl.py:216(_setup_verify)
        3    0.000    0.000    0.000    0.000 httplib_ssl.py:231(_setup_ca_cert)
        3    0.000    0.000    1.430    0.477 httplib_ssl.py:252(connect)
        3    0.000    0.000    0.005    0.002 mimetools.py:24(__init__)
        3    0.000    0.000    0.000    0.000 mimetools.py:33(parsetype)
        3    0.000    0.000    0.000    0.000 mimetools.py:50(parseplist)
        3    0.000    0.000    0.000    0.000 misc.py:244(lowercase_keys)
       18    0.000    0.000    0.000    0.000 misc.py:245(<genexpr>)
     6370    0.003    0.000    0.025    0.000 pyexpat.c:441(CharacterData)
     3187    0.002    0.000    0.033    0.000 pyexpat.c:566(StartElement)
     3187    0.002    0.000    0.016    0.000 pyexpat.c:618(EndElement)
        6    0.000    0.000    0.000    0.000 pyexpat.c:839(DefaultHandlerExpand)
        3    0.000    0.000    0.000    0.000 re.py:188(compile)
        6    0.000    0.000    0.000    0.000 re.py:204(escape)
        3    0.000    0.000    0.000    0.000 re.py:226(_compile)
       15    0.000    0.000    0.000    0.000 rfc822.py:197(isheader)
       18    0.000    0.000    0.000    0.000 rfc822.py:209(islast)
       18    0.000    0.000    0.000    0.000 rfc822.py:219(iscomment)
       18    0.000    0.000    0.000    0.000 rfc822.py:285(getheader)
        3    0.000    0.000    0.000    0.000 rfc822.py:454(items)
        3    0.000    0.000    0.005    0.002 rfc822.py:88(__init__)
        6    0.007    0.001    0.007    0.001 socket.py:185(__init__)
        3    0.000    0.000    0.000    0.000 socket.py:192(close)
        9    0.000    0.000    0.210    0.023 socket.py:223(meth)
        3    0.000    0.000    0.000    0.000 socket.py:246(__init__)
        6    0.000    0.000    0.012    0.002 socket.py:276(close)
        3    0.000    0.000    0.000    0.000 socket.py:285(__del__)
        3    0.000    0.000    0.000    0.000 socket.py:292(flush)
       44    0.001    0.000    0.358    0.008 socket.py:336(read)
       49    0.003    0.000    0.838    0.017 socket.py:406(readline)
        3    0.000    0.000    0.915    0.305 socket.py:537(create_connection)
      2/1    0.000    0.000    0.000    0.000 sre_compile.py:32(_compile)
        1    0.000    0.000    0.000    0.000 sre_compile.py:354(_simple)
        1    0.000    0.000    0.000    0.000 sre_compile.py:359(_compile_info)
        2    0.000    0.000    0.000    0.000 sre_compile.py:472(isstring)
        1    0.000    0.000    0.000    0.000 sre_compile.py:478(_code)
        1    0.000    0.000    0.000    0.000 sre_compile.py:493(compile)
        4    0.000    0.000    0.000    0.000 sre_parse.py:126(__len__)
        6    0.000    0.000    0.000    0.000 sre_parse.py:130(__getitem__)
        1    0.000    0.000    0.000    0.000 sre_parse.py:134(__setitem__)
       21    0.000    0.000    0.000    0.000 sre_parse.py:138(append)
      3/2    0.000    0.000    0.000    0.000 sre_parse.py:140(getwidth)
        1    0.000    0.000    0.000    0.000 sre_parse.py:178(__init__)
       28    0.000    0.000    0.000    0.000 sre_parse.py:182(__next)
        4    0.000    0.000    0.000    0.000 sre_parse.py:195(match)
       26    0.000    0.000    0.000    0.000 sre_parse.py:201(get)
        4    0.000    0.000    0.000    0.000 sre_parse.py:257(_escape)
        1    0.000    0.000    0.000    0.000 sre_parse.py:301(_parse_sub)
        1    0.000    0.000    0.000    0.000 sre_parse.py:379(_parse)
        1    0.000    0.000    0.000    0.000 sre_parse.py:67(__init__)
        1    0.000    0.000    0.000    0.000 sre_parse.py:677(parse)
        2    0.000    0.000    0.000    0.000 sre_parse.py:90(__init__)
        3    0.000    0.000    0.514    0.171 ssl.py:107(__init__)
      890    0.001    0.000    1.187    0.001 ssl.py:159(read)
        3    0.000    0.000    0.000    0.000 ssl.py:179(getpeercert)
        3    0.000    0.000    0.000    0.000 ssl.py:195(send)
        3    0.000    0.000    0.000    0.000 ssl.py:225(sendall)
      890    0.001    0.000    1.188    0.001 ssl.py:240(recv)
        6    0.012    0.002    0.012    0.002 ssl.py:299(close)
        3    0.000    0.000    0.452    0.151 ssl.py:306(do_handshake)
        3    0.000    0.000    0.000    0.000 ssl.py:368(makefile)
        3    0.000    0.000    0.514    0.171 ssl.py:381(wrap_socket)
        3    0.000    0.000    0.000    0.000 stat.py:24(S_IFMT)
        3    0.000    0.000    0.000    0.000 stat.py:49(S_ISREG)
        3    0.000    0.000    0.000    0.000 utf_8.py:15(decode)
     2694    0.005    0.000    0.007    0.000 xml.py:24(fixxpath)
     2692    0.003    0.000    0.038    0.000 xml.py:32(findtext)
        3    0.000    0.000    0.000    0.000 {_codecs.utf_8_decode}
        3    0.697    0.232    0.697    0.232 {_socket.getaddrinfo}
        1    0.000    0.000    0.000    0.000 {_sre.compile}
       19    0.000    0.000    0.000    0.000 {_sre.getlower}
        3    0.061    0.020    0.061    0.020 {_ssl.sslwrap}
        3    0.000    0.000    0.000    0.000 {binascii.b2a_base64}
        6    0.014    0.002    0.087    0.015 {built-in method Parse}
        3    0.452    0.151    0.452    0.151 {built-in method do_handshake}
        3    0.000    0.000    0.000    0.000 {built-in method fromkeys}
        3    0.000    0.000    0.000    0.000 {built-in method peer_certificate}
      890    1.186    0.001    1.186    0.001 {built-in method read}
        3    0.000    0.000    0.000    0.000 {built-in method write}
       96    0.000    0.000    0.000    0.000 {cStringIO.StringIO}
       18    0.000    0.000    0.000    0.000 {delattr}
      223    0.000    0.000    0.001    0.000 {filter}
       54    0.000    0.000    0.000    0.000 {getattr}
      247    0.000    0.000    0.000    0.000 {hasattr}
       12    0.000    0.000    0.000    0.000 {isinstance}
       18    0.000    0.000    0.000    0.000 {iter}
1050/1049    0.000    0.000    0.000    0.000 {len}
       44    0.000    0.000    0.000    0.000 {max}
    12951    0.003    0.000    0.003    0.000 {method 'append' of 'list' objects}
        3    0.210    0.070    0.210    0.070 {method 'connect' of '_socket.socket' objects}
     3187    0.001    0.000    0.001    0.000 {method 'copy' of 'dict' objects}
        3    0.000    0.000    0.000    0.000 {method 'count' of 'str' objects}
        3    0.000    0.000    0.000    0.000 {method 'decode' of 'str' objects}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
     6407    0.008    0.000    0.008    0.000 {method 'encode' of 'unicode' objects}
        3    0.000    0.000    0.000    0.000 {method 'extend' of 'list' objects}
      768    0.001    0.000    0.001    0.000 {method 'find' of 'str' objects}
       18    0.000    0.000    0.000    0.000 {method 'findall' of '_sre.SRE_Pattern' objects}
       48    0.000    0.000    0.000    0.000 {method 'get' of 'dict' objects}
        3    0.000    0.000    0.000    0.000 {method 'getpeername' of '_socket.socket' objects}
        3    0.000    0.000    0.000    0.000 {method 'getsockopt' of '_socket.socket' objects}
       70    0.000    0.000    0.000    0.000 {method 'getvalue' of 'cStringIO.StringO' objects}
        7    0.000    0.000    0.000    0.000 {method 'items' of 'dict' objects}
        3    0.000    0.000    0.000    0.000 {method 'iteritems' of 'dict' objects}
     9147    0.001    0.000    0.001    0.000 {method 'join' of 'str' objects}
       72    0.000    0.000    0.000    0.000 {method 'lower' of 'str' objects}
        3    0.000    0.000    0.000    0.000 {method 'match' of '_sre.SRE_Pattern' objects}
        3    0.000    0.000    0.000    0.000 {method 'pop' of 'dict' objects}
     3187    0.001    0.000    0.001    0.000 {method 'pop' of 'list' objects}
      142    0.000    0.000    0.000    0.000 {method 'seek' of 'cStringIO.StringO' objects}
     2703    0.002    0.000    0.002    0.000 {method 'split' of 'str' objects}
        9    0.000    0.000    0.000    0.000 {method 'startswith' of 'str' objects}
       27    0.000    0.000    0.000    0.000 {method 'strip' of 'str' objects}
      142    0.000    0.000    0.000    0.000 {method 'tell' of 'cStringIO.StringO' objects}
     3202    0.001    0.000    0.001    0.000 {method 'update' of 'dict' objects}
        3    0.000    0.000    0.000    0.000 {method 'upper' of 'str' objects}
      916    0.002    0.000    0.002    0.000 {method 'write' of 'cStringIO.StringO' objects}
       48    0.000    0.000    0.000    0.000 {min}
       19    0.000    0.000    0.000    0.000 {ord}
       21    0.000    0.000    0.000    0.000 {posix.stat}
        3    0.007    0.002    0.007    0.002 {pyexpat.ParserCreate}
        3    0.000    0.000    0.000    0.000 {range}
       54    0.000    0.000    0.000    0.000 {setattr}

@Kami
Copy link
Copy Markdown
Member

Kami commented Jul 19, 2015

Sorry for the delay.

There was a discussion about doing caching in Libcloud in the past, but we decided not to implement it. It's simply too complex and there are too many edge cases (cache invalidation for long running processes, support for multiple caching backends, making sure we don't use too much memory, LRU, etc.), so it's better to leave caching up to the user.

I will try to find some time to add a documentation section on caching - why don't we do it and other ways users can speed up the requests (putting caching proxy in front, etc.).

@relaxdiego
Copy link
Copy Markdown
Contributor Author

I can modify this so that it only caches the data for each function call only. The problem I'm trying to solve here can't be solved by the client caching the data because the data is being repeatedly downloaded within a loop inside an internal method. Furthermore, a caching proxy up front is not always feasible (e.g. libcloud is being used as part of a CLI tool)

@relaxdiego
Copy link
Copy Markdown
Contributor Author

"I can modify this so that it only caches the data for each function call only."

I take that back. The implementation will be hacky at best. The only other way I can think of is for this part of the driver[1] to avoid eager loading the location object.

cc @tonybaloney

[1]

def _to_base_image(self, element):

@tonybaloney
Copy link
Copy Markdown
Contributor

I have updated the methods to get the list of locations before transforming the responses, then using a lamba over the in-memory list removing the requirement for a cache.

This is now implemented in PR 587 so can be closed.

@relaxdiego relaxdiego closed this Sep 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants