Project

Profile

Help

Interrupt transformation

Added by Anonymous almost 14 years ago

Legacy ID: #8938079 Legacy Poster: Zdenek (zkovanda)

Hi togther... Our server uses Saxon for transformation of XML to HTML. From time to time the transformation process takes too long time. The reason can be a bug in XSL stylesheet (e.g. some loop...) or simple overloaded server. In this case a client looses interest about the result of transormation - he clicks to another link ot simply closed the browser etc. In this case it would be fine to interrupt the currently running transformation. The request processing thread creates a new transformation thread. The transformation thread creates a new transformer and submits the transformation. The request process thread is waiting for the result in a loop calling sleep() function. So I am able to measure the time of running transformation. I tried to find some function of Saxon transformer, which would stop somehow but regularly the transformation. But I had no success..... Then I tried to call simply an interrupt() function of the transformation thread. But nothing happened. It seems that there is no way. In case of long transformation it is not so big problem. The transformation will end sometime but in case of some bad XSL file (loop etc...) it would be fine to end it up somehow to save server resources. Any idea??? Zdenek


Replies (3)

Please register to reply

RE: Interrupt transformation - Added by Anonymous almost 14 years ago

Legacy ID: #8940774 Legacy Poster: Michael Kay (mhkay)

Interrupting a thread has no effect unless the thread does a sleep() or something similar (which Saxon doesn't). You could insert user code into the serialization pipeline to check for an interrupt at any point where Saxon is producing output. But I suspect that if a transformation is taking a really long time then it might be doing some kind of complex operation on the input that doesn't actually generate any output. Adding monitoring code using the TraceListener interface probably has far too severe an effect on performance. I can think of one or two other places you could inject user code whose sole purpose is to check for interrupts: for example with a user-written TreeModel that subclasses TinyTree you could intercept every time a temporary tree gets created, or you could have a default collation that's called every time a string comparison is done. But none of these insertion points is guaranteed to interrupt all tight loops in the code. I can't think of anything better at the moment.

RE: Interrupt transformation - Added by Anonymous almost 14 years ago

Legacy ID: #8940963 Legacy Poster: David Lee (daldei)

You could implement a java: function which checks occasionally for an interrupt and throw an exception. It would have to be inserted specifically in "checkpoint" locations which might be hard in XSLT if its mostly in PUSH mode. I could see adding a feature in Saxon XPath/XQuery/XSLT to do occasional callbacks to a user supplied "shouldContinue" callback. Implementing this should be easy, but implementing it such that it has low performance impact as well as is called often enough to be useful may not be so easy. -David

RE: Interrupt transformation - Added by Anonymous almost 14 years ago

Legacy ID: #8941011 Legacy Poster: Michael Kay (mhkay)

I was assuming a constraint of "no change to user queries or stylesheets", since presumably the intent is to kill queries and stylesheets that were badly written in the first place. Yes, it's difficult to see where in Saxon one could insert a "hasBeenInterrupted() call (or whatever the method is called) that would give a high probability of being executed and a low probability of affecting performance.

    (1-3/3)

    Please register to reply