Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cold start issue within the infra with limited resource #3415

Closed
denismakogon opened this issue Nov 30, 2018 · 12 comments
Closed

Cold start issue within the infra with limited resource #3415

denismakogon opened this issue Nov 30, 2018 · 12 comments
Labels

Comments

@denismakogon
Copy link

Long story short

I've been working on a UDS HTTP server and found that aiohttp has pretty sane API to make it work.
However, with some testing being done I've found out that aiohttp has a problem of the cold start. Within the constraint-bound infrastructure, imagine a docker container with the following resources:

--cpu-quota=10000 --cpu-period=100000 --cpu-shares=128 --memory=128m --kernel-memory=128m --memory-swap=128m

aiohttp UDS HTTP server consumes unfortunate amount of time for the cold start, here's the statistics of the imports from Python 3.7 with PYTHONPROFILEIMPORTTIME=1:

import time: self [us] | cumulative | imported package
import time:       168 |        168 | zipimport
import time:      1150 |       1150 | _frozen_importlib_external
import time:        91 |         91 |     _codecs
import time:      4804 |       4894 |   codecs
import time:     88056 |      88056 |   encodings.aliases
import time:      4840 |      97789 | encodings
import time:      1731 |       1731 | encodings.utf_8
import time:       204 |        204 | _signal
import time:      1318 |       1318 | encodings.latin_1
import time:       153 |        153 |     _abc
import time:      1621 |       1774 |   abc
import time:     92601 |      94375 | io
import time:       176 |        176 |   _locale
import time:      1681 |       1857 | _bootlocale
import time:       160 |        160 |       _stat
import time:     96817 |      96977 |     stat
import time:      1960 |       1960 |       genericpath
import time:      3918 |       5877 |     posixpath
import time:     87176 |      87176 |     _collections_abc
import time:      6476 |     196505 |   os
import time:      1223 |       1223 |   _sitebuiltins
import time:       262 |        262 |   sitecustomize
import time:       258 |        258 |   usercustomize
import time:      6408 |     204654 | site
import time:       147 |        147 |           _operator
import time:    188664 |     188811 |         operator
import time:      1541 |       1541 |         keyword
import time:       392 |        392 |           _heapq
import time:      5235 |       5627 |         heapq
import time:       212 |        212 |         itertools
import time:      2494 |       2494 |         reprlib
import time:     91121 |      91121 |         _collections
import time:     94050 |     383852 |       collections
import time:       609 |        609 |       collections.abc
import time:       968 |        968 |         concurrent
import time:       229 |        229 |             time
import time:        77 |         77 |                   _functools
import time:     94078 |      94155 |                 functools
import time:     92610 |      92610 |                       types
import time:      7071 |      99680 |                     enum
import time:       112 |        112 |                       _sre
import time:      1558 |       1558 |                         sre_constants
import time:     93503 |      95061 |                       sre_parse
import time:    101855 |     197027 |                     sre_compile
import time:      1860 |       1860 |                     copyreg
import time:     99112 |     397677 |                   re
import time:      1531 |       1531 |                   token
import time:      6687 |     405894 |                 tokenize
import time:      2139 |     502187 |               linecache
import time:      2896 |     505083 |             traceback
import time:     97892 |      97892 |             warnings
import time:      2698 |       2698 |               _weakrefset
import time:      5511 |       8209 |             weakref
import time:        78 |         78 |               _string
import time:     87842 |      87920 |             string
import time:      6537 |       6537 |             threading
import time:       144 |        144 |             atexit
import time:    187032 |     893042 |           logging
import time:      4603 |     897645 |         concurrent.futures._base
import time:       991 |     899603 |       concurrent.futures
import time:       592 |        592 |         _socket
import time:       517 |        517 |           math
import time:     86062 |      86062 |           select
import time:      5099 |      91677 |         selectors
import time:       229 |        229 |         errno
import time:      9377 |     101874 |       socket
import time:     96501 |      96501 |         signal
import time:      1561 |       1561 |         _posixsubprocess
import time:    103890 |     201951 |       subprocess
import time:      1874 |       1874 |         _ssl
import time:       413 |        413 |             _struct
import time:       572 |        984 |           struct
import time:     93528 |      93528 |           binascii
import time:      4376 |      98888 |         base64
import time:     95527 |     196288 |       ssl
import time:      1503 |       1503 |       asyncio.constants
import time:       338 |        338 |               _opcode
import time:     85969 |      86307 |             opcode
import time:      5353 |      91660 |           dis
import time:      2079 |       2079 |             importlib
import time:      1011 |       3089 |           importlib.machinery
import time:    299486 |     394235 |         inspect
import time:      2993 |       2993 |           asyncio.format_helpers
import time:      2143 |       5135 |         asyncio.base_futures
import time:      1787 |       1787 |         asyncio.log
import time:      3146 |     404301 |       asyncio.coroutines
import time:      2476 |       2476 |           _contextvars
import time:     88070 |      90546 |         contextvars
import time:      1539 |       1539 |           asyncio.base_tasks
import time:      7506 |       9045 |         _asyncio
import time:      5551 |     105141 |       asyncio.events
import time:      3540 |       3540 |       asyncio.futures
import time:     85365 |      85365 |       asyncio.protocols
import time:      2511 |       2511 |         asyncio.transports
import time:      5479 |       7989 |       asyncio.sslproto
import time:      5688 |       5688 |       asyncio.tasks
import time:      9556 |    2407255 |     asyncio.base_events
import time:      5543 |       5543 |     asyncio.locks
import time:      2308 |       2308 |     asyncio.runners
import time:      2708 |       2708 |     asyncio.queues
import time:     97048 |      97048 |     asyncio.streams
import time:      2853 |       2853 |     asyncio.subprocess
import time:     85194 |      85194 |       asyncio.base_subprocess
import time:    102495 |     102495 |       asyncio.selector_events
import time:      7549 |     195238 |     asyncio.unix_events
import time:     84536 |    2797487 |   asyncio
import time:        94 |         94 |       gc
import time:       386 |        480 |     uvloop.includes
import time:       540 |        540 |     uvloop._patch
import time:       476 |        476 |       backports_abc
import time:     78295 |      78295 |       uvloop._noop
import time:      1092 |       1092 |           _queue
import time:      3299 |       4391 |         queue
import time:      4589 |       8979 |       concurrent.futures.thread
import time:    104049 |     191798 |     uvloop.loop
import time:      1360 |     194177 |   uvloop
import time:      1127 |       1127 |   fdk.constants
import time:      1440 |       1440 |   fdk.log
import time:      2368 |       2368 |           numbers
import time:      1916 |       4284 |         _decimal
import time:       594 |       4877 |       decimal
import time:       396 |        396 |         _datetime
import time:     93148 |      93544 |       datetime
import time:       489 |      98909 |     ujson
import time:     10406 |      10406 |             platform
import time:       374 |      10779 |           multidict._compat
import time:     91622 |      91622 |           multidict._abc
import time:       244 |        244 |             multidict._istr
import time:       452 |        452 |             multidict._multidict_base
import time:       725 |       1420 |           multidict._multidict
import time:       442 |     104262 |         multidict
import time:       591 |     104852 |       aiohttp.hdrs
import time:      1666 |       1666 |           _hashlib
import time:       307 |        307 |           _blake2
import time:     91593 |      91593 |           _sha3
import time:      2317 |      95881 |         hashlib
import time:       418 |        418 |               _json
import time:      1444 |       1861 |             json.scanner
import time:      2734 |       4595 |           json.decoder
import time:     96686 |      96686 |           json.encoder
import time:      2425 |     103704 |         json
import time:      2727 |       2727 |           contextlib
import time:     96681 |      99407 |         typing
import time:      1320 |       1320 |           __future__
import time:       181 |        181 |                     org
import time:       392 |        573 |                   org.python
import time:       344 |        917 |                 org.python.core
import time:      2826 |       3742 |               copy
import time:       378 |        378 |               attr._config
import time:       510 |        510 |                   _ctypes
import time:      1538 |       1538 |                   ctypes._endian
import time:     88577 |      90624 |                 ctypes
import time:      1040 |      91664 |               attr._compat
import time:       577 |        577 |               attr.exceptions
import time:      3989 |     100349 |             attr._make
import time:       964 |     101312 |           attr.converters
import time:       333 |        333 |           attr.filters
import time:     96471 |      96471 |           attr.validators
import time:       836 |        836 |           attr._funcs
import time:      3746 |     204016 |         attr
import time:     96483 |      96483 |           ipaddress
import time:      1121 |       1121 |             urllib
import time:    103727 |     104847 |           urllib.parse
import time:       285 |        285 |             idna.package_data
import time:       588 |        588 |               idna.idnadata
import time:       358 |        358 |                 _bisect
import time:      2667 |       3025 |               bisect
import time:       395 |        395 |               unicodedata
import time:       518 |        518 |               idna.intranges
import time:     93101 |      97625 |             idna.core
import time:       746 |      98656 |           idna
import time:       395 |        395 |             yarl._quoting
import time:      1199 |       1593 |           yarl.quoting
import time:      2338 |     303915 |         yarl
import time:      1243 |       1243 |         aiohttp.client_exceptions
import time:      2740 |       2740 |             http
import time:     93976 |      96715 |           http.cookies
import time:       634 |        634 |                 email
import time:      1347 |       1347 |                   email.errors
import time:      2516 |       2516 |                       email.quoprimime
import time:      1045 |       1045 |                       email.base64mime
import time:      1733 |       1733 |                           quopri
import time:     87119 |      88852 |                         email.encoders
import time:      3090 |      91941 |                       email.charset
import time:    100394 |     195895 |                     email.header
import time:       285 |        285 |                         _random
import time:     94047 |      94331 |                       random
import time:    102339 |     102339 |                           locale
import time:     98757 |     201096 |                         calendar
import time:      5651 |     206746 |                       email._parseaddr
import time:      3892 |     304968 |                     email.utils
import time:      5218 |     506081 |                   email._policybase
import time:     99983 |     607410 |                 email.feedparser
import time:     85240 |     693283 |               email.parser
import time:      1155 |       1155 |                 uu
import time:      2514 |       2514 |                 email._encoded_words
import time:      1065 |       1065 |                 email.iterators
import time:     92932 |      97665 |               email.message
import time:     12377 |      12377 |                 html.entities
import time:    180954 |     193330 |               html
import time:      1155 |       1155 |                   fnmatch
import time:       833 |        833 |                   zlib
import time:       992 |        992 |                     _compression
import time:       953 |        953 |                     _bz2
import time:     89428 |      91372 |                   bz2
import time:       669 |        669 |                     _lzma
import time:      3602 |       4270 |                   lzma
import time:       275 |        275 |                   pwd
import time:       553 |        553 |                   grp
import time:    102263 |     200719 |                 shutil
import time:      5895 |     206614 |               tempfile
import time:      9513 |    1200403 |             cgi
import time:      2482 |       2482 |               shlex
import time:     87735 |      90217 |             netrc
import time:       208 |        208 |                 nt
import time:       954 |        954 |                 nt
import time:       605 |        605 |                 nt
import time:    100771 |     102536 |               ntpath
import time:    101934 |     204469 |             pathlib
import time:    103125 |     103125 |               http.client
import time:      1429 |       1429 |                 urllib.response
import time:      2376 |       3804 |               urllib.error
import time:    191045 |     297972 |             urllib.request
import time:       916 |        916 |             async_timeout
import time:       860 |        860 |             aiohttp.abc
import time:     93244 |      93244 |             aiohttp.log
import time:       358 |        358 |             aiohttp._helpers
import time:    104458 |    1992893 |           aiohttp.helpers
import time:       150 |        150 |                 winreg
import time:     86282 |      86431 |               mimetypes
import time:      4959 |       4959 |               socketserver
import time:     11136 |     102525 |             http.server
import time:     98074 |      98074 |             aiohttp.http_exceptions
import time:       331 |        331 |                 aiohttp.base_protocol
import time:       106 |        106 |                   aiohttp.multidict
import time:       474 |        579 |                 aiohttp._http_writer
import time:      1874 |       2783 |               aiohttp.http_writer
import time:       764 |        764 |                 aiohttp.typedefs
import time:      2497 |       3261 |               aiohttp.streams
import time:       425 |        425 |               brotli
import time:       144 |        144 |                 backports_abc
import time:       822 |        965 |               aiohttp._http_parser
import time:      4569 |      12001 |             aiohttp.http_parser
import time:       328 |        328 |               aiohttp._websocket
import time:     97916 |      98243 |             aiohttp.http_websocket
import time:     90324 |     401166 |           aiohttp.http
import time:       208 |        208 |               _uuid
import time:      9808 |      10016 |             uuid
import time:      1020 |       1020 |             aiohttp.payload
import time:     85342 |      96376 |           aiohttp.multipart
import time:       635 |        635 |           aiohttp.formdata
import time:       297 |        297 |           cchardet
import time:       385 |        385 |             chardet.compat
import time:       399 |        399 |                 chardet.enums
import time:       346 |        346 |                 chardet.charsetprober
import time:       581 |       1325 |               chardet.charsetgroupprober
import time:       289 |        289 |                 chardet.codingstatemachine
import time:       352 |        352 |                 chardet.escsm
import time:       886 |       1526 |               chardet.escprober
import time:       456 |        456 |               chardet.latin1prober
import time:       335 |        335 |                   chardet.mbcssm
import time:       674 |       1009 |                 chardet.utf8prober
import time:       305 |        305 |                   chardet.mbcharsetprober
import time:       522 |        522 |                     chardet.euctwfreq
import time:       402 |        402 |                     chardet.euckrfreq
import time:       768 |        768 |                     chardet.gb2312freq
import time:      1250 |       1250 |                     chardet.big5freq
import time:       627 |        627 |                     chardet.jisfreq
import time:     91953 |      95520 |                   chardet.chardistribution
import time:       680 |        680 |                   chardet.jpcntx
import time:      1332 |      97836 |                 chardet.sjisprober
import time:       540 |        540 |                 chardet.eucjpprober
import time:       437 |        437 |                 chardet.gb2312prober
import time:       456 |        456 |                 chardet.euckrprober
import time:       517 |        517 |                 chardet.cp949prober
import time:       338 |        338 |                 chardet.big5prober
import time:       318 |        318 |                 chardet.euctwprober
import time:      1401 |     102848 |               chardet.mbcsgroupprober
import time:       278 |        278 |                 chardet.sbcharsetprober
import time:       422 |        422 |                 chardet.langcyrillicmodel
import time:       534 |        534 |                 chardet.langgreekmodel
import time:       455 |        455 |                 chardet.langbulgarianmodel
import time:       749 |        749 |                 chardet.langthaimodel
import time:     85346 |      85346 |                 chardet.langhebrewmodel
import time:      1350 |       1350 |                 chardet.hebrewprober
import time:      1227 |       1227 |                 chardet.langturkishmodel
import time:      1021 |      91379 |               chardet.sbcsgroupprober
import time:      2158 |     199689 |             chardet.universaldetector
import time:       748 |        748 |             chardet.version
import time:       803 |     201624 |           chardet
import time:      7880 |    2797583 |         aiohttp.client_reqrep
import time:       286 |        286 |           aiohttp.client_proto
import time:       316 |        316 |           aiohttp.locks
import time:       170 |        170 |             aiodns
import time:       668 |        838 |           aiohttp.resolver
import time:     91319 |      92757 |         aiohttp.connector
import time:      1957 |       1957 |         aiohttp.client_ws
import time:      1335 |       1335 |             _compat_pickle
import time:     83611 |      83611 |                 org
import time:       127 |      83738 |               org.python
import time:        71 |      83809 |             org.python.core
import time:       684 |        684 |             _pickle
import time:     12772 |      98598 |           pickle
import time:      3240 |     101838 |         aiohttp.cookiejar
import time:     95985 |      95985 |         aiohttp.tcp_helpers
import time:       142 |        142 |                   aiohttp.collections
import time:       214 |        356 |                 aiohttp.collections.abc
import time:      1090 |       1446 |               aiohttp._frozenlist
import time:       548 |       1994 |             aiohttp.frozenlist
import time:       388 |       2381 |           aiohttp.signals
import time:     10661 |      13042 |         aiohttp.tracing
import time:    187869 |    4099192 |       aiohttp.client
import time:      1046 |       1046 |       aiohttp.payload_streamer
import time:       320 |        320 |           gunicorn
import time:       123 |        443 |         gunicorn.config
import time:      1008 |       1450 |       aiohttp.worker
import time:     95296 |    4301835 |     aiohttp
import time:    186432 |     186432 |         gettext
import time:     13800 |     200231 |       argparse
import time:       642 |        642 |             aiohttp.web_response
import time:     92020 |      92661 |           aiohttp.web_exceptions
import time:       425 |        425 |             aiohttp.web_fileresponse
import time:      3469 |       3894 |           aiohttp.web_urldispatcher
import time:       403 |      96958 |         aiohttp.web_middlewares
import time:     99315 |      99315 |         aiohttp.web_request
import time:      1089 |       1089 |           aiohttp.web_protocol
import time:      1030 |       2119 |         aiohttp.web_server
import time:      1841 |     200231 |       aiohttp.web_app
import time:      3288 |       3288 |       aiohttp.web_routedef
import time:      1739 |       1739 |       aiohttp.web_runner
import time:      1817 |       1817 |       aiohttp.web_ws
import time:      1630 |     408936 |     aiohttp.web
import time:     85227 |      85227 |       xml
import time:      1446 |      86673 |     xml.etree
import time:      2154 |       2154 |       xml.etree.ElementPath
import time:       400 |        400 |         pyexpat
import time:       693 |       1093 |       _elementtree
import time:     99974 |     103220 |     xml.etree.ElementTree
import time:      2159 |       2159 |         iso8601.iso8601
import time:       466 |       2624 |       iso8601
import time:       382 |        382 |         fdk.headers
import time:       502 |        883 |       fdk.context
import time:       449 |        449 |         fdk.response
import time:       251 |        699 |       fdk.errors
import time:       661 |       4867 |     fdk.runner
import time:      1687 |    5006123 |   fdk.http_stream
import time:       810 |    8001160 | fdk

