11
11
12
12
namespace NKikimr {
13
13
14
- Y_UNIT_TEST_SUITE (TSectorMap ) {
14
+ Y_UNIT_TEST_SUITE (TSectorMapPerformance ) {
15
15
16
- bool TestSectorMapPerformance (NPDisk::NSectorMap::EDiskMode diskMode, ui64 diskSizeGb, ui64 dataSizeMb, bool toFirstSector,
17
- bool testRead, ui32 tries, double deviationRange = 0.05 , std::pair<double , double >* time = nullptr ) {
16
+ enum class ESectorPosition : ui8 {
17
+ SectorFirst = 0 ,
18
+ SectorLast,
19
+ };
20
+
21
+ enum class EOperationType : ui8 {
22
+ OperationRead = 0 ,
23
+ OperationWrite,
24
+ };
25
+
26
+ using EDiskMode = NPDisk::NSectorMap::EDiskMode;
27
+
28
+ bool TestSectorMapPerformance (EDiskMode diskMode, ui64 diskSizeGb, ui64 dataSizeMb, ESectorPosition sectorPosition,
29
+ EOperationType operationType, ui32 tries, double deviationRange = 0.05 , std::pair<double , double >* time = nullptr ) {
18
30
static TString data = PrepareData (1024 * 1024 * 1024 );
19
31
ui64 dataSize = dataSizeMb * 1024 * 1024 ;
20
32
ui64 deviceSize = diskSizeGb * 1024 * 1024 * 1024 ;
21
33
22
34
auto deviceType = NPDisk::NSectorMap::DiskModeToDeviceType (diskMode);
23
35
ui64 diskRate;
24
- if (testRead) {
25
- diskRate = toFirstSector ? NPDisk::DevicePerformance.at (deviceType).FirstSectorReadBytesPerSec :
26
- NPDisk::DevicePerformance.at (deviceType).LastSectorReadBytesPerSec ;
36
+ const auto & performanceParams = NPDisk::DevicePerformance.at (deviceType);
37
+ if (operationType == EOperationType::OperationRead) {
38
+ diskRate = (sectorPosition == ESectorPosition::SectorFirst)
39
+ ? performanceParams.FirstSectorReadBytesPerSec
40
+ : performanceParams.LastSectorReadBytesPerSec ;
27
41
} else {
28
- diskRate = toFirstSector ? NPDisk::DevicePerformance.at (deviceType).FirstSectorWriteBytesPerSec :
29
- NPDisk::DevicePerformance.at (deviceType).LastSectorWriteBytesPerSec ;
42
+ diskRate = (sectorPosition == ESectorPosition::SectorFirst)
43
+ ? performanceParams.FirstSectorWriteBytesPerSec
44
+ : performanceParams.LastSectorWriteBytesPerSec ;
30
45
}
31
46
32
47
ui64 sectorsNum = deviceSize / NPDisk::NSectorMap::SECTOR_SIZE;
33
- ui64 sectorPos = toFirstSector ? 0 : sectorsNum - dataSize / NPDisk::NSectorMap::SECTOR_SIZE - 2 ;
34
- double timeExpected = (double )dataSize / diskRate;
48
+ ui64 sectorPos = (sectorPosition == ESectorPosition::SectorFirst)
49
+ ? 0
50
+ : sectorsNum - dataSize / NPDisk::NSectorMap::SECTOR_SIZE - 2 ;
51
+
52
+ double timeExpected = (double )dataSize / diskRate + 1e-9 * performanceParams.SeekTimeNs ;
35
53
double timeSum = 0 ;
36
54
for (ui32 i = 0 ; i < tries; ++i) {
37
55
NPDisk::TSectorMap sectorMap (deviceSize, diskMode);
38
56
sectorMap.ZeroInit (2 );
39
57
40
58
double timeElapsed = 0 ;
41
- if (testRead ) {
59
+ if (operationType == EOperationType::OperationRead ) {
42
60
sectorMap.Write ((ui8*)data.data (), dataSize, sectorPos * NPDisk::NSectorMap::SECTOR_SIZE);
43
61
THPTimer timer;
44
62
sectorMap.Read ((ui8*)data.data (), dataSize, sectorPos * NPDisk::NSectorMap::SECTOR_SIZE);
@@ -50,44 +68,43 @@ Y_UNIT_TEST_SUITE(TSectorMap) {
50
68
}
51
69
52
70
timeSum += timeElapsed;
53
- }
54
- double timeAvg = timeSum / tries;
55
- double relativeDeviation = (timeAvg - timeExpected) / timeExpected;
56
- if (time ) {
57
- *time = { timeExpected, timeAvg };
58
- }
59
-
60
- return std::abs (relativeDeviation) <= deviationRange;
61
- }
62
71
63
- Y_UNIT_TEST (SectorMapPerformance) {
64
- std::vector<TString> failedTests;
65
-
66
- std::pair<double , double > time ;
67
-
68
- using EDiskMode = NPDisk::NSectorMap::EDiskMode;
69
- auto test = [&](EDiskMode diskMode, ui32 diskSizeGb, ui32 dataSizeMb, bool toFirstSector, bool testRead, ui32 tries) {
70
- if (!TestSectorMapPerformance (diskMode, diskSizeGb, dataSizeMb, toFirstSector, testRead, tries, 0.1 , &time )) {
71
- failedTests.push_back (TStringBuilder () << diskSizeGb << " GB " << NPDisk::NSectorMap::DiskModeToString (diskMode) <<
72
- (testRead ? " read " : " write " ) << dataSizeMb << " MB to" << (toFirstSector ? " first " : " last " ) <<
73
- " sector, timeExpected=" << time .first << " , timeAverage=" << time .second );
72
+ double timeAvg = timeSum / tries;
73
+ double relativeDeviation = (timeAvg - timeExpected) / timeExpected;
74
+ if (time ) {
75
+ *time = { timeExpected, timeAvg };
74
76
}
75
- };
76
-
77
- for (auto diskMode : { EDiskMode::DM_HDD, EDiskMode::DM_SSD }) {
78
- for (ui32 dataSizeMb : { 100 , 1000 }) {
79
- for (bool testRead : { false , true }) {
80
- test (diskMode, 1960 , dataSizeMb, true , testRead, 1 );
81
- }
77
+ if (std::abs (relativeDeviation) <= deviationRange) {
78
+ return true ;
82
79
}
83
80
}
84
- test (EDiskMode::DM_HDD, 1960 , 100 , false , true , 1 );
85
- test (EDiskMode::DM_HDD, 1960 , 100 , false , false , 1 );
86
81
87
- for (auto & testName : failedTests) {
88
- Cerr << testName << Endl;
89
- }
90
- UNIT_ASSERT (failedTests.empty ());
82
+ return false ;
91
83
}
84
+
85
+
86
+ #define MAKE_TEST (diskMode, diskSizeGb, dataSizeMb, operationType, position ) \
87
+ Y_UNIT_TEST (Test##diskMode##diskSizeGb##GB##operationType##dataSizeMb##MB##On##position##Sector) { \
88
+ std::pair<double , double > time ; \
89
+ UNIT_ASSERT_C (TestSectorMapPerformance (EDiskMode::DM_##diskMode, diskSizeGb, dataSizeMb, \
90
+ ESectorPosition::Sector##position, EOperationType::Operation##operationType, 3 , 0.1 , &time ), \
91
+ " Time expected# " << time .first << " actual avg time#" << time .second ); \
92
+ }
93
+
94
+ MAKE_TEST (HDD, 1960 , 100 , Read, First);
95
+ MAKE_TEST (HDD, 1960 , 100 , Read, Last);
96
+ MAKE_TEST (HDD, 1960 , 100 , Write, First);
97
+ MAKE_TEST (HDD, 1960 , 100 , Write, Last);
98
+ MAKE_TEST (HDD, 1960 , 1000 , Read, First);
99
+ MAKE_TEST (HDD, 1960 , 1000 , Read, Last);
100
+ MAKE_TEST (HDD, 1960 , 1000 , Write, First);
101
+ MAKE_TEST (HDD, 1960 , 1000 , Write, Last);
102
+
103
+ MAKE_TEST (SSD, 1960 , 100 , Read, First);
104
+ MAKE_TEST (SSD, 1960 , 100 , Write, First);
105
+ MAKE_TEST (SSD, 1960 , 1000 , Read, First);
106
+ MAKE_TEST (SSD, 1960 , 1000 , Write, First);
107
+
108
+ #undef MAKE_TEST
92
109
}
93
110
}
0 commit comments