Tm1SessionPool
from skipcheck_tm1 import Tm1SessionPool Sessions on one TM1 server, one per Tm1Identity, for applications that act on
behalf of many users. In TM1 identity is the session, so the number of sessions grows
with the number of users; the pool keeps that bounded.
# One pool for the application, built once
pool = (
Tm1SessionPool.builder(Tm1Session.builder().base_url("http://tm1:8010/api/v1/").basic_auth("service", secret))
.idle_timeout(timedelta(minutes=10))
.build()
)
# Each time it's needed: the user's session, which logs in on its first request
session = pool.session(Tm1Identity.impersonating(user))
return CubeService(session).list()
- Get a session for each piece of work and don't keep it: the pool may evict it. Getting one never blocks and sends nothing; the session logs in on its first request.
- Eviction happens when a session has been idle for
idle_timeout, is older thanmax_age, or the pool is overmax_size(least recently used first). It's checked on eachsessioncall and everysweep_interval. A session with a request running isn't idle, however long ago it was asked for. - An evicted session is closed after
close_grace, or when the requests running on it have finished, if that's later: closing it would end them on TM1. The next request for that identity gets a new session. closecloses every session at once, and the pool refuses new ones.- Nothing falls back: a refused identity fails, and the pool never uses another identity in its place.
Thread-safe. stats reports what the pool holds and has done, for metrics;
each eviction is also a tm1.session.pool.evict observation, tagged with its
reason.
Members
Stats static | |
__init__ constructor | |
builder static | A builder for a pool of sessions with these settings; each identity's session is built from a copy of them. |
session | The session for identity (the service account if none). |
evict_expired | Evicts every session that has been idle too long or is too old, and closes the evicted ones whose grace period is over and that have no request running. |
sweep_forever | Evicts expired sessions every sweep_interval until the pool is closed (run it alongside, as a task or a thread); a failure is logged and the sweep goes on. |
stats | What the pool holds and has done so far, for metrics. |
is_closed property | Whether close has been called. |
close | Closes every session, including evicted ones still in their grace period, and refuses new ones. |
sweep_interval |
Stats
staticStats__init__
constructor__init__(builder: Tm1SessionPoolBuilder)builder
staticbuilder(sessions: Tm1SessionBuilder) -> Tm1SessionPoolBuilderA builder for a pool of sessions with these settings; each identity's session is built from a copy of them.
session
session(identity: Tm1Identity | None = None) -> Tm1SessionThe session for identity (the service account if none): the pool's, or a new one if it has none, or the one it had has expired. Sends nothing.
evict_expired
evict_expired() -> NoneEvicts every session that has been idle too long or is too old, and closes the evicted ones whose grace period is over and that have no request running.
sweep_forever
sweep_forever() -> NoneEvicts expired sessions every sweep_interval until the pool is closed (run it alongside, as a task or a thread); a failure is logged and the sweep goes on.
stats
stats() -> Tm1PoolStatsWhat the pool holds and has done so far, for metrics.
is_closed
propertyis_closed: boolWhether close has been called.
close
close() -> NoneCloses every session, including evicted ones still in their grace period, and refuses new ones.
sweep_interval
sweep_interval