Put a separate transaction around allocate_clear

to deal with MySQL issues.  It reduces deadlocks
Do allocate_clear no more than once per second

To lower the load on the database.