As you may see, aiohttp takes at least 8 seconds to start, which is not quite expected. The validation system that ensures that a UDS server is up and running expects it to become active within 2-4 seconds at maximum within given constraints, but aiohttp takes at least 8 seconds to start.
The thing is, if I would use native tools like asyncio with some custom HTTP routine, i can speed up cold start up to 1.8 seconds:

import time: self [us] | cumulative | imported package
import time:       117 |        117 | zipimport
import time:       749 |        749 | _frozen_importlib_external
import time:        71 |         71 |     _codecs
import time:       579 |        650 |   codecs
import time:       482 |        482 |   encodings.aliases
import time:       967 |       2097 | encodings
import time:       252 |        252 | encodings.utf_8
import time:       134 |        134 | _signal
import time:    101907 |     101907 | encodings.latin_1
import time:        74 |         74 |     _abc
import time:       805 |        879 |   abc
import time:       902 |       1780 | io
import time:        77 |         77 |       _stat
import time:       323 |        400 |     stat
import time:       244 |        244 |       genericpath
import time:       710 |        953 |     posixpath
import time:      1455 |       1455 |     _collections_abc
import time:       911 |       3717 |   os
import time:       609 |        609 |   _sitebuiltins
import time:       253 |        253 |   sitecustomize
import time:        89 |         89 |   usercustomize
import time:      1531 |       6197 | site
import time:       171 |        171 |           _operator
import time:       950 |       1121 |         operator
import time:       446 |        446 |         keyword
import time:       354 |        354 |           _heapq
import time:       597 |        951 |         heapq
import time:       190 |        190 |         itertools
import time:       446 |        446 |         reprlib
import time:       137 |        137 |         _collections
import time:      2290 |       5578 |       collections
import time:       481 |        481 |       collections.abc
import time:       268 |        268 |         concurrent
import time:       165 |        165 |             time
import time:       136 |        136 |                   _functools
import time:      1097 |       1233 |                 functools
import time:       435 |        435 |                       types
import time:      1234 |       1668 |                     enum
import time:       108 |        108 |                       _sre
import time:       502 |        502 |                         sre_constants
import time:       868 |       1369 |                       sre_parse
import time:       774 |       2250 |                     sre_compile
import time:       315 |        315 |                     _locale
import time:       266 |        266 |                     copyreg
import time:      1187 |       5684 |                   re
import time:       538 |        538 |                   token
import time:      2060 |       8282 |                 tokenize
import time:       995 |      10509 |               linecache
import time:     91646 |     102155 |             traceback
import time:     90384 |      90384 |             warnings
import time:       716 |        716 |               _weakrefset
import time:      1259 |       1975 |             weakref
import time:       162 |        162 |               _string
import time:      2321 |       2482 |             string
import time:      1053 |       1053 |             threading
import time:        99 |         99 |             atexit
import time:      1819 |     200129 |           logging
import time:       955 |     201083 |         concurrent.futures._base
import time:       573 |     201924 |       concurrent.futures
import time:       781 |        781 |         _socket
import time:      2226 |       2226 |           math
import time:      1378 |       1378 |           select
import time:     91586 |      95189 |         selectors
import time:       160 |        160 |         errno
import time:      4047 |     100176 |       socket
import time:      2550 |       2550 |         signal
import time:       713 |        713 |         _posixsubprocess
import time:     92993 |      96255 |       subprocess
import time:      2475 |       2475 |         _ssl
import time:      1010 |       1010 |             _struct
import time:       235 |       1244 |           struct
import time:     85825 |      85825 |           binascii
import time:       631 |      87699 |         base64
import time:      5161 |      95334 |       ssl
import time:      3549 |       3549 |       asyncio.constants
import time:       395 |        395 |               _opcode
import time:       836 |       1231 |             opcode
import time:      1256 |       2486 |           dis
import time:       718 |        718 |             importlib
import time:       632 |       1349 |           importlib.machinery
import time:     95292 |      99126 |         inspect
import time:      2461 |       2461 |           asyncio.format_helpers
import time:      3483 |       5943 |         asyncio.base_futures
import time:     87232 |      87232 |         asyncio.log
import time:      3981 |     196280 |       asyncio.coroutines
import time:       723 |        723 |           _contextvars
import time:      1069 |       1792 |         contextvars
import time:     87770 |      87770 |           asyncio.base_tasks
import time:      2261 |      90031 |         _asyncio
import time:      9031 |     100853 |       asyncio.events
import time:      3099 |       3099 |       asyncio.futures
import time:      1285 |       1285 |       asyncio.protocols
import time:      1635 |       1635 |         asyncio.transports
import time:      3742 |       5377 |       asyncio.sslproto
import time:     94459 |      94459 |       asyncio.tasks
import time:    187970 |    1092612 |     asyncio.base_events
import time:      5250 |       5250 |     asyncio.locks
import time:     88265 |      88265 |     asyncio.runners
import time:      4817 |       4817 |     asyncio.queues
import time:      5412 |       5412 |     asyncio.streams
import time:      2363 |       2363 |     asyncio.subprocess
import time:      3087 |       3087 |       asyncio.base_subprocess
import time:     95452 |      95452 |       asyncio.selector_events
import time:    188089 |     286627 |     asyncio.unix_events
import time:      5128 |    1490471 |   asyncio
import time:       123 |        123 |       gc
import time:       626 |        749 |     uvloop.includes
import time:       559 |        559 |     uvloop._patch
import time:       223 |        223 |       backports_abc
import time:       274 |        274 |       uvloop._noop
import time:       261 |        261 |           _queue
import time:       429 |        689 |         queue
import time:      2178 |       2867 |       concurrent.futures.thread
import time:     94008 |      97371 |     uvloop.loop
import time:      1340 |     100017 |   uvloop
import time:      1220 |       1220 |   fdk.constants
import time:       393 |        393 |   fdk.log
import time:       677 |        677 |           numbers
import time:      1196 |       1873 |         _decimal
import time:       321 |       2193 |       decimal
import time:      1297 |       1297 |         _datetime
import time:      1397 |       2694 |       datetime
import time:       606 |       5492 |     ujson
import time:       407 |        407 |       xml
import time:       690 |       1096 |     xml.etree
import time:       727 |        727 |       contextlib
import time:      2094 |       2094 |       xml.etree.ElementPath
import time:       133 |        133 |               org
import time:        84 |        216 |             org.python
import time:        37 |        253 |           org.python.core
import time:       388 |        640 |         copy
import time:       505 |        505 |         pyexpat
import time:       999 |       2142 |       _elementtree
import time:     90014 |      94976 |     xml.etree.ElementTree
import time:      2823 |       2823 |         iso8601.iso8601
import time:       373 |       3196 |       iso8601
import time:       361 |        361 |         fdk.headers
import time:       565 |        925 |       fdk.context
import time:       646 |        646 |         fdk.response
import time:      1151 |       1796 |       fdk.errors
import time:     92801 |      98717 |     fdk.runner
import time:       687 |        687 |     fdk.http
import time:       389 |        389 |       fdk.http.parser
import time:       319 |        319 |       fdk.http.streams
import time:       318 |        318 |       urllib
import time:      1783 |       1783 |       urllib.parse
import time:       984 |       3791 |     fdk.http.request
import time:      1683 |       1683 |       http
import time:       413 |       2096 |     fdk.http.response
import time:       934 |     207785 |   fdk.http_stream
import time:       906 |    1800790 | fdk

