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 lowe the load on the database.