Thanks Niphlod for your help,
Seems a connection to a legacy database was a culprit for a real slow 
down...


On Thursday, August 22, 2013 4:31:22 PM UTC-4, Niphlod wrote:
>
> uhm. download() lets web2py stream the file instead of nginx. 
> fast_download() too, it just skips the part that handles the authorization 
> logic and adds correct cache headers, but this will lead to faster loading 
> of pages from the 2nd time the user accesses the page: it won't change a 
> thing in the 1st request.
>
> Why don't you just put those images in "static/something" ?
>
> The other very smart thing to do is using http://wiki.nginx.org/X-accel . 
> This basically enables nginx to "intercept" an empty page with some special 
> headers (so web2py does it without even accessing the file) and take care 
> of serving the file instead of your application. This will probably speed 
> up your 1st request (and releaves some pressure from the web2py process), 
> but the hard-limit of bandwith will of course remain there, no matter what.
>
> Your fast download will then kinda look like 
> def fast_download():
>     ....
>     filename = os.path.join(request.folder,'uploads',request.args(0))
>     response.headers['X-Accel-Redirect'] = os.path.join(request.folder, 
> 'uploads', document.file)
>      return ''
>
>
>
> On Thursday, August 22, 2013 10:06:34 PM UTC+2, Adi wrote:
>>
>>
>>
>> Hello everyone.
>>
>> Am trying to populate a page with around 20 dynamic images from the 
>> upload folder, but they get rendered extremely slow, even as thumbnails. 
>> Tried using a suggest approach from the forum "fast_download()", but 
>> without luck in my case. 
>>
>> Anyone has a suggestion, what should I be looking at, and how to improve 
>> the speed of loading dynamic images? 
>>
>> Platform: clean ubuntu node with web2py and nginx (no caching setup, 1Gb 
>> of ram). Nothing else is running on it.
>>
>> Performed following three tests:
>>
>> Regular download():
>> Compressed images (through PIL, with extension .thumbnail): 
>> http://www.webpagetest.org/result/130822_1F_WAD/ (500Kb in 25 sec)
>> Regular size images: http://www.webpagetest.org/result/130822_5K_ZSX/(3Mb in 
>> 26 sec)
>>
>> Fast_Download() with regular size images:
>> http://www.webpagetest.org/result/130822_C3_1008/ (3Mb in 28 sec)
>>
>> Tried to implement caching in nginx site config, but that disabled images 
>> completely, and I couldn't get it to work:
>>
>> #location ~* ^.+\.(jpg|jpeg|gif)$ {
>> #   root         /home/www-data/web2py/applications/;
>> #   access_log   off;
>> #   expires      30d;
>> #}
>>
>> or 
>>
>> #location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
>>  #    access_log off;
>>  #    log_not_found off;
>>  #    expires 180d;
>>  #}
>>
>> Fast download used: 
>> def fast_download():
>>     session.forget(response)
>>     cache.action(time_expire=604800)(lambda: 0)()
>>
>>     # very basic security (only allow fast_download on 
>> your_table.upload_field):
>>     if not request.args(0).startswith("product.image"):
>>     return download()
>>
>>     filename = os.path.join(request.folder,'uploads',request.args(0))
>>
>>     return response.stream(open(filename,'rb'))
>>
>>
>> Segment of the code that displays the images:
>>
>>                         <div id="prod_img" itemprop="image">
>>                             {{if p.image:}}
>>                                 <a href="{{=product_link}}">
>>                 {{
>>                 #big_regex = re.compile('|'.join(map(re.escape, 
>> IMAGE_EXTENSIONS)))
>>                 #tmb_image = big_regex.sub(INDEX_TMB, p.image)
>>                 }}
>>                                 <img src="{{=URL('download', 
>> args=p.image, scheme=True, host=True)}}" 
>>                     alt="{{=product_name}}" href="{{=product_link}}" 
>> height="180px" width="160px"/>
>>                                 </a>
>>                             <img data-src='{{=tmb_image}}' >
>>                                 {{pass}}
>>                         </div>
>>
>>
>>
>>
>>  
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to