New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tornado.gen and ExceptionStackContext make things painfully slow #507
Comments
Can you post some specific code that's slower than you expect? It's been on my todo list for a while to investigate the performance of tornado.gen in general, but it would be helpful to understand what exactly you're seeing. tornado.gen is going to have some amount of overhead in comparison to hand-coded callbacks, but hopefully it's fairly small. It's possible, however, that we've got a StackContext leak or something that's causing much worse performance. This should be fairly easy to identify once we've got a reproducible test case. |
The idea is that I'm processing a fairly big XML file, with about 15000 'interesting' elements in it. For each of those, I sometimes check something in my MongoDB database. I use lxml. In the for loop that iterates over the elements, I yield Tasks. In the Task'ed function, I also yield Tasks. The code in question is part of a big system from which it would be hard to extract the incriminated part. I will try to find time to write something that approximates it, but I have to find time. |
I think I can guess what's happening. Even though your code looks procedurally like a loop, each yielded I haven't confirmed this, however. |
Yep, that'll do it. We've seen similar issues before and the fix was to call |
So, where should I grap the stack context ? |
Yes, to fix this problem the way we did with HTTPConnection, you'd need to wrap the callback before the "with ExceptionStackContext" block in gen.engine. (This means pulling the callback out of **kwargs). |
I'll try that and keep you posted. |
I think I've got a fix for this in 57a3f83, although it's a little messy. Please give it a try. |
The fix seems to be doing the job. |
changing ExceptionStackContext's code to the following makes everything smooth again :
I do not understand all the magic's that's going on here, but my problem is that the contexts, by being copied all the time can get to slow everything down to a crawl.
What am I doing wrong ? Why is there so much ExceptionStackContext being run ?
The text was updated successfully, but these errors were encountered: