Sometimes bottle takes a lot of time

Cecil Westerhof Cecil at decebal.nl
Sat Aug 22 23:06:03 CEST 2015


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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: fetch.log
Type: text/x-log
Size: 1656 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20150822/baacbfe3/attachment.bin>
-------------- next part --------------

So my next bet is AngularJS.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


More information about the Python-list mailing list