Optimize thread count if keys_count < thread_count