<commit_before>/**
 * @file storageHelperCreator.h
 * @author <NAME>
 * @copyright (C) 2016 ACK CYFRONET AGH
 * @copyright This software is released under the MIT license cited in
 * 'LICENSE.txt'
 */

#ifndef HELPERS_STORAGE_HELPER_FACTORY_H
#define HELPERS_STORAGE_HELPER_FACTORY_H

#include "storageHelper.h"

#ifdef BUILD_PROXY_IO
#include "communication/communicator.h"
#endif

#include <boost/optional.hpp>
#include <folly/executors/IOExecutor.h>
#include <tbb/concurrent_hash_map.h>

#include <memory>
#include <string>

namespace one {

class Scheduler;

namespace helpers {
namespace buffering {

class BufferAgentsMemoryLimitGuard;

struct BufferLimits {
    BufferLimits(std::size_t readBufferMinSize_ = 5 * 1024 * 1024,
        std::size_t readBufferMaxSize_ = 10 * 1024 * 1024,
        std::chrono::seconds readBufferPrefetchDuration_ =
            std::chrono::seconds{1},
        std::size_t writeBufferMinSize_ = 20 * 1024 * 1024,
        std::size_t writeBufferMaxSize_ = 50 * 1024 * 1024,
        std::chrono::seconds writeBufferFlushDelay_ = std::chrono::seconds{5},
        std::chrono::nanoseconds targetLatency_ =
            std::chrono::nanoseconds{1000},
        double prefetchPowerBase_ = 1.3, std::size_t readBuffersTotalSize_ = 0,
        std::size_t writeBuffersTotalSize_ = 0)
        : readBufferMinSize{readBufferMinSize_}
        , readBufferMaxSize{readBufferMaxSize_}
        , readBuffersTotalSize{readBuffersTotalSize_}
        , prefetchPowerBase{prefetchPowerBase_}
        , targetLatency{std::move(targetLatency_)}
        , readBufferPrefetchDuration{std::move(readBufferPrefetchDuration_)}
        , writeBufferMinSize{writeBufferMinSize_}
        , writeBufferMaxSize{writeBufferMaxSize_}
        , writeBuffersTotalSize{writeBuffersTotalSize_}
        , writeBufferFlushDelay{std::move(writeBufferFlushDelay_)}
    {
    }

    /**
     * @name Variables impacting prefetching.
     * The prefetched block size is never smaller than @c readBufferMinSize or
     * bigger than @c readBufferMaxSize . The actual formula for prefetched
     * block size is:
     * @code
     * readBufferMinSize * prefetchPowerBase ^ number_of_subsequent_hits
     * @endcode
     * When the number of subsequent hits (i.e. subsequent requested blocks for<commit_msg>VFS-8240 Fxed clang-tidy readability-magic-numbers warnings<commit_after>/**
 * @file storageHelperCreator.h
 * @author <NAME>
 * @copyright (C) 2016 ACK CYFRONET AGH
 * @copyright This software is released under the MIT license cited in
 * 'LICENSE.txt'
 */

#ifndef HELPERS_STORAGE_HELPER_FACTORY_H
#define HELPERS_STORAGE_HELPER_FACTORY_H

#include "storageHelper.h"

#ifdef BUILD_PROXY_IO
#include "communication/communicator.h"
#endif

#include <boost/optional.hpp>
#include <folly/executors/IOExecutor.h>
#include <tbb/concurrent_hash_map.h>

#include <memory>
#include <string>

namespace one {

class Scheduler;

namespace helpers {
namespace buffering {

class BufferAgentsMemoryLimitGuard;

namespace {
constexpr std::size_t kMB = 1024 * 1024;
constexpr std::size_t kReadBufferMinSize = 5 * kMB;
constexpr std::size_t kReadBufferMaxSize = 10 * kMB;
constexpr std::size_t kWriteBufferMinSize = 20 * kMB;
constexpr std::size_t kWriteBufferMaxSize = 50 * kMB;
constexpr int kWriteBufferFlushDelaySeconds = 5;
constexpr int kTargetLatencyNanoSeconds = 1000;
constexpr double kPrefetchPowerBase = 1.3;
}

struct BufferLimits {
    BufferLimits(std::size_t readBufferMinSize_ = kReadBufferMinSize,
        std::size_t readBufferMaxSize_ = kReadBufferMaxSize,
        std::chrono::seconds readBufferPrefetchDuration_ =
            std::chrono::seconds{1},
        std::size_t writeBufferMinSize_ = kWriteBufferMinSize,
        std::size_t writeBufferMaxSize_ = kWriteBufferMaxSize,
        std::chrono::seconds writeBufferFlushDelay_ =
            std::chrono::seconds{kWriteBufferFlushDelaySeconds},
        std::chrono::nanoseconds targetLatency_ =
            std::chrono::nanoseconds{kTargetLatencyNanoSeconds},
        double prefetchPowerBase_ = kPrefetchPowerBase,
        std::size_t readBuffersTotalSize_ = 0,
        std::size_t writeBuffersTotalSize_ = 0)
        : readBufferMinSize{readBufferMinSize_}
        , readBufferMaxSize{readBufferMaxSize_}
        , readBuffersTotalSize{readBuffersTotalSize_}
        , prefetchPowerBase{prefetchPowerBase_}
        , targetLatency{std::move(targetLatency_)}
        , readBufferPrefetchDuration{std::move(readBufferPrefetchDuration_)}
        , writeBufferMinSize{writeBufferMinSize_}
        , writeBufferMaxSize{writeBufferMaxSize_}
        , writeBuffersTotalSize{writeBuffersTotalSize_}
        , writeBufferFlushDelay{std::move(writeBufferFlushDelay_)}
    {
    }

    /**
     * @name Variables impacting prefetching.
     * The prefetched block size is never smaller than @c readBufferMinSize or
     * bigger than @c readBufferMaxSize . The actual formula for prefetched
     * block size is:
     * @code
     * readBufferMinSize * prefetchPowerBase ^ number_of_subsequent_hits
     * @endcode
     * When the number of subsequent hits (i.e. subsequent requested blocks for
{'fraction_non_alphanumeric': 0.08583106267029973, 'fraction_numerical': 0.016738030362008563, 'mean_word_length': 4.217258883248731, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1772183', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1594, 'n_words': 327}