473,387 Members | 1,283 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Fast Imaging for Webserver

Hi. I'm creating a web-application using CherryPy 2.2.1. My application
needs to process images (JPG/PNG files) to

1) create thumbnails (resize them)
2) overlay them on a custom background (a simple frame)
3) Overlay 'badges' (small 16x16 images) on top of the final thumbnail

I am using PIL 1.1.5 which I have custom compiled on my development
machine (MacBook Pro 2.33Ghz Core Duo)..
I am using im.thumbnail for step 1 and im.paste for steps 2 and 3.

The problem is that this thing is just way too slow.
For ab -n 1000 -C session_id=2f55ae2dfefa896f67a80f73045aadfa4b4269f 1
http://localhost:8080/imaging/icon/def/128/255 (where def is the name
of the image - default in this case - 128 is the size in pixels and 255
is the background color), I am getting:

Document Path: /imaging/icon/def/128/255
Document Length: 14417 bytes

Concurrency Level: 1
Time taken for tests: 18.664 seconds
Complete requests: 1000
Failed requests: 0
Broken pipe errors: 0
Total transferred: 14680000 bytes
HTML transferred: 14417000 bytes
Requests per second: 53.58 [#/sec] (mean)
Time per request: 18.66 [ms] (mean)
Time per request: 18.66 [ms] (mean, across all concurrent
requests)
Transfer rate: 786.54 [Kbytes/sec] received

FYI: This request returns a PNG image (image/png) and not html

My understanding is that the problem is either with the CherryPy setup
(which is likely because even in other cases, i don't get much more
than 65 requests per second) or PIL itself (even though I'm caching the
background images and source images)

Does anyone have a better solution? Is there a faster replacement for
PIL?

Thanks in advance.
Prateek

Jan 25 '07 #1
5 1587
On Jan 25, 12:46 am, "Prateek" <sure...@gmail.comwrote:
Concurrency Level: 1
Time taken for tests: 18.664 seconds
Complete requests: 1000
Failed requests: 0
Broken pipe errors: 0
Total transferred: 14680000 bytes
HTML transferred: 14417000 bytes
Requests per second: 53.58 [#/sec] (mean)
Time per request: 18.66 [ms] (mean)
Time per request: 18.66 [ms] (mean, across all concurrent
requests)
Transfer rate: 786.54 [Kbytes/sec] received

FYI: This request returns a PNG image (image/png) and not html

My understanding is that the problem is either with the CherryPy setup
(which is likely because even in other cases, i don't get much more
than 65 requests per second) or PIL itself (even though I'm caching the
background images and source images)

Does anyone have a better solution? Is there a faster replacement for
PIL?
So you have some gross level statistics on how long a request takes to
process, that's good. But before you start replacing PIL, or
optimizing CherryPy, or other possible performance-improving efforts,
you should profile the within-request processing, find the bottleneck,
and take care of that first. Without profiling info, you can easily
spend days optimizing out 90% of a task that takes 2% of the total
processing time, for little net gain.

-- Paul

Jan 25 '07 #2

On Jan 24, 10:46 pm, "Prateek" <sure...@gmail.comwrote:
Hi. I'm creating a web-application using CherryPy 2.2.1. My application
needs to process images (JPG/PNG files) to

1) create thumbnails (resize them)
2) overlay them on a custom background (a simple frame)
3) Overlay 'badges' (small 16x16 images) on top of the final thumbnail

I am using PIL 1.1.5 which I have custom compiled on my development
machine (MacBook Pro 2.33Ghz Core Duo)..
I am using im.thumbnail for step 1 and im.paste for steps 2 and 3.

The problem is that this thing is just way too slow.
For ab -n 1000 -C session_id=2f55ae2dfefa896f67a80f73045aadfa4b4269f 1http://localhost:8080/imaging/icon/def/128/255(where def is the name
of the image - default in this case - 128 is the size in pixels and 255
is the background color), I am getting:

Document Path: /imaging/icon/def/128/255
Document Length: 14417 bytes

Concurrency Level: 1
Time taken for tests: 18.664 seconds
Complete requests: 1000
Failed requests: 0
Broken pipe errors: 0
Total transferred: 14680000 bytes
HTML transferred: 14417000 bytes
Requests per second: 53.58 [#/sec] (mean)
Time per request: 18.66 [ms] (mean)
Time per request: 18.66 [ms] (mean, across all concurrent
requests)
Transfer rate: 786.54 [Kbytes/sec] received

FYI: This request returns a PNG image (image/png) and not html

My understanding is that the problem is either with the CherryPy setup
(which is likely because even in other cases, i don't get much more
than 65 requests per second) or PIL itself (even though I'm caching the
background images and source images)

Does anyone have a better solution? Is there a faster replacement for
PIL?

Thanks in advance.
Prateek
Check out the mac CoreGraphics bindings. Not sure if it will be any
faster, but it can do what you want.

http://www.macdevcenter.com/pub/a/ma..._graphics.html

~Sean DiZazzo

Jan 25 '07 #3
Paul McGuire:
before you start replacing PIL, or
optimizing CherryPy, or other possible performance-improving efforts,
you should profile the within-request processing, find the bottleneck,
and take care of that first.
Good advice.
Among the tests, the OP can also try to change the antialiasing type of
PIL, going to the nearest neighbor, and doing some transfer timings
again. It may help find where the bottleneck is.

Bye,
bearophile

Jan 25 '07 #4
"Prateek" wrote:
Hi. I'm creating a web-application using CherryPy 2.2.1. My application
needs to process images (JPG/PNG files) to

1) create thumbnails (resize them)
2) overlay them on a custom background (a simple frame)
3) Overlay 'badges' (small 16x16 images) on top of the final thumbnail

I am using PIL 1.1.5 which I have custom compiled on my development
machine (MacBook Pro 2.33Ghz Core Duo)..
I am using im.thumbnail for step 1 and im.paste for steps 2 and 3.

The problem is that this thing is just way too slow.
For ab -n 1000 -C session_id=2f55ae2dfefa896f67a80f73045aadfa4b4269f 1
http://localhost:8080/imaging/icon/def/128/255 (where def is the name
of the image - default in this case - 128 is the size in pixels and 255
is the background color), I am getting:

Document Path: /imaging/icon/def/128/255
Document Length: 14417 bytes

Concurrency Level: 1
Time taken for tests: 18.664 seconds
Complete requests: 1000
Failed requests: 0
Broken pipe errors: 0
Total transferred: 14680000 bytes
HTML transferred: 14417000 bytes
Requests per second: 53.58 [#/sec] (mean)
Time per request: 18.66 [ms] (mean)
Time per request: 18.66 [ms] (mean, across all concurrent
requests)
Transfer rate: 786.54 [Kbytes/sec] received

FYI: This request returns a PNG image (image/png) and not html

My understanding is that the problem is either with the CherryPy setup
(which is likely because even in other cases, i don't get much more
than 65 requests per second) or PIL itself (even though I'm caching the
background images and source images)
without knowing more about what kind of source images you're using, the
amount of data they represent etc, it's not entirely obvious to me that 50+
images per second on a single server is that bad, really. unless the source
images are rather tiny, that's plenty of pixels per second to crunch.

are you really receiving more than 4500000 source images per day per
server?

</F>

Jan 25 '07 #5
Thanks for all the responses so far..

The 'imaging' app that I mentioned is actually serving as a library for
a bunch of other apps.
A typical scenario is icon processing. The source image *could* be
large (in this case it was 128x128 PNGA)

Think of it as a Mac Finder/Win Explorer style view (grid + imagelist)
where you're showing a bunch of data in icon form (16x16). For small
amounts of data, everything is ok... but as soon as I get to 600-700
items, the page takes forever to load. The obvious solution is
pagination but I'm doing some aggregate analysis on the data (like a
frequency distribution) where if I were to paginate the data, i'd lose
the client-side sorting ability (I'd have to sort server side which is
a whole other can of worms).

I'm gonna take Paul's advice and report as soon as I can. One other
alternative is to save this information on the filesystem (as temp
files) and route all future requests via the static file processing
mechanism (which can be handled by Apache)... do you think that is a
good idea?

Prateek

On Jan 25, 3:11 pm, "Fredrik Lundh" <fred...@pythonware.comwrote:
"Prateek" wrote:
Hi. I'm creating a web-application using CherryPy 2.2.1. My application
needs to process images (JPG/PNG files) to
1) create thumbnails (resize them)
2) overlay them on a custom background (a simple frame)
3) Overlay 'badges' (small 16x16 images) on top of the final thumbnail
I am using PIL 1.1.5 which I have custom compiled on my development
machine (MacBook Pro 2.33Ghz Core Duo)..
I am using im.thumbnail for step 1 and im.paste for steps 2 and 3.
The problem is that this thing is just way too slow.
For ab -n 1000 -C session_id=2f55ae2dfefa896f67a80f73045aadfa4b4269f 1
http://localhost:8080/imaging/icon/def/128/255(where def is the name
of the image - default in this case - 128 is the size in pixels and 255
is the background color), I am getting:
Document Path: /imaging/icon/def/128/255
Document Length: 14417 bytes
Concurrency Level: 1
Time taken for tests: 18.664 seconds
Complete requests: 1000
Failed requests: 0
Broken pipe errors: 0
Total transferred: 14680000 bytes
HTML transferred: 14417000 bytes
Requests per second: 53.58 [#/sec] (mean)
Time per request: 18.66 [ms] (mean)
Time per request: 18.66 [ms] (mean, across all concurrent
requests)
Transfer rate: 786.54 [Kbytes/sec] received
FYI: This request returns a PNG image (image/png) and not html
My understanding is that the problem is either with the CherryPy setup
(which is likely because even in other cases, i don't get much more
than 65 requests per second) or PIL itself (even though I'm caching the
background images and source images)without knowing more about what kind of source images you're using, the
amount of data they represent etc, it's not entirely obvious to me that 50+
images per second on a single server is that bad, really. unless the source
images are rather tiny, that's plenty of pixels per second to crunch.

are you really receiving more than 4500000 source images per day per
server?

</F>
Jan 25 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Richard | last post by:
In the days of VB6 I would often use the Wang/Kodak Imaging control that ships with Windows to process TIFF files. Drop the ocx on a form and TIFF file manipulation is all very easy. So how do...
0
by: MC | last post by:
Hi, I'm developing an VB.NET app that converts TIFFs to PDFs using Office Imaging 2003 and Adobe Distiller 6.0 in the follwing way: 1. Using automation, I open the TIFF file with Office...
0
by: Stedak | last post by:
My application seems to freeze when Microsoft Office Document Imaging is set as the default for loading images. If the Windows Picture and Fax Viewer is used there is no problem. When I set a break...
4
by: Harry | last post by:
Hello, I am using a 2-dimensional matrix for image manipulation and recognition. The x-axes is image.width pixels long and the y-axes image.height. All fields have a RGB integer value. To store...
3
by: David A. Osborn | last post by:
I currently have a class that has an enumeration of graphics extensions that it supports ie: Public Enum GraphicFormats JPG JPEG BMP TIFF End Enum
6
by: André | last post by:
Hi, I made a webform for a survey, with multiple-choice questions. The results of each question is put into a table e.g.: values frequency 1 6 2 3 3 32 4 ...
4
by: setesting001 | last post by:
How many of you are running Fast CGI instead of the popular mod_php? I planning to change to fast cgi since my applications need around 15MB memory to handle a single request, so consider if...
0
by: Peter Morris | last post by:
A while ago I asked how to replace an image with a solid black colour whilst preserving the alpha mask/channel, this was so that I could automatically create a drop shadow. For future reference of...
0
by: tavares | last post by:
----------------------------------------------------------------------------------------------------------------------------------------- (Apologies for cross-posting) International Journal of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.