Improve query expiration logic

Queries are placed in an expiration queue upon completion. The task
that expires old queries processes the queue in arrival order instead
of looking at every query every time, sorting them by time and processing
the oldest from the list.

Also, increase the interval for processing expired and abandoned queries to
1 second