Performance differences with ColdFusion working with Java objects

241 views
Skip to first unread message

WebFlint

unread,
May 16, 2009, 10:15:08 AM5/16/09
to Railo
I was playing around with the following code this morning and I
noticed some pretty drastic differences in the performance of the code
on ColdFusion vs Railo.

On ColdFusion, ~325ms

On Railo, ~15000ms

I also experience out of memory errors quite often with Railo when
making subsequent requests to the same template or switching between
assignment tests.

Anyone have any insight on what might be going on here? I'm not sure
if this is a bug or where the bug is might be. The inconstancy from
Railo is concerning though.

I've also noticed that CF handles out of memory errors much better
than Railo. Railo _really_ hangs on these. This is probably another
topic though.

regards,

.brett


Windows XP
Java Sun 1.6.0_11
Tomcat 6.0.18
CF 8.01
Railo 3.1.0.012


<cfset lhm = CreateObject("java", "java.util.LinkedHashMap").init() />

<cfset s1 = getTickCount() />

<cfloop from="1" to="100000" index="idx">

<!--- #1 slow ~15000ms, leads to out of memory errors --->
<cfset lhm[ "key" & idx ] = idx />


<!--- these are much faster assignments ~5 sec, but much slower than
CF still
#2
<cfset lhm[ idx ] = idx />

#3
<cfset key = "key" & idx />
<cfset lhm[ key ] = idx />

--->

</cfloop>

<cfoutput><p>#getTickCount() - s1# ms</p></cfoutput>

Dave

unread,
May 16, 2009, 10:19:26 AM5/16/09
to ra...@googlegroups.com
did you increase your tomcat memory or are you just running 81mb? (the
standard for java 1.6)

WebFlint

unread,
May 16, 2009, 10:52:12 AM5/16/09
to Railo
I'm running with the default Tomcat java settings so I haven't
increased the heap size to test what effect that would have on the
tests. I had to move onto something else so I was curious if anyone
else has thoughts on what I was experiencing.

I'm primarily concerned that

1) Railo is much slower than CF

2) There is a big difference in performance between the #1 & #3
statements.

3) Railo is inconsistent across requests. Running #1 it will return
in in 15 seconds. If I then modify the template and swap in #2 or #3
I'll get the out of memory errors. But if I restart tomcat I can run
#2 or #3 with out any issues.

I also see out of memory errors if I request the template running the
#1 statement multiple times, the first execution will succeed but
subsequent requests will result in out of memory errors so there seems
to be something lingering in memory across requests.

Dave

unread,
May 16, 2009, 11:09:29 AM5/16/09
to ra...@googlegroups.com
Well if you are going to say one is faster than the other wouldn't it
make sense to first make sure they are running similar resources?
If your cf8 is running on a 1gb of ram and your railo is running on
81mb that wouldnt be a very fair comparison.

I dunno bout your test there but I tend to agree with most people that
say railo is way faster.. at least with full on web pages.

WebFlint

unread,
May 16, 2009, 11:53:18 AM5/16/09
to Railo
Just to be clear - both ColdFusion and Railo are running in the same
Tomcat instance.

I'm one of those people that agree Railo seems to outperform CF. That
is why I was taken back a bit with this test.

Andrea Campolonghi

unread,
May 16, 2009, 12:31:59 PM5/16/09
to railo
replace:

<cfset lhm = CreateObject("java", "java.util.LinkedHashMap").init() />

with this:

<cfset lhm = structNew() />

performance of both engines increase a lot from 5.000/6.000 ms to 200/300 with Railo back faster of cf.

to use that java class is a really bad idea.

Andrea 

2009/5/16 WebFlint <webf...@gmail.com>

Peter Boughton

unread,
May 16, 2009, 12:58:06 PM5/16/09
to ra...@googlegroups.com
Regular structs don't guarantee order - which I guess is why he wants
the LinkedHashMap.

However, with Railo, you can do this:
<cfset lhm = StructNew( type:'linked' ) />

And then the order is guaranteed, but it is much faster than the Java one.

WebFlint

unread,
May 16, 2009, 1:00:35 PM5/16/09
to Railo
Hi Andrea - I'm not trying to work around the issue, I'm just curious
what is going on in Railo to cause the inconsistencies I am seeing.
It may be a larger issue not specific to the java.util.LinkedHashMap
class.

For instance in the original code why is:

<cfset key = "key" & idx />
<cfset lhm[ key ] = idx />

~3x faster than:

<cfset lhm[ "key" & idx ] = idx />

Also why do I get out of memory errors with the later example but not
the first.

regards,

.brett




On May 16, 12:31 pm, Andrea Campolonghi <acampolon...@gmail.com>
wrote:
> replace:
> <cfset lhm = CreateObject("java", "java.util.LinkedHashMap").init() />
>
> with this:
>
> <cfset lhm = structNew() />
>
> performance of both engines increase a lot from 5.000/6.000 ms to 200/300
> with Railo back faster of cf.
>
> to use that java class is a really bad idea.
>
> Andrea
>
> 2009/5/16 WebFlint <webfl...@gmail.com>

Anthony

unread,
May 17, 2009, 4:30:43 PM5/17/09
to Railo
I'm guessing that maybe the slowness may have something to do with how
structs are created internally by Railo or CF. It might be unrelated,
but see http://www.bennadel.com/blog/1556-Ability-To-Leverage-ColdFusion-Bug-Will-Mean-Errors-Later.htm
for some info about other issues with structs and arrays.

-Anthony

Michael Offner-Streit

unread,
May 17, 2009, 5:12:44 PM5/17/09
to ra...@googlegroups.com
first example has 2 assigment, second only one this make the second 2 times faster by garanty.
how many assigments do you make? because i think this is a memory problem, in this example you fill the memory and memory is never endless.

/micha




Anthony schrieb:

Michael Offner-Streit

unread,
May 17, 2009, 5:38:51 PM5/17/09
to ra...@googlegroups.com
Hi Brett

the problem is as follows:
in railo a struct is from type Struct
(http://www.railo.ch/javadoc/railo/runtime/type/Struct.html) in adobeCF
it is of type Map.
Railo can handle Maps, but for railo Maps and Structs are not the same,
railo can Maps not handle "native".
you can see this when you dump your map
<cfdump var="#lhm#">

railo is not slower in java handling in general.
Example:
<cfset sb = CreateObject("java", "java.lang.StringBuffer").init() />
<cfset s1 = getTickCount() />
<cfloop from="1" to="100000" index="idx">
<cfset sb.append(idx) />
</cfloop>
<cfoutput><p>#getTickCount() - s1# ms</p></cfoutput>

railo:217 ms
adobecf:1590 ms

we will defintly look into this in detail and we will working on a
improvment for map handling, will inform HERE in the next days about
details.


You write you run both engine on the same Tomcat, do you run both engine
at same time?
You should run only one engine at time. otherwise you can not be shure
that one engine not grap all memory away.


"I've also noticed that CF handles out of memory errors much better"
what you mean with this? what they do, what we do not?

greetings michael




/



WebFlint schrieb:

WebFlint

unread,
May 18, 2009, 1:56:08 PM5/18/09
to Railo
Hi Michael,

> You write you run both engine on the same Tomcat, do you run both engine
> at same time?

Yes both/all (openBD is running too) startup along side Railo. I was
restarting the tomcat between performance comparisons. Good point
though, I'll separate these entirely for future performance
comparisons.

> "I've also noticed that CF handles out of memory errors much better"
> what you mean with this? what they do, what we do not?

Railo is hanging tomcat for 4-6minutes when it throws the out of
memory error, where as CF will throw the error and release the request
almost immediately.

Here is what I see from Railo when it is doing this, I've given two
examples of what happened since the output was different, the once
similarity was the "no open locks" message from Railo when it tried to
time the request out.

Any idea what is going on here?


================
Failure #1
================

================
HTTP response
(no quotes)
================

">"


================
console output
================

Mon May 18 13:15:13 EDT 2009-437 Call:/lhm-test.cfm (1)
request (path: E:\web\sites\railo.local\webapps\ROOT\lhm-test.cfm:1)
is run into a timeout (50 seconds) and has been stopped. no open locks
at railo.runtime.exp.PageRuntimeException.<init>
(PageRuntimeException.java:37):37
at railo.runtime.CFMLFactoryImpl.checkTimeout(CFMLFactoryImpl.java:
192):192
at railo.runtime.engine.Controler.run(Controler.java:110):110
at railo.runtime.engine.Controler.run(Controler.java:92):92
Mon May 18 13:21:39 EDT 2009-968 Release: (1)

================
requesttimeout.log
================
"ERROR","web-0","05/18/2009","13:16","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:16","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:16","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:16","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:17","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:17","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:17","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:17","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:17","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:18","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:18","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:18","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:18","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:18","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:19","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:19","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:19","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:19","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:19","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:20","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:20","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:20","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:20","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:20","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:21","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:21","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:21","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"
"ERROR","web-0","05/18/2009","13:21","controler","stop thread (1)
because run into a timeout path: E:\web\sites\railo.local\webapps\ROOT
\lhm-test.cfm. no open locks"


================
Failure #2
================


================
HTTP Response:
================

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented
it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception

root cause

java.lang.OutOfMemoryError: Java heap space

note The full stack trace of the root cause is available in the Apache
Tomcat/6.0.18 logs.
Apache Tomcat/6.0.18

================
console output
================

Mon May 18 13:37:38 EDT 2009-281 Call:/lhm-test.cfm (6)
e:\web\sites\railo.local\webapps\root\web-inf\railo\logs
\requesttimeout.log
e:\web\sites\railo.local\webapps\root\web-inf\railo\logs
\requesttimeout.log
e:\web\sites\railo.local\webapps\root\web-inf\railo\logs
\requesttimeout.log
java.lang.OutOfMemoryError: Java heap space
Exception in thread "Timer-2" java.lang.OutOfMemoryError: Java heap
space
e:\web\sites\railo.local\webapps\root\web-inf\railo\logs
\requesttimeout.log
e:\web\sites\railo.local\webapps\root\web-inf\railo\logs
\requesttimeout.log
Exception in thread "Thread-28" java.lang.OutOfMemoryError: Java heap
space
e:\web\sites\railo.local\webapps\root\web-inf\railo\logs
\requesttimeout.log
e:\web\sites\railo.local\webapps\root\web-inf\railo\logs
\requesttimeout.log
Exception in thread "ContainerBackgroundProcessor[StandardEngine
[Catalina]]" java.lang.OutOfMemoryError: Java heap space
e:\web\sites\railo.local\webapps\root\web-inf\railo\logs
\requesttimeout.log
e:\web\sites\railo.local\webapps\root\web-inf\railo\logs
\requesttimeout.log
Mon May 18 13:41:15 EDT 2009-671 Release: (6)

================
requesttimeout.log
(only a single line)
================

"ERROR","web-0","05/18/2009","13:41","controler","stop thread (6)
because run into a timeout . no open locks"


================
catalina.log
================
May 18, 2009 1:38:12 PM org.apache.catalina.core.StandardWrapperValve
invoke
SEVERE: Servlet.service() for servlet FileServlet threw exception
java.lang.OutOfMemoryError: Java heap space
at railo.commons.io.IOUtil.copy(IOUtil.java:214)
at railo.commons.io.IOUtil.copy(IOUtil.java:50)
at railo.commons.io.IOUtil.copy(IOUtil.java:159)
at railo.runtime.engine.CFMLEngineImpl.serviceFile
(CFMLEngineImpl.java:260)
at railo.loader.servlet.FileServlet.service(FileServlet.java:32)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke
(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke
(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke
(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke
(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke
(AccessLogValve.java:568)
at org.apache.catalina.core.StandardEngineValve.invoke
(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service
(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process
(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:
447)
at java.lang.Thread.run(Thread.java:619)
May 18, 2009 1:41:15 PM org.apache.catalina.core.StandardWrapperValve
invoke
SEVERE: Servlet.service() for servlet CFMLServlet threw exception
java.lang.OutOfMemoryError: Java heap space

gary gilbert

unread,
May 22, 2009, 5:29:19 PM5/22/09
to ra...@googlegroups.com
I receive the "no open locks" error about once per week, not sure whats going on there either.  Generally happens during a spider crawl of my blog.


Gary Gilbert
http://www.garyrgilbert.com/blog

Gert Franz

unread,
May 22, 2009, 7:07:38 PM5/22/09
to ra...@googlegroups.com

No open locks just states that when a timeout occurs that there are no locks that caused the problem to happen. It’s just a hint but only appearing when you receive a timeout error.

 

Gert

Bruce Kirkpatrick

unread,
Jun 11, 2013, 11:16:40 PM6/11/13
to ra...@googlegroups.com, webf...@gmail.com
I ran your original code on Coldfusion 10 tomcat (up to date as of this post) and Railo 4 tomcat, and Railo 4.0.4.001 is twice as fast as Coldfusion 10 with that code after they are "warmed up".

I was going to say that it is better to "var" your variables for best performance as well - it makes a huge difference even on coldfusion it seems.  You have a lot of wasted CPU by not "var"ing the variables since CFML has to search several scopes to find the value, and you've multiple that by millions.

You also need to make sure you have railo debugging disabled if you are running performance tests like this.  The implicit scope option can be excessively slower.

the times are for a single execution on my machine:

coldfusion 10 (in my windows host)
187 ms - original code
29 ms - original code explicit scope
56 ms - structnew() instead of java with explicit scope

railo 4.0.4.001 (in my linux virtual machine)
83 ms - original code
55 ms - original code explicit scope
60 ms - structnew() instead of java with explicit scope

The virtual machine is at a disadvantage but still very fast. I don't run ACF in linux at the moment.

The out of memory issues are your problem here.  Give Railo more memory.  It might need more then ACF to be stable for your app.  Mine did.   Also consider that running many contexts is more memory intensive then a single context, so railo will use more memory then ACF if you have a lot of virtualhosts that are configured as contexts in tomcat. 

This is my tomcat jvm config
/opt/railo/tomcat/bin/setenv.sh
JAVA_OPTS="-Xms1012m -Xmx2024m -XX:PermSize=32M -XX:MaxPermSize=300m -XX:NewRatio=4 -XX:SurvivorRatio=10 -XX:NewSize=386m -XX:MaxNewSize=768m -XX:ParallelGCThreads=8  -XX:+UseParNewGC -XX:ReservedCodeCacheSize=100m -XX:GCTimeRatio=19 -XX:+OptimizeStringConcat";

You can't rely on the default setenv.sh options if you have a more significant app.  I give it 1gb more then it needs to be hopefully improve stability under unusual load conditions.  If you do load tests, you may need to play with tomcat's threadlimit as well.  I found going too high above 50 simultaneous railo threads to be dangerous for stability in my app.  I can get up to 5000 requests per second with railo doing nothing (empty application.cfc) on this machine with a threadlimit of 50.  I have an older intel core i7-860 cpu.  The newest cpus are about 120% faster then my cpu.

Bruce Kirkpatrick

unread,
Jun 11, 2013, 11:21:43 PM6/11/13
to ra...@googlegroups.com, webf...@gmail.com
I also agree that if you run out of memory in Railo, it can sometimes hang instead of throwing an exception.  I'm not sure if Coldfusion was better at memory management or if my app wasn't using memory as much back then.  I did have to raise coldfusion heap memory above the default, and railo needed even more then that back in railo 3.2 to run my app at first.  I have since greatly reduced the need for memory in my app, and railo 4 is more efficient with memory, so I haven't seen any memory related crashes anymore unless i really try to crash it.
Reply all
Reply to author
Forward
0 new messages