-
-
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
Throttle simultaneous DNS requests #1924 #2111
Conversation
Added a new option at TCPConnector level called `throttle_dns` that allows to the connector throttle simulatnewous DNS requests for a specific domain. This functionality its only compatible when the DNS cache is enabled and it is dissabled by default. Therefore, many requests can end up making the same DNS resolution.
Will help the user to throttle DNS requests to the same domain. By design it will happen always when many URLs behind the same domain are scheduled at the same time, perhaps via *gather* The Event class is no longer a derivated class of the asyncio.locks.Event, and makes a full copy of this one to avoid future issues.
Trying to get a green pipeline, just a copy of the #1924. Now issues with the output of the coverage having a really weird error
Again
Any recommendation to fix that issue with the pipeline? @asvetlov @kxepal @fafhrd91 |
do not worry about "Python: nightly". |
aiohttp/locks.py
Outdated
from .helpers import create_future | ||
|
||
|
||
class Event: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it possible to inherint from asyncio.Event and override set method instead? I'm not sure we want to maintain whole own Even lock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer used that pattern
Thanks for the tip @fafhrd91 fixed. Aside of that, after some research I decided to get rid of the full Event class, the same behavior can be reached with the new and simple wrapper called Disclaimer, there is still a red-flag raised by @asvetlov regarding the Futures related to these tasks pending to be awakened, the whole thread can be followed here [2]. BTW my opinion about that is still the same, the proposed implementation is not nocive at all or at least is guided by the same principles than the current one. [1] https://mail.python.org/pipermail/python-ideas/2017-July/046486.html |
Codecov Report
@@ Coverage Diff @@
## master #2111 +/- ##
==========================================
+ Coverage 97.09% 97.09% +<.01%
==========================================
Files 38 39 +1
Lines 7740 7780 +40
Branches 1351 1357 +6
==========================================
+ Hits 7515 7554 +39
Misses 101 101
- Partials 124 125 +1
Continue to review full report at Codecov.
|
you should to cleanup all event in connector's close method. just set otherwise I think PR is fine. |
self._ssl_context = ssl_context | ||
self._family = family | ||
self._local_addr = local_addr | ||
|
||
def close(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is for 2.3 release. otherwise lgtm. |
@asvetlov looks you have the last word for this PR. BTW adapted to last CHANGES protocol and one small fix about the explicit loop. |
Please do rebase feature branch against master instead of merging master into feature branch. Twisted git log history is quite hard to follow. |
@kxepal it doesn't needed, we usually do quash PRs anyway |
@asvetlov ah, cool then! |
aiohttp/locks.py
Outdated
from .helpers import ensure_future | ||
|
||
|
||
class ErrorfulOneShotEvent: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name is too long.
Also it starts with Error
, usually this schema is used for nameing exception classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to EventResultOrError
, still long but at least more meaningful. Let me know if it suits better for you.
Ok, thanks. The name is not public, we could change it later anyway. |
What do these changes do?
Allows to the connector throttle simultaneous DNS requests for a specific
domain when the DNS cache is enabled, having this enabled by default.
This feature get rid of the dogpile side effect when there is a miss in the cache, having
just one request doing the DNS resolution - at hostname granularity, requests that continue arriving while the ongoing DNS resolution is not finished will wait till it finishes.
When the DNS cache is not used. All requests will end up making a DNS query.
Are there changes in behavior for the user?
No
Related issue number
No
Checklist
CONTRIBUTORS.txt
CHANGES.rst
#issue_number
format at the end of changelog message. Use Pull Request number if there are no issues for PR or PR covers the issue only partially.