Cache stats and optimization

Cache stats about time consuming added.
Treap optimized.
Sync strategy changed to process records in batches with only one lock.