-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Improve router performance #1137
Comments
Interesting, i have couple questions, your main page route is on top of routing table? Do you have any regex routes? |
The main page route is in the middle of the routes. There are a couple of regex routes. |
@iceboy-sjtu personally I have no plan to work on the issue in the nearest future. |
Not a dev here, but I was looking for a particular issue and stumbled across this one. @iceboy-sjtu I built a Trie based router just the other day, it may be useful as inspiration to implement something similar for aiohttp. |
@nitely Well, we use |
@iceboy-sjtu It does not, it would be trivial to implement that on top of it, though. However, reading your first post I thought you were thinking of implementing a trie router from scratch, that's why I mentioned that router at all. |
url generation is really trivial. |
Keeping the current API would be tricky indeed, but doable. Last node of the Trie has the Router handler (variable param names and the handler/callback/controller), that can be replaced by a list of Routers (ie: clashing URLs) and each Router would have the regexes, then you can check URL variable parts for each regex pattern, if it does not match then try the next one, if all fail then try next Trie branch. So the only thing to implement would be the regex matching logic, everything else is already taken care of. This would handle a case like: router.add_get('/{:\d+}', handler)
router.add_get('/{:.+}', handler)
# and
router.add_get('/{:.+}', handler)
router.add_get('/{:\d+}', handler)
# Although the second handler will never match But it breaks behaviour in a case like: router.add_get('/{:.+}', handler)
router.add_get('/foo', handler) In the current implementation there is no way to reach the second handler because the first one always matches (I think, did't try it though). In the Trie router, static parts take precedence, so |
No, for sake of backward compatibility we should keep ordering.
|
'router' should be replaceable. I'd just create aio libs project and over time we could move it into aiohttp |
@fafhrd91 please don't rush. I believe trie is not the only possible implementation, maybe we can invite something without breaking backward compatibility. Say, joining all regexps together into super-expression may improve performance very well, but we need to test it. But I want to publish aiohttp 1.0 first. |
@asvetlov Yeah, if you want to keep that behaviour, Trie is not the way to go IMHO.
Yes, actually that would be a good approach [0]. [0] http://nikic.github.io/2014/02/18/Fast-request-routing-using-regular-expressions.html |
I am more about how to prove idea, that's it. I personally never had situation when aiohttp is the bottleneck |
It seems that python's built-in |
|
Created aiohttp-r3 to use r3 :) |
pretty cool. I would deprecate aiohttp's path dispatcher, in favor of something like this. |
Although r3 seems to be already used in many places, I found bugs in both 1.3.4 and 2.0 branch (c9s/r3#99, c9s/r3#100), and it lacks feature for static files and url reversing. r3 is a random pick. Are there any other libraries that worth a try? |
I just want to say, I do not want to maintain code if we can find good alternatives |
We found out that aiohttp's router performance is very slow.
In our webapp, there are currently 127 routes. If we delete all routes except main page, the performance is 2544qps. After restoring all routes, the performance becomes 1727qps. Test is done on a MacBook with single process.
We could implement tree-based routing which should have good performance in most real-world case, or implement an NFA-based router for optimal performance.
The text was updated successfully, but these errors were encountered: