1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "../zen.h"
#include <filesystem>
namespace zen {
class BenchPurgeSubCmd : public ZenSubCmdBase
{
public:
BenchPurgeSubCmd();
void Run(const ZenCliOptions& GlobalOptions) override;
private:
bool m_SingleProcess = false;
};
class BenchHttpSubCmd : public ZenSubCmdBase
{
public:
BenchHttpSubCmd();
void Run(const ZenCliOptions& GlobalOptions) override;
private:
void RunFixedCount(const std::string& BaseUri, const std::string& Path);
void RunContinuous(const std::string& BaseUri, const std::string& Path);
std::string m_Url;
std::string m_SocketPath;
int m_Count = 100;
int m_Concurrency = 1;
std::string m_Method = "GET";
bool m_NoKeepAlive = false;
bool m_Continuous = false;
};
class BenchDiskSubCmd : public ZenSubCmdBase
{
public:
BenchDiskSubCmd();
void Run(const ZenCliOptions& GlobalOptions) override;
private:
struct SeqResult
{
uint64_t BytesPerSec = 0;
uint64_t Iops = 0;
double ElapsedSec = 0.0;
int ErrorCount = 0;
bool UsedDirectIo = false;
};
SeqResult RunSeqWrite(const std::filesystem::path& Dir, uint64_t BlockSize, bool DirectIo);
SeqResult RunSeqRead(const std::filesystem::path& Dir, uint64_t BlockSize, bool DirectIo);
SeqResult RunRandWrite(const std::filesystem::path& Dir, uint64_t BlockSize, bool DirectIo);
SeqResult RunRandRead(const std::filesystem::path& Dir, uint64_t BlockSize, bool DirectIo);
void PrefillRandFiles(const std::filesystem::path& Dir, bool DirectIo);
void RunFileOps(const std::filesystem::path& Dir);
void RunClone(const std::filesystem::path& Dir);
void CleanupSeqFiles(const std::filesystem::path& Dir);
void CleanupRandFiles(const std::filesystem::path& Dir);
void CleanupFileOpFiles(const std::filesystem::path& Dir);
void CleanupCloneFiles(const std::filesystem::path& Dir);
void RunSync(const std::filesystem::path& Dir);
void CleanupSyncFiles(const std::filesystem::path& Dir);
std::string m_Path;
std::string m_Run = "seq,rand,ops,clone";
int m_SyncDurationSec = 10;
int m_Concurrency = 1;
uint64_t m_FileSize = 256 * 1024 * 1024;
int m_FileCount = 1000;
int m_RandOps = 10000;
bool m_NoDirectIo = false;
};
class BenchCommand : public ZenCmdWithSubCommands
{
public:
static constexpr char Name[] = "bench";
static constexpr char Description[] = "Utility command for benchmarking";
BenchCommand();
~BenchCommand();
cxxopts::Options& Options() override { return m_Options; }
ZenCmdCategory& CommandCategory() const override { return g_UtilitiesCategory; }
private:
cxxopts::Options m_Options{Name, Description};
std::string m_SubCommand;
BenchPurgeSubCmd m_PurgeSubCmd;
BenchHttpSubCmd m_HttpSubCmd;
BenchDiskSubCmd m_DiskSubCmd;
};
} // namespace zen
|