Friday, December 14, 2007

Images and CFDocument performance

Sometime back one of our customer reported that using png images in cfdocument makes it very very slow. I could not replicate it with any png image but it did happen with his png image.

Today, Andy reported a similar issue but this time it was for jpeg images. In both the cases, performance hit is huge and it does not happen with all the images.

I spent a significant amount of time debugging it today and it turns out that the reason for both the issues are same - there is something special about these images and that is colorspace. All these images actually had a different colorspace than what java imaging uses. Because of this, when we need the pixel values of image to print it on pdf (by calling BufferedImage.getRGB()), it tries to convert this colorspace to RGB colorspace and that is very very costly. That is where the entire time goes. So how do you fix it? I opened all the images in an image editor and saved it again. This time it got saved in standard RGB colorspace and the time taken to create the pdf got reduced from 110 sec to 1.5 seconds. That is huge!!! Isn't it? But can you control all the images over the web? NO.. right? Read on.. there is more to this story.

A little bit of looking up on web pointed me to this Sun bug which is the exact same bug which we were hitting. Thankfully it got fixed in mustang i.e JDK1.6 which ColdFusion8 uses by default. But hey wait a second.. Didn't Andy say that he is seeing it on ColdFusion 8? why do we still see this happening when it is fixed in JDK1.6? It appears that this bug was fixed only in core JDK api but not in JAI (Java advanced imaging) codecLib that ColdFusion 8 uses. So what do we do now? You can do either of these two

  1. Remove clibwrapper_jiio.jar from "lib" folder.
  2. Or, set this system property to the JVM. -Dcom.sun.media.imageio.disableCodecLib=true . You can set this in [cf-install_dir]/runtime/bin/jvm.config if you are using standalone coldfusion server.

You should keep in mind that codecLib libraries are native libraries which are meant to increase the java imaging performance. So disabling it might degrade the performance of CFImage somewhere. Also keep in mind that removing this jar or disabling codecLib will not result into any loss of functionality - it just means that all image operations will be pure java.

There is another related Sun's bug which I thought might be useful to you. Image loading might get very slow if the server is running in debug mode. Your server is running in debug mode if you see something like this in your jvm.config or VM startup option.

-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
This bug got introduced in JDK1.6 and does not exist on 1.5. So make sure that you are not running the server in debug mode.

To summarise, you can do following to increase the performance of image loading in cfdocument.
  1. If you are on JDK1.5, there is not much you can do. The only option is to change the colorspace of images. I will try to see if we can address this in ColdFusion code.
  2. If you are on JDK1.6,
    • Disable codecLib as mentioned above.
    • Disable debug mode by removing the complete debug string mentioned above
  3. In addition to this, you might want to use 'localurl' attribute for cfdocument tag. See this for more details.

9 comments:

hemant said...

Excellent article Rupesh!

creole said...

As the one who brought up this issue, I can say from the bottom of my heart, THANK YOU Rupesh. I just tried your simple fix, which was to resave the images with a different color profile and it worked like a charm. Not to mention that it also reduced the file size of all of the images used in this particular proposal from 1.35 megs to 776k. That's what you get when you let the client upload their own images.

I created an action for the client which alters the built-in color profile to sRGB. I'll push that to them and ask them to change their file saving strategy.

You rock my friend!

Rupesh Kumar said...

@Hemant, thanks !

@Creole,I am glad to know that it helped and thanks for the nice comment.
I am curious to know how do you change the color profile to sRGB programmatically on upload? Are you using cfimage for that?

webRat said...

@Rupesh, he said he created an action, so I'm assuming that means he created a Photoshop action that manipulates the color profile to sRGB.

MB4042 said...

I have a weird one. I developed a fairly complex cfdocument report with JPEG images. It worked fine in my test environment, producing a 185 page document in about 10 seconds.

But, as soon as I moved it over to production (CF 7.0.2 Cumulative Hotfix 3 running on Server 2003/IIS 6.0), it takes 30-60 seconds for even 5 pages of the report.

Then, I tried a funny thing. I switched the images to PNG, and the PDF created as quick in production as it did in my test environment.

My images are all RGB, but JPEG's slow down the report in my production environment.

java -version gives me the same in my test and production environments.

cvxv said...

看房子,買房子,建商自售,自售,台北新成屋,台北豪宅,新成屋,豪宅,美髮儀器,美髮,儀器,髮型,EMBA,MBA,學位,EMBA,專業認證,認證課程,博士學位,DBA,PHD,在職進修,碩士學位,推廣教育,DBA,進修課程,碩士學位,網路廣告,關鍵字廣告,關鍵字,課程介紹,學分班,文憑,牛樟芝,段木,牛樟菇,日式料理, 台北居酒屋,日本料理,結婚,婚宴場地,推車飲茶,港式點心,尾牙春酒,台北住宿,國內訂房,台北HOTEL,台北婚宴,飯店優惠,台北結婚,場地,住宿,訂房,HOTEL,飯店,造型系列,學位,SEO,婚宴,捷運,學區,美髮,儀器,髮型,看房子,買房子,建商自售,自售,房子,捷運,學區,台北新成屋,台北豪宅,新成屋,豪宅,學位,碩士學位,進修,在職進修, 課程,教育,學位,證照,mba,文憑,學分班,台北住宿,國內訂房,台北HOTEL,台北婚宴,飯店優惠,住宿,訂房,HOTEL,飯店,婚宴,台北住宿,國內訂房,台北HOTEL,台北婚宴,飯店優惠,住宿,訂房,HOTEL,飯店,婚宴,台北住宿,國內訂房,台北HOTEL,台北婚宴,飯店優惠,住宿,訂房,HOTEL,飯店,婚宴,結婚,婚宴場地,推車飲茶,港式點心,尾牙春酒,台北結婚,場地,結婚,場地,推車飲茶,港式點心,尾牙春酒,台北結婚,婚宴場地,結婚,婚宴場地,推車飲茶,港式點心,尾牙春酒,台北結婚,場地,居酒屋,燒烤,美髮,儀器,髮型,美髮,儀器,髮型,美髮,儀器,髮型,美髮,儀器,髮型,小套房,小套房,進修,在職進修,留學,證照,MBA,EMBA,留學,MBA,EMBA,留學,進修,在職進修,牛樟芝,段木,牛樟菇,關鍵字排名,網路行銷,PMP,在職專班,研究所在職專班,碩士在職專班,PMP,證照,在職專班,研究所在職專班,碩士在職專班,SEO,廣告,關鍵字,關鍵字排名,網路行銷,網頁設計,網站設計,網站排名,搜尋引擎,網路廣告,SEO,廣告,關鍵字,關鍵字排名,網路行銷,網頁設計,網站設計,網站排名,搜尋引擎,網路廣告,SEO,廣告,關鍵字,關鍵字排名,網路行銷,網頁設計,網站設計,網站排名,搜尋引擎,網路廣告,SEO,廣告,關鍵字,關鍵字排名,網路行銷,網頁設計,網站設計,網站排名,搜尋引擎,網路廣告,EMBA,MBA,PMP,在職進修,專案管理,出國留學,EMBA,MBA,PMP,在職進修,專案管理,出國留學,EMBA,MBA,PMP,在職進修,專案管理,出國留學,婚宴,婚宴,婚宴,婚宴,漢高資訊,漢高資訊,比利時,比利時聯合商學院,宜蘭民宿,台東民宿,澎湖民宿,墾丁民宿,花蓮民宿,SEO,找工作,汽車旅館,阿里山,日月潭,阿里山民宿,東森購物,momo購物台,pc home購物,購物漢高資訊,漢高資訊,在職進修,漢高資訊,在職進修,住宿,住宿,整形,造型,室內設計,室內設計,漢高資訊,在職進修,漢高資訊,在職進修,住宿,美容,室內設計,在職進修,羅志祥,周杰倫,五月天,住宿,住宿,整形,整形,室內設計,室內設計,比利時聯合商學院,在職進修,比利時聯合商學院,在職進修,漢高資訊,找工作,找工作,找工作,找工作,找工作,蔡依林,林志玲

Anonymous said...

酒店喝酒,禮服店,酒店小姐,傳播妹,便服店,鋼琴酒吧,酒店兼職,酒店兼差,酒店打工,伴唱小姐,暑假打工,酒店上班,酒店兼職,ktv酒店,酒店,酒店公關,酒店兼差,酒店上班,酒店打工,禮服酒店,禮服店,酒店小姐,酒店兼差,暑假打工,酒店小姐,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,寒假打工,酒店小姐,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,暑假打工,酒店小姐,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,寒假打工,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,暑假打工,酒店小姐,台北酒店,禮服店 ,酒店小姐,酒店兼差,暑假打工,酒店小姐,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,寒假打工,酒店小姐,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,暑假打工,酒店小姐,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,寒假打工,酒店小姐,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,暑假打工,酒店小姐,禮服店 ,酒店小姐,酒店經紀,酒店兼差,寒假打工,酒店小姐,禮服店 ,酒店小姐,酒店經紀,酒店兼差,暑假打工,酒店小姐,禮服店 ,酒店小姐,酒店經紀,酒店兼差,寒假打工,酒店小姐,禮服店 ,酒店小姐,酒店經紀,酒店兼差,暑假打工,酒店小姐,酒店傳播,酒店經紀人,酒店,酒店,酒店,酒店 ,禮服店 , 酒店小姐,酒店經紀,酒店兼差,暑假打工,招待所,酒店小姐,酒店兼差,寒假打工,酒店上班,暑假打工,酒店公關,酒店兼職,禮服店 , 酒店小姐 ,酒店經紀 ,酒店兼差,暑假打工,酒店,酒店,酒店經紀,

Anonymous said...

酒店喝酒,禮服店,酒店小姐,酒店領檯,便服店,鋼琴酒吧,酒店兼職,酒店兼差,酒店打工,伴唱小姐,暑假打工,酒店上班,酒店兼職,ktv酒店,酒店,酒店公關,酒店兼差,酒店上班,酒店打工,禮服酒店,禮服店,酒店小姐,酒店兼差,暑假打工,酒店經紀,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,寒假打工,酒店小姐,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,暑假打工,酒店小姐,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,寒假打工,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,暑假打工,酒店小姐,台北酒店,禮服店 ,酒店小姐,酒店兼差,暑假打工,酒店小姐,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,寒假打工,酒店小姐,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,暑假打工,酒店小姐,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,寒假打工,酒店小姐,台北酒店,禮服店 ,酒店小姐,酒店經紀,酒店兼差,暑假打工,酒店小姐,禮服店 ,酒店小姐,酒店經紀,酒店兼差,寒假打工,酒店小姐,禮服店 ,酒店小姐,酒店經紀,酒店兼差,暑假打工,酒店小姐,禮服店 ,酒店小姐,酒店經紀,酒店兼差,寒假打工,酒店小姐,禮服店 ,酒店小姐,酒店經紀,酒店兼差,暑假打工,酒店小姐,酒店傳播,酒店經紀人,酒店,酒店,酒店,酒店 ,禮服店 , 酒店小姐,酒店經紀,酒店兼差,暑假打工,招待所,酒店小姐,酒店兼差,寒假打工,酒店上班,暑假打工,酒店公關,酒店兼職,禮服店 , 酒店小姐 ,酒店經紀 ,酒店兼差,暑假打工,酒店,酒店,酒店經紀,酒店領檯 ,禮服店 ,酒店小姐 ,酒店經紀 ,酒店兼差,暑假打工, 酒店上班,禮服店 ,酒店小姐 ,酒店經紀 ,酒店兼差,暑假打工, 酒店上班,禮服店 ,酒店小姐 ,酒店經紀 ,酒店兼差,暑假打工, 酒店上班,酒店經紀

Anonymous said...

福~
「朵
語‧,最一件事,就。好,你西...............................................................................................................................-...相互
,以讓>它使...................