You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I considered if a workaround is still needed, also after kubernetes_asyncio is used to replace kubernetes in #563, and concluded yes it probably is - but it isn't if a property is never read - but that's hard to be confident about.
Background
I'm reviewing #563 that replaces kubernetes with kubernetes_asyncio. Doing that, I'm considering if we should remove a workaround or not.
A ThreadPool object was in the past initialized by the kubernetes client without a specified number of threads to be used, which led to a number of threads matching the number of CPUs. Since kubernetes>=9 they initialize the ThreadPool object with 1 thread by default.
Does this make us no longer need the patch, or is it problematic that a ThreadPool object is instantiated at all? I think so, but does this change with switching to kubernetes_asyncio?
@propertydefpool(self):
"""Create thread pool on first request avoids instantiating unused threadpool for blocking clients. """ifself._poolisNone:
atexit.register(self.close)
self._pool=ThreadPool(self.pool_threads)
returnself._pool
From this, I presume that when self.pool is referenced, a Mock() instance is returned, which just happily accepts everything but does nothing.
Will kubernetes_asyncio use the pool?
Depends, is async_req passed when ApiClient instances calls call_api?
I think neither kubernetes or kubernetes_asyncion makes api requests by passing async_req parameters. But I note there is a difference between a __call_api function.
Overall, I conclude we shouldn't have a threadpool, and Mocking it to never initialize a ThreadPool with one thread is fine - because it will never be referenced no matter what.
At the same time, I wonder if a ThreadPool would ever be initialized? What if the pool property isn't accessed at any time? If it isn't, then it won't try create a ThreadPool at all, and it doesn't look to be read in api_client.py for example - if it were with our mock - I think it would error anyhow.
The text was updated successfully, but these errors were encountered:
I came to basically the same conclusion. I don't think we need it anymore, but it's super-lightweight and it didn't feel like there was any harm in leaving it around. We should not need a threadpool since we're no longer using Threading at all.
TL;DR
I considered if a workaround is still needed, also after
kubernetes_asyncio
is used to replacekubernetes
in #563, and concluded yes it probably is - but it isn't if a property is never read - but that's hard to be confident about.Background
I'm reviewing #563 that replaces
kubernetes
withkubernetes_asyncio
. Doing that, I'm considering if we should remove a workaround or not.Regarding this workaround
This is a workaround introduced in #169.
kubespawner/kubespawner/clients.py
Lines 12 to 19 in a669816
Do we still need it?
A ThreadPool object was in the past initialized by the kubernetes client without a specified number of threads to be used, which led to a number of threads matching the number of CPUs. Since
kubernetes>=9
they initialize the ThreadPool object with1
thread by default.Does this make us no longer need the patch, or is it problematic that a ThreadPool object is instantiated at all? I think so, but does this change with switching to
kubernetes_asyncio
?How does the hack work?
kubespawner/kubespawner/clients.py
Lines 18 to 19 in a669816
This modifies the following code:
From this, I presume that when
self.pool
is referenced, aMock()
instance is returned, which just happily accepts everything but does nothing.Will
kubernetes_asyncio
use thepool
?Depends, is
async_req
passed whenApiClient
instances callscall_api
?Initial conclusion
I think neither
kubernetes
orkubernetes_asyncion
makes api requests by passingasync_req
parameters. But I note there is a difference between a__call_api
function.__call_api
withoutasync
.__call_api
withasync
.Overall, I conclude we shouldn't have a threadpool, and Mocking it to never initialize a ThreadPool with one thread is fine - because it will never be referenced no matter what.
At the same time, I wonder if a ThreadPool would ever be initialized? What if the
pool
property isn't accessed at any time? If it isn't, then it won't try create a ThreadPool at all, and it doesn't look to be read in api_client.py for example - if it were with our mock - I think it would error anyhow.The text was updated successfully, but these errors were encountered: