Author |
Message
|
keenlearner |
Posted: Thu Aug 13, 2009 8:48 pm Post subject: Loopinf in ESQL : FOR v/s WHILE using LASTMOVE |
|
|
Acolyte
Joined: 24 Aug 2006 Posts: 62
|
Hi All
We are in a position where we want to understand which loop method is more advantageous FOR or WHILE
The syntax for FOR is
FOR refVariable AS referenc.child[] DO
END FOR
WHILE LASTMOVE(refVariable)
MOVE refVariable TO NEXTSIBLING
END WHILE;
The reason for this being we are getting a very large message and looping causes broker to abend. Though there are N number of ways to resolve this issue but we want to make sure that we are using the correct looping method.
any help would be much appreciatied. |
|
Back to top |
|
 |
Vitor |
Posted: Fri Aug 14, 2009 4:53 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
The search function will turn up a number of potentially useful discussions on this. There are also some redbooks on the subject that might help.
In your situation I'd consider using NEXTSIBLING and pruning the message tree as you go.
I'm also interested in why exactly the broker is abending. It's important to handle large messages efficiently, but shouldn't blow if you don't. Just sit & burn CPU. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
WMBDEV1 |
Posted: Mon Aug 17, 2009 5:58 am Post subject: |
|
|
Sentinel
Joined: 05 Mar 2009 Posts: 888 Location: UK
|
Vitor wrote: |
I'm also interested in why exactly the broker is abending. It's important to handle large messages efficiently, but shouldn't blow if you don't. Just sit & burn CPU. |
Depends what you mean by "large". previously when doing an immediate parse for 30MB CSV messages i've seen the broker abend with out of memory errors because it exceeded the 1gb limit. To resolve this the large memory handling techniques were then to be used and all was well. |
|
Back to top |
|
 |
keenlearner |
Posted: Thu Aug 20, 2009 5:39 am Post subject: |
|
|
Acolyte
Joined: 24 Aug 2006 Posts: 62
|
hey....problem here is not handling large message.... as I have written in post as well that there are N number of ways to handle large messages... and we know some of them and successfully implemented the same.
I wanted to have a feedback on the loop statement .... which is better FOR loop of the while loop using the lastmove fucntion.
@Vitor.... Definitely the search option would have been resulted various results but nothing would have given what I am looking for. Hence raised the issue.
secondly referring to red books is always an answer to all questions posted in the forums. |
|
Back to top |
|
 |
fschofer |
Posted: Thu Aug 20, 2009 6:30 am Post subject: |
|
|
 Knight
Joined: 02 Jul 2001 Posts: 524 Location: Mainz, Germany
|
Hi,
i tend to use FOR loops where possible as moving the references is done internally and it is less code with less potential for errors.
As we all know a missing MOVE NEXTSIBLING will lead to a endless loop.
But there are some cases where WHILE LASTMOVE has to be used for example when deleting some of the elements during the loop.
Greetings
Frank |
|
Back to top |
|
 |
WMBDEV1 |
Posted: Thu Aug 20, 2009 6:42 am Post subject: |
|
|
Sentinel
Joined: 05 Mar 2009 Posts: 888 Location: UK
|
I'm not sure what your point is with this statement (but i'm probably just missing it so please feel free to explain it to me!)....
fschofer wrote: |
As we all know a missing MOVE NEXTSIBLING will lead to a endless loop.
|
If we miss the code to increment the loop variable in a for loop we will also loop forever. Infinite loops are not caused by the fact we are using pointers!
Quote: |
But there are some cases where WHILE LASTMOVE has to be used for example when deleting some of the elements during the loop.
|
Using NEXTSIBLING instead of indices to access the message tree will perform significantly better as the message tree grows larger.
Last edited by WMBDEV1 on Thu Aug 20, 2009 6:45 am; edited 1 time in total |
|
Back to top |
|
 |
WMBDEV1 |
Posted: Thu Aug 20, 2009 6:43 am Post subject: |
|
|
Sentinel
Joined: 05 Mar 2009 Posts: 888 Location: UK
|
keenlearner wrote: |
hey....problem here is not handling large message.... |
Are you sure?
Please share how you came to this conclusion....
Quote: |
The reason for this being we are getting a very large message and looping causes broker to abend.
|
|
|
Back to top |
|
 |
fschofer |
Posted: Thu Aug 20, 2009 7:47 am Post subject: |
|
|
 Knight
Joined: 02 Jul 2001 Posts: 524 Location: Mainz, Germany
|
WMBDEV1 wrote: |
If we miss the code to increment the loop variable in a for loop we will also loop forever. Infinite loops are not caused by the fact we are using pointers!
|
When using the syntax below (FOR loop using references) then the moving of the reference is done automatically by the broker.
Code: |
FOR refVariable AS referenc.child[] DO
END FOR
|
Only when using a FOR loop with indices then the indice value has to be increased with a separate line of code.
Greetings
Frank |
|
Back to top |
|
 |
WMBDEV1 |
Posted: Thu Aug 20, 2009 8:01 am Post subject: |
|
|
Sentinel
Joined: 05 Mar 2009 Posts: 888 Location: UK
|
Thanks Frank, i've not used that syntax before... but now i've learnt something new today
My other comments are still true though although maybe a little less relevant as the question is slightly different to the one I thought I was answering! My bad |
|
Back to top |
|
 |
keenlearner |
Posted: Fri Aug 21, 2009 1:59 am Post subject: |
|
|
Acolyte
Joined: 24 Aug 2006 Posts: 62
|
Hi WMBDEV1
We are receiving flat files which are over 50 MB in size but that is not over problem ... we are splitting the files before it is begin read into the broker. So there is no problem in handling large messages.
Let me rephrase my query:
Which Loop statement is better in terms of performance
1) For loop
2) While loop
in esql. |
|
Back to top |
|
 |
fschofer |
Posted: Fri Aug 21, 2009 2:09 am Post subject: |
|
|
 Knight
Joined: 02 Jul 2001 Posts: 524 Location: Mainz, Germany
|
Hi,
Quote: |
Which Loop statement is better in terms of performance
1) For loop
2) While loop |
Should be easy to determine this by executing some performance tests on your own.
But depending on the work which is done inside the loop it should not matter very much to use FOR or WHILE loops.
If there are several lines of code within the loop i assume the difference to be marginally.
Greetings
Frank |
|
Back to top |
|
 |
keenlearner |
Posted: Fri Aug 21, 2009 3:10 am Post subject: |
|
|
Acolyte
Joined: 24 Aug 2006 Posts: 62
|
Yes we definitely tried it and did not get a significant difference rather no diffrence at all for a xml file which has 5000 records. Just wondering some body have any specific details on it |
|
Back to top |
|
 |
|