Expected behaviour

cold start shouldn't be a problem to aiohttp

Actual behaviour

cold start within the given constraints is a huge problem to aiohttp

Steps to reproduce

A library that uses aiohttp is in OSS, https://github.com/fnproject/fdk-python.
Feel free to reach out me for more details and code spinnets.

Your environment

Python 3.7.1
Docker (latest)
Linux Alpine, Debian Stretch

@aio-libs-bot
Copy link

GitMate.io thinks the contributor most likely able to help you is @asvetlov.

Possibly related issues are #2302 (Issue with MultipartReader), #206 (SSL issue with aiohttp.request), #487 (Issue with mailgun routed data?), #70 (MultiDict issues in http request), and #82 (Fix proxy issue).

@asvetlov
Copy link
Member

asvetlov commented Dec 1, 2018

I have no idea why is you box so slow.
aiohttp import time is 0.2-0.3 sec on my laptop, servers show even better performance.
PYTHONPROFILEIMPORTTIME=1 adds extra slowdown (measurer take CPU time on measuring obviously), with this flag aiohttp import time is increased to 0.3-0.4 sec.

Numbers are 10 times different from yours 4-8 sec.

@denismakogon
Copy link
Author

I provided exact constraints for the docker container that are considered to be bare minimum requirements for the UDS servers written with various programming languages to start:
--cpu-quota=10000 --cpu-period=100000 --cpu-shares=128 --memory=128m --kernel-memory=128m --memory-swap=128m. With this constraints aiohttp takes at least 7.5-8 seconds to start and that’s problem that may lead to a statement that aiohttp was never designed for the resources and devices with limited resources.

