You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Ben V <ve...@gmail.com> on 2012/11/27 12:07:27 UTC
Speed up marshalling objects to XML by explicitly loading classes
I have lots of xsd and create java classes from them (~1000 classes) using
xjc and deployed them to Servicemix4 as an OSGI bundle.
Then I have application where I process the request and set exchange body to
some object from generated classes.
The problem is when it processes the first request - it takes around ~10
seconds (JAXB to marshal object and set Exchange Body to XML??).
Other requests runs without any time loss...
Is there a way to speed up first request and explicitly load all generated
classes when I deploy my bundle?
-------------------
camelContext:
<camelContext id="cds_context"
xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="cxfrs:bean:rsServer?bus=#cxf-bus" />
<to uri="requestProcessor" />
<to uri="log:REQUEST?level=DEBUG&multiline=true" />
<to uri="nmr:http://example.com/some_routing" />
<to uri="log:RESPONSE?level=DEBUG&multiline=true" />
</route>
</camelContext>
-------------------
requestProcessor:
import my.package.Subscription;
...
public void process(Exchange exchange) throws Exception {
....
Subscription subr = new Subscription();
subr.setNumber("123");
exchange.getOut().setBody(subr, Subscription.class);
log.debug("process DONE");
.....
}
-------------------
First request:
2012-11-27 12:33:09,797 | DEBUG | qtp24871952-549 | RequestProcessor
| 176 - my_bundle - 1.0.0.SNAPSHOT | process DONE
2012-11-27 12:33:18,045 | DEBUG | qtp24871952-549 | RQUEST
| 91 - org.apache.camel.camel-core - 2.8.5 | Exchange[
, ExchangePattern:InOut
, BodyType:my.package.Subscription
, Body:<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns8:subscription xmlns:ns8="http://omnitel.lt/cdm">
<ns8:number>123</ns8:number>
</ns8:subscription>
]
-------------------
Other requests:
2012-11-27 12:36:48,053 | DEBUG | qtp24871952-549 | RequestProcessor
| 176 - my_bundle - 1.0.0.SNAPSHOT | process DONE
2012-11-27 12:36:48,055 | DEBUG | qtp24871952-549 | RQUEST
| 91 - org.apache.camel.camel-core - 2.8.5 | Exchange[
, ExchangePattern:InOut
, BodyType:my.package.Subscription
, Body:<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns8:subscription xmlns:ns8="http://omnitel.lt/cdm">
<ns8:number>123</ns8:number>
</ns8:subscription>
]
--
View this message in context: http://camel.465427.n5.nabble.com/Speed-up-marshalling-objects-to-XML-by-explicitly-loading-classes-tp5723299.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Speed up marshalling objects to XML by explicitly loading classes
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
No there is not.
Maybe if you specify a JAXB data format, and with the contextPath,
then JAXB may load these on startup. Not sure though.
On Tue, Nov 27, 2012 at 12:07 PM, Ben V <ve...@gmail.com> wrote:
> I have lots of xsd and create java classes from them (~1000 classes) using
> xjc and deployed them to Servicemix4 as an OSGI bundle.
> Then I have application where I process the request and set exchange body to
> some object from generated classes.
> The problem is when it processes the first request - it takes around ~10
> seconds (JAXB to marshal object and set Exchange Body to XML??).
> Other requests runs without any time loss...
>
> Is there a way to speed up first request and explicitly load all generated
> classes when I deploy my bundle?
>
> -------------------
> camelContext:
> <camelContext id="cds_context"
> xmlns="http://camel.apache.org/schema/blueprint">
> <route>
> <from uri="cxfrs:bean:rsServer?bus=#cxf-bus" />
> <to uri="requestProcessor" />
> <to uri="log:REQUEST?level=DEBUG&multiline=true" />
> <to uri="nmr:http://example.com/some_routing" />
> <to uri="log:RESPONSE?level=DEBUG&multiline=true" />
> </route>
> </camelContext>
> -------------------
> requestProcessor:
> import my.package.Subscription;
> ...
> public void process(Exchange exchange) throws Exception {
> ....
> Subscription subr = new Subscription();
> subr.setNumber("123");
> exchange.getOut().setBody(subr, Subscription.class);
> log.debug("process DONE");
> .....
> }
> -------------------
> First request:
> 2012-11-27 12:33:09,797 | DEBUG | qtp24871952-549 | RequestProcessor
> | 176 - my_bundle - 1.0.0.SNAPSHOT | process DONE
> 2012-11-27 12:33:18,045 | DEBUG | qtp24871952-549 | RQUEST
> | 91 - org.apache.camel.camel-core - 2.8.5 | Exchange[
> , ExchangePattern:InOut
> , BodyType:my.package.Subscription
> , Body:<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <ns8:subscription xmlns:ns8="http://omnitel.lt/cdm">
> <ns8:number>123</ns8:number>
> </ns8:subscription>
> ]
> -------------------
> Other requests:
> 2012-11-27 12:36:48,053 | DEBUG | qtp24871952-549 | RequestProcessor
> | 176 - my_bundle - 1.0.0.SNAPSHOT | process DONE
> 2012-11-27 12:36:48,055 | DEBUG | qtp24871952-549 | RQUEST
> | 91 - org.apache.camel.camel-core - 2.8.5 | Exchange[
> , ExchangePattern:InOut
> , BodyType:my.package.Subscription
> , Body:<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <ns8:subscription xmlns:ns8="http://omnitel.lt/cdm">
> <ns8:number>123</ns8:number>
> </ns8:subscription>
> ]
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Speed-up-marshalling-objects-to-XML-by-explicitly-loading-classes-tp5723299.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Re: Speed up marshalling objects to XML by explicitly loading classes
Posted by Henryk Konsek <he...@gmail.com>.
> Is there a way to speed up first request and explicitly load all generated
> classes when I deploy my bundle?
If loading these 1000 classes by classloader is the issue, then you
can use Reflections [1] and eager loaded Spring bean to load all these
classed when bundle context starts up.
<bean lazy-init="true" class="com.example.MyReflectionsBasedClassScanner">
<property name="basePackage" value="com.example.xsd"/>
</bean>
Regards.
[1] http://code.google.com/p/reflections
--
Henryk Konsek
http://henryk-konsek.blogspot.com