Skip to content

Commit d92cd52

Browse files
committed
- take out count-invalidated for now, this is unlikely to be useful
1 parent a505d0b commit d92cd52

File tree

4 files changed

+52
-45
lines changed

4 files changed

+52
-45
lines changed

README.rst

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ look like::
248248
count-checkedout
249249
count-connections
250250
count-detached
251-
count-invalidated
252251
count-numpools
253252
count-numprocs
254253
derive-checkouts
@@ -302,30 +301,6 @@ integers representing the current count of a resource or activity:
302301
they have been disconnected from the engine/pool using the ``.detach()``
303302
method but are still being used as a database connection.
304303

305-
* ``count-invalidated`` - total number of connections that have been **explicitly**
306-
invalidated, meaning, the ``.invalidate()`` method has been called
307-
individually for a connection. In this state, there may or may not be a
308-
database connection present for each of these, depending on if the
309-
invalidation was "hard" or "soft". Invalidation usually corresponds to a
310-
connection that reported a problem in being able to communicate with the
311-
database, and for which an error was raised. For this reason, the
312-
"invalidated" count should be considered to be roughly an "error" counter -
313-
each count here usually corresponds to a connectivity error encountered by
314-
the application to which it responded by invalidating the connection, which
315-
results either in immediate or eventual reconnection.
316-
317-
For most invalidation scenarios, the entire pool of connections is
318-
invalidated at once using a "freshness" timestamp; any connection older than
319-
this timestamp is refreshed on next use. This is to suit the case of assuming
320-
that the database was probably restarted, so all connections need to be
321-
reconnected. These connections which have been **implicitly** invalidated
322-
are **not** included in this count.
323-
324-
Since an invalidated connection is usually discarded immediately, this
325-
number as a running count should be very low, unless the database is down in
326-
which case you'll see a spike.The ``derive-invalidated`` value should be
327-
consulted as well which provides an ongoing *rate* of invalidation.
328-
329304
* ``count-numpools`` - the number of connection pools in use. A SQLAlchemy
330305
``Engine`` features exactly one connection pool. If an application connects
331306
to two different database URLs in a process and creates two different
@@ -364,7 +339,8 @@ on the reporting tools being used.
364339
* ``derive-invalidated`` - rate of connections that are explicitly **invalidated**,
365340
e.g. have encountered a connectivity error which made the program invalidate
366341
the connection. The application may or may not have tried to connect
367-
again immediately depending on how it is using this feature.
342+
again immediately depending on how it is using this feature. See the
343+
section on "invalidated connections" below for details on this.
368344

369345
* ``derive-commits`` - (TODO: not implemented yet) rate of calls to ``transaction.commit()``. This value
370346
can be used to estimate TPS, e.g. transactions per second, however note that
@@ -380,19 +356,48 @@ on the reporting tools being used.
380356
if the application also discards transactions and/or ``Session`` objects
381357
without calling ``.commit()`` or ``.rollback()``.
382358

383-
384-
.. topic Collectd types
385-
386-
These funny names ``count-`` and ``derive-`` are an artifact of how
387-
collectd provides **types**. collectd has a fixed list of "types" which it
388-
lists in a file called ``types.db``. The server does not accept type names
389-
that are not either in this file or in a separately configured custom types file,
390-
as each type is accompanied by a template for what kinds of values it
391-
carries. Annoyingly, collectd does not let us add these names within the
392-
regular .conf file, which would make it very easy for us to include
393-
our own custom names; it instead requires they be listed in completely separate file that must be
394-
explicitly referred to by absolute path within a conf file, and then to
395-
make matters worse when this option is used, we have to uncomment the location
396-
of the default types.db file in the central collectd.conf else it will
397-
no longer be able to find it. Given the choice between "very nice names"
398-
and "no need to set up three separate config files", we chose the latter :)
359+
Invalidated Connections
360+
^^^^^^^^^^^^^^^^^^^^^^^
361+
362+
The ``derive-invalidated`` stat records the rate of invalidations.
363+
364+
By invalidated, we mean the ``.invalidated()`` method on the connection
365+
is called, which marks this connection as no longer usable and marks it
366+
for refresh on next use (soft invalidation) or more commonly closes it
367+
immediately (hard invalidation). Typically, when a connection is invalidated,
368+
the application is either pre-pinging the database and will try to connect
369+
again, or it was in the middle of an operation when the database got
370+
cut off, in which case depending on how the application was designed it
371+
may or may not try the operation again.
372+
373+
Invalidation usually corresponds to a
374+
connection that reported a problem in being able to communicate with the
375+
database, and for which an error was raised. For this reason, the
376+
"invalidated" rate should be considered to be roughly an "error" rate -
377+
each count here usually corresponds to a connectivity error encountered by the
378+
application to which it responded by invalidating the connection, which results
379+
either in immediate or eventual reconnection.
380+
381+
For most invalidation scenarios, the entire pool of connections is
382+
invalidated at once using a "freshness" timestamp; any connection older than
383+
this timestamp is refreshed on next use. This is to suit the case of assuming
384+
that the database was probably restarted, so all connections need to be
385+
reconnected. These connections which have been **implicitly** invalidated
386+
are **not** included in this count.
387+
388+
Collectd Types
389+
^^^^^^^^^^^^^^^
390+
391+
These funny names ``count-`` and ``derive-`` are an artifact of how
392+
collectd provides **types**. collectd has a fixed list of "types" which it
393+
lists in a file called ``types.db``. The server does not accept type names
394+
that are not either in this file or in a separately configured custom types file,
395+
as each type is accompanied by a template for what kinds of values it
396+
carries. Annoyingly, collectd does not let us add these names within the
397+
regular .conf file, which would make it very easy for us to include
398+
our own custom names; it instead requires they be listed in completely separate file that must be
399+
explicitly referred to by absolute path within a conf file, and then to
400+
make matters worse when this option is used, we have to uncomment the location
401+
of the default types.db file in the central collectd.conf else it will
402+
no longer be able to find it. Given the choice between "very nice names"
403+
and "no need to set up three separate config files", we chose the latter :)

sqlalchemy_collectd/client/collector.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def __init__(self, name):
2121
# or were checked in
2222
self.checkedin = set()
2323

24-
# note these are prior to being closed and/or discarded
24+
# not clear if this is useful yet. only "soft" invalidated
25+
# will actually be present. still counting them so that
26+
# we can return an accurate checkout count.
2527
self.invalidated = set()
2628

2729
# detached connections.

sqlalchemy_collectd/client/internal_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
("checkedout", protocol.VALUE_GAUGE),
77
("checkedin", protocol.VALUE_GAUGE),
88
("detached", protocol.VALUE_GAUGE),
9-
("invalidated", protocol.VALUE_GAUGE),
9+
# ("invalidated", protocol.VALUE_GAUGE),
1010
("connections", protocol.VALUE_GAUGE),
1111
)
1212

sqlalchemy_collectd/client/sender.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _send_pool(message_sender, connection, collection_target, timestamp):
3737
collection_target.num_checkedout,
3838
collection_target.num_checkedin,
3939
collection_target.num_detached,
40-
collection_target.num_invalidated,
40+
# collection_target.num_invalidated,
4141
collection_target.num_connections
4242
)
4343

0 commit comments

Comments
 (0)