Your laptop is definitely not the best device to debug this issue, definitely.

@asvetlov
Copy link
Member

asvetlov commented Dec 1, 2018

Have you a concrete proposal for improvement?
Otherwise, let's state that aiohttp (and Python itself also) was not designed to work in a very limited environment and close the issue.

@thehesiod
Copy link
Contributor

@denismakogon I suggest stating what is being imported. I wouldn't import aiohttp, that will get you almost everything, just import what you need.

@denismakogon
Copy link
Author

I’m not doing thing like import aiohttp. The only import is: from aiohttp import web - that’s what causes the delay.

@asvetlov
Copy link
Member

asvetlov commented Dec 1, 2018

Looking at numbers from tables above I see that the import of asyncio itself is 2.8 secs from the first table and 1.5 sec from the second.
It doesn't provide any time budget, isn't it?

@denismakogon
Copy link
Author

The difference between table one and table two is in a number of imports from the asyncio, that’s why you see the difference.

@denismakogon
Copy link
Author

All related routine to an aiohttp is here (master branch): https://github.com/fnproject/fdk-python/blob/master/fdk/http_stream.py#L90-L159

And here's the code that i plan to use as a substitution on aiohttp: https://github.com/fnproject/fdk-python/blob/performance/fdk/http_stream.py#L66-L115

I can provide steps to reproduce including code samples of this lib with dockerfiles, so you can build and see the numbers by yourself.

So, @asvetlov you asked me about the solution here. Well, the best we can do is to actually extract HTTP core API to a library that would be a native asyncio-based http framework which is very similar to SimpleHTTP server (https://docs.python.org/3/library/http.server.html) and make aiohttp be based on it. Like if you need a simple concurrent asyncio HTTP server - use lib, if you'd like to go to production lots of nifty features - go with aiohttp.

@asvetlov
Copy link
Member

asvetlov commented Dec 1, 2018

If you've found a solution that satisfies all your needs -- that's fine.

Closing the issue.

@asvetlov asvetlov closed this as completed Dec 1, 2018
@thehesiod
Copy link
Contributor

interesting that aiohttp.client_reqrep and aiohttp.client seem to be huge. The breakdown seems to be missing a lot of detail.

@lock
Copy link

lock bot commented Dec 3, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Dec 3, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants