Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.python Subject: Re: Sometimes bottle takes a lot of time Date: Sat, 22 Aug 2015 23:06:03 +0200 Organization: Decebal Computing Lines: 166 Message-ID: <87lhd3m3t0.fsf@Equus.decebal.nl> References: <87si7cnxq6.fsf@Equus.decebal.nl> <87a8tjo8oz.fsf@Equus.decebal.nl> <87pp2fmc9z.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: mx02.eternal-september.org; posting-host="528adfd6ad074c92fdc6a7f8fb9e23d8"; logging-data="21583"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18X+wc5Q3dbSkioGUiGdpF+chcif3SnzHU=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Homepage: http://www.decebal.nl/ Cancel-Lock: sha1:P37gVJxFfcciU8BolUAHOdudLco= sha1:st/ooIxFrMXv51HqLYq0zP2Qs6Q= Xref: csiph.com comp.lang.python:95566 --=-=-= Content-Type: text/plain On Saturday 22 Aug 2015 20:03 CEST, Cecil Westerhof wrote: > On Saturday 22 Aug 2015 17:33 CEST, Michael Torrie wrote: > >> On 08/22/2015 05:37 AM, Cecil Westerhof wrote: >>>> I don't know. Is it bottle, or the browser, or something >>>> completely different that eats the extra time? >>> >>> I really do not know. I suspect bottle, but I am new to this, so I >>> value the suspicion of someone who has more experience more. :-D >> >> These are requests performed from browser Javascript (ajax), right? >> Could you write a shell script that fetches these urls in sequence >> using curl or wget, simulating the web browser? This would let you >> check times in a controlled way, without the variable of the >> browser itself. > > I should have thought about that myself. :-( I used Python instead of a shell script of-course. :-P ======================================================================== #!/usr/bin/env python3 import time from urllib.request import urlopen server = 'http://localhost:8080' urls = [ '/', '/static/css/default.css', '/static/JavaScript/angular.js', '/static/appPublishedPhotos.js', '/links/data', '/versionPython', '/versionSQLite', ] for x in range(0, 10): start_time = time.time() for url in urls: print(url) urlopen(server + url).read() end_time = time.time() print('It took {0} seconds\n'.format(end_time - start_time), flush = True) time.sleep(20) ======================================================================== It is not perfect code, no error checking and the last sleep is superfluous, but for the current job good enough. I have included the output as attachment. It is clear that bottle is not the problem: fetching all the data takes at most 0.017 seconds. --=-=-= Content-Type: text/x-log Content-Disposition: inline; filename=fetch.log / /static/css/default.css /static/JavaScript/angular.js /static/appPublishedPhotos.js /links/data /versionPython /versionSQLite It took 0.012779951095581055 seconds / /static/css/default.css /static/JavaScript/angular.js /static/appPublishedPhotos.js /links/data /versionPython /versionSQLite It took 0.010144948959350586 seconds / /static/css/default.css /static/JavaScript/angular.js /static/appPublishedPhotos.js /links/data /versionPython /versionSQLite It took 0.010040283203125 seconds / /static/css/default.css /static/JavaScript/angular.js /static/appPublishedPhotos.js /links/data /versionPython /versionSQLite It took 0.013696908950805664 seconds / /static/css/default.css /static/JavaScript/angular.js /static/appPublishedPhotos.js /links/data /versionPython /versionSQLite It took 0.01705002784729004 seconds / /static/css/default.css /static/JavaScript/angular.js /static/appPublishedPhotos.js /links/data /versionPython /versionSQLite It took 0.009366750717163086 seconds / /static/css/default.css /static/JavaScript/angular.js /static/appPublishedPhotos.js /links/data /versionPython /versionSQLite It took 0.011032581329345703 seconds / /static/css/default.css /static/JavaScript/angular.js /static/appPublishedPhotos.js /links/data /versionPython /versionSQLite It took 0.015336990356445312 seconds / /static/css/default.css /static/JavaScript/angular.js /static/appPublishedPhotos.js /links/data /versionPython /versionSQLite It took 0.016999244689941406 seconds / /static/css/default.css /static/JavaScript/angular.js /static/appPublishedPhotos.js /links/data /versionPython /versionSQLite It took 0.010639429092407227 seconds --=-=-= Content-Type: text/plain So my next bet is AngularJS. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof --=-=-=--