Symptoms: all threads in BackgroundScheduledPool busy, lot of tasks in replication queue, none of the tasks is executing. 

![Screenshot from 2021-04-16 16-21-44_](https://user-images.githubusercontent.com/1549571/115193796-e767d600-a0ec-11eb-887c-5c9c2412e50c.png)

Related to #16895

Possible workarounds (poor options): increasing the background_schedule_pool_size to huge values, or restart server every time when that happens etc. - 

const ASTPtr &,
    const StorageMetadataPtr &,
    const ASTPtr & partition,
    bool final,
    bool deduplicate,
    const Names & deduplicate_by_columns,
    ContextPtr query_context)
{
    
    
    auto table_lock = lockForShare(query_context->getCurrentQueryId(), query_context->getSettingsRef().lock_acquire_timeout);
    assertNotReadonly();
    if (!is_leader)
        throw Exception("OPTIMIZE cannot be done on this replica because it is not a leader", ErrorCodes::NOT_A_LEADER);
    constexpr size_t max_retries = 10;
    std::vector<ReplicatedMergeTreeLogEntryData> merge_entries;
    {
        auto zookeeper = getZooKeeper();
        auto handle_noop = [&] (const String & message)
        {
            if (query_context->getSettingsRef().optimize_throw_if_noop)
                throw Exception(message, ErrorCodes::CANNOT_ASSIGN_OPTIMIZE);
            return false;
        };
        const auto storage_settings_ptr = getSettings();
        auto metadata_snapshot = getInMemoryMetadataPtr();
        if (!partition && final)
        {
            DataPartsVector data_parts = getDataPartsVector();