Hi Sebastien, thanks for the info! Indeed, deleting big files from the filesystem while having to update references in the database can be quite IO/CPU intensive. However, I suspect the slowness I am facing is linked MySQL locks, and I think Orthanc could avoid it.
By default, the isolation level of MySQL 5.7 is
REPEATABLE READ. I changed it to
READ COMMITTED (it is the default in Postgres) and I noticed a decrease in locks. Now, depending on how the bulk-delete creates its deletes queries, it could produce table locks that could block the arrival of new resources.
By running this MySQL query
SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE COMMAND != 'Sleep';I see that both bulk-delete and the old DELETE endpoint create this DELETE (notice the other locked statements):
+------+---------------+------------------------------------+-------------------------+-------+----+------------+-------------------------------------------------------------------------------------------------------------+
|ID |USER |HOST |DB |COMMAND|TIME|STATE |INFO |
+------+---------------+------------------------------------+-------------------------+-------+----+------------+-------------------------------------------------------------------------------------------------------------+
|326039|---------------|---------------- |-------------------------|Execute|109 |Sending data|
DELETE FROM Resources WHERE internalId IN (SELECT internalId FROM DeletedResources) |
|326041|root |localhost:38704 |-------------------------|Execute|109 |update |INSERT INTO Resources VALUES (DEFAULT, 3, instance, seriesKey) |
|326040|root |localhost:38702 |-------------------------|Execute|108 |update |INSERT INTO Resources VALUES (DEFAULT, 3, instance, seriesKey) |
|326042|root |localhost:38706 |-------------------------|Execute|109 |update |INSERT INTO Resources VALUES (DEFAULT, 3, instance, seriesKey) |
|326043|root |localhost:38708 |-------------------------|Execute|107 |update |INSERT INTO Resources VALUES (DEFAULT, 3, instance, seriesKey) |
+------+---------------+------------------------------------+-------------------------+-------+----+------------+-------------------------------------------------------------------------------------------------------------+
And I believe it is locking the entire table. I deduce DeletedResources is a temporary table.
Maybe I could change the way Orthanc builds its delete queries to avoid table locks?