-
Notifications
You must be signed in to change notification settings - Fork 24k
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
WIP: bypass ansible-connection for existing connections #76430
base: devel
Are you sure you want to change the base?
Conversation
* skip creation of (expensive!) new process once a persistent connection is going * move persistent connection detect logic into main worker * defer persistent connection creation until the connection is used (cleans up special cases in TE, speeds up dispatch of local-only actions under persistent connection hosts)
related #77509 |
# is this even necessary anymore now that we're passing the connection options over directly? | ||
# pcdata = cPickle.dumps(self._play_context.serialize(), protocol=0) | ||
# conn.update_play_context(to_text(pcdata)) | ||
|
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 problem is that you start the connection before we know the connection details for sure, so getting the data earlier will make it even worse. In some cases (when all is known before task templating) you should have no issues as play_context carries the correct info, but if you need info to change at the task, or worse, loop/delegation levels you'll run into trouble much sooner.
Most of the time this problem can be ignored as plays tend to reuse the same information w/o changing it, specially networking ones.
As you note, since we are passing the connection information and using set_options/get_option on them, we should be able to ignore most of the play_context data, but this requires all connection plugins to correctly source the data (all those in core do, but many of those in collections do not). Why I was planning to add deprecation notices to play_context soon.
setattr(connection, '_socket_path', socket_path) | ||
# HACK: need a better way to make these necessary bits accessible for the deferred connection startup | ||
connection._smuggled_options = options | ||
connection._startconn = start_connection |
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.
instead of 'starting connection' here we might want to 'reserve socket path', to create it if it doesn't exist and to 'touch it' if it does (making a-connection timeout reset so we avoid a race condition)
If this was ready soon, would it wait for a .0 release/major release? |
@mkrizek what's happening here? |
SUMMARY
fixes #75813
Creating new ansible-connection processes to use existing persisted connections is extremely wasteful and slow, since the newly-created ansible-connection effectively exits immediately in that case. This PR significantly reduces connection overhead for all networking connection plugins, but especially speeds up local actions under host contexts where a persistent connection is in use (since TE was blindly running ansible-connection in cases where no connection was used).
KNOWN ISSUES:
ansible_user
is wrong on playcontextremote_user
on subsequent connection round-trips- seems to default to current UNIX user instead. Not sure how much longer we'll need to serialize playcontext anyway, since we're already sending over all the connection vars.This could be done in the base persistent connection's
_connect
method , except that it's defined as abstractmethod, so none of the subclasses are currently callingsuper()._connect()
.ISSUE TYPE
COMPONENT NAME
ansible-connection (et al)
ADDITIONAL INFORMATION
cc @cidrblock @Qalthos