Describe the bug
The queries performed by the evict tool are quite inefficient and produce significant contention with active users of the DSS instance. For example, in a DB where we had ~25k expired rows in the identification_service_areas table, each time the dss-rid-evict job ran for around 20-40min and was unable to make any progress due to contention, before failing with:
failed to execute db-manager: failed to execute RID transaction: timeout: context already done: context deadline exceeded
This also led to failed RID queries - it appears the interactions of these queries are effectively locking all rows in each table.
After killing the dss-rid-evict job, it was possible to delete the expired rows using manual SQL queries:
root@localhost:26257/rid> DELETE FROM identification_service_areas WHERE ends_at <= '<date>' AND writer = '<writer>';
DELETE 24504
Time: 33.266s total (execution 33.266s / network 0.000s)
and
root@localhost:26257/rid> DELETE FROM subscriptions WHERE ends_at <= '<date>' AND writer = '<writer>';
DELETE 800
Time: 1.144s total (execution 1.143s / network 0.000s)
These queries were able to execute quickly and without any observed contention with active traffic.
Note that we have also experienced similar behaviour for SCD.
It seems that we could run these same DELETE queries from within the evict tool to achieve this same significant increase in performance. Currently, the evict tool runs a "list", followed by an individual "delete" for each row returned from the list inside a transaction. This adds up to a large number of individual queries, as well as their accompanying network traffic to/from the DB client. I don't have firm evidence, but it also appears that any API queries on unrelated rows of the table force the transaction to retry.
Is there any reason why these could not be simplified into a single DELETE for ISAs and another for subscriptions (and correspondingly for SCD, operational intents and subscriptions) to keep all this processing within the DB?
Additionally, is there any need to run ISA and subscription deletion together in a single transaction? I imagine we could achieve this without a transaction at all, given each query is implicitly its own transaction and they don't seem to be dependent on each other for consistency. Is that an accurate assumption?
Describe the bug
The queries performed by the
evicttool are quite inefficient and produce significant contention with active users of the DSS instance. For example, in a DB where we had ~25k expired rows in theidentification_service_areastable, each time thedss-rid-evictjob ran for around 20-40min and was unable to make any progress due to contention, before failing with:This also led to failed RID queries - it appears the interactions of these queries are effectively locking all rows in each table.
After killing the
dss-rid-evictjob, it was possible to delete the expired rows using manual SQL queries:and
These queries were able to execute quickly and without any observed contention with active traffic.
Note that we have also experienced similar behaviour for SCD.
It seems that we could run these same
DELETEqueries from within theevicttool to achieve this same significant increase in performance. Currently, theevicttool runs a "list", followed by an individual "delete" for each row returned from the list inside a transaction. This adds up to a large number of individual queries, as well as their accompanying network traffic to/from the DB client. I don't have firm evidence, but it also appears that any API queries on unrelated rows of the table force the transaction to retry.Is there any reason why these could not be simplified into a single DELETE for ISAs and another for subscriptions (and correspondingly for SCD, operational intents and subscriptions) to keep all this processing within the DB?
Additionally, is there any need to run ISA and subscription deletion together in a single transaction? I imagine we could achieve this without a transaction at all, given each query is implicitly its own transaction and they don't seem to be dependent on each other for consistency. Is that an accurate assumption?