don't call client.authenticate() only when it is authenticated

Actually, that line is redundant if call keystoneclient with auth_url
and without endpoint parameter, because in this case keystoneclient will
call authenticate itself[1][2]. Actually this case is managed by
'endpoint_type' now. So this patch changes the behavior to call
authenticate() only when the client is not authenticated. One of not
authenticated case is passing endpoint parameter into keystoneclient.

There are examples I tested:
                            before                after
keystone create user*       ~0.35s                ~0.22s
keystone create token       ~0.21s                ~0.13s

The data based on real enviornment, but could explain something still.
That redundant authenticate line bring about 0.07s overload which is costly
for those APIs which could respond in 1 second. In a case calling API with
500 times and 10 concurrency, I could find the whole scenario time would
reduced from 110s to 65s by removing that line.

* this case is to create token first and create user then which two API
are called
[1]
https://github.com/openstack/python-keystoneclient/blob/master/keystoneclient/v3/client.py#L190-L191
[2]
https://github.com/openstack/python-keystoneclient/blob/master/keystoneclient/v2_0/client.py#L146-L147

Change-Id: Ib9d766a345b68b3920121d8b8c69c4f3c5ca1dc2
This commit is contained in:
Kun Huang 2014-10-10 10:10:04 +08:00
parent 734739ed72
commit 935028e78b

View File

@ -109,7 +109,8 @@ class Clients(object):
else:
kw["endpoint"] = kw["auth_url"]
client = create_keystone_client(kw)
client.authenticate()
if client.auth_ref is None:
client.authenticate()
return client
def verified_keystone(self):