Hello again,

After some more test, I found out that I forgot that a sequence was called
in the connector (the actual call of the Java class). In my connector, the
call of the Java class was followed by a Payload Factory which used the
generated JSON located in the content of the body to "cast" it as JSON.
Something like that:

<payloadFactory media-type="json">
    <format>$1</format>
    <args>
        <arg evaluator="xml" expression="$body/"/>
    </args>
</payloadFactory>

So that was why when I wanted to retrieve my "body content" as simple text
to put it into a property, the ESB just parse it to generate XML
(auto-conversion JSON => XML) and that is why I had to use json-eval to
prevent that.

On the performance-side, it seems that I gained some precious seconds so...
I am happy :)

Regards,

Thomas

2017-10-30 14:28 GMT+01:00 Thomas LEGRAND <[email protected]>:

> Hello everybody!
>
> I have a custom connector in which I inserted some instruction to get the
> time it takes to finish the execution. It is very simple and is like that :
>
> @Override
> public void connect(MessageContext messageContext) throws ConnectException
> {
>     long start = System.currentTimeMillis();
>     // MY CODE HERE
>     messageContext.getEnvelope().getBody().setText(<MY BADASS JSON>);
>     LOGGER.info("Generation of the message took " +
> (System.currentTimeMillis() - start) + " ms");
> }
>
> My connector took around 110 ms to finish the connect method. Is it too
> long or too short? For the moment, we don't care.
>
> This connector is called from a custom sequence in which I do the same :
> some properties to retrieve the start date and end date and process the
> difference to see how much time the execution takes. Something like that:
>
> <sequence name="mySequence" trace="disable" xmlns="http://ws.apache.org/
> ns/synapse">
>     <property description="start" expression="get-property('SYSTEM_TIME')"
> name="start" scope="default" type="LONG"/>
>     <custom.callMyConnector>
>         <!-- some properties here -->
>     </custom.callMyConnector>
>     <property description="myBadassJson" expression="json-eval($.)"
> name="myBadassJson" scope="default" type="STRING"/>
>     <call-template description="logExecutionTime"
> target="logExecutionTime">
>         <with-param name="startExecutionTime" value="{$ctx:start}"/>
>         <with-param name="executionLabel" value="mySequence"/>
>     </call-template>
> </sequence>
>
> It calls a template which does just that:
>
> <template name="logExecutionTime" xmlns="http://ws.apache.org/ns/synapse";>
>     <parameter name="startExecutionTime"/>
>     <parameter name="executionLabel"/>
>     <sequence>
>         <property description="startExecutionTime" 
> expression="$func:startExecutionTime"
> name="startExecutionTime" scope="default" type="STRING"/>
>         <property description="executionLabel" 
> expression="$func:executionLabel"
> name="executionLabel" scope="default" type="STRING"/>
>         <property description="endExecutionTime" 
> expression="get-property('SYSTEM_TIME')"
> name="endExecutionTime" scope="default" type="LONG"/>
>         <script language="js"><![CDATA[var startExecutionTime =
> mc.getProperty("startExecutionTime");
>             var endExecutionTime = mc.getProperty("endExecutionTime");
>             var executionLabel = mc.getProperty("executionLabel");
>
>             var logger = mc.getServiceLog();
>             logger.info(executionLabel + " executed in " +
> (endExecutionTime - startExecutionTime) + " ms");]]></script>
>     </sequence>
> </template>
>
> And, here is the wild thing appearing: I have in my log:
>
> TID: [-1234] [] [2017-10-30 14:03:55,464]  INFO
> {org.apache.synapse.mediators.bsf.ScriptMessageContext} -  mySequence
> executed in 3975 ms {org.apache.synapse.mediators.
> bsf.ScriptMessageContext}
>
> 3 secs! It is huge! It is like the json-eval invokation in the property
> mediator, after the call of my connector, is taking too much time (around
> 3800 ms?). If I don't use json-eval, the ESB generates me XML and I suspect
> that it take much more time to convert it from JSON to XML.
> In addition, I put the payload in a property because I call many
> connectors sequentially to do an aggregation of their payload later (via a
> script mediator). I do the same for each connector I call.
>
> Do you have an idea why is it taking so long to just put text from the
> payload into a property (actually, if it is possible to just don't evaluate
> it, it would be cool)?
> Have you some directios to give me to optimize my process?
>
> Thank you!
>
> Regards,
>
> Thomas
>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to