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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
package benchmarks
import (
"fmt"
"os"
"path/filepath"
"testing"
"time"
)
// BenchmarkDCatSimple benchmarks simple file reading
func BenchmarkDCatSimple(b *testing.B) {
cleanup := SetupBenchmark(b)
defer cleanup()
sizes := GetBenchmarkSizes()
for _, size := range sizes {
b.Run(fmt.Sprintf("Size=%s", size), func(b *testing.B) {
// Generate test file
config := TestDataConfig{
Size: size,
Format: SimpleLogFormat,
Compression: NoCompression,
LineVariation: 50,
}
testFile := GenerateTestFile(b, config)
defer os.Remove(testFile)
fileSize, _ := GetFileSize(testFile)
lineCount, _ := CountFileLines(testFile)
// Warmup
WarmupCommand(b, "dcat", "--plain", "--cfg", "none", testFile)
b.ResetTimer()
// Run benchmark
totalDuration := time.Duration(0)
for i := 0; i < b.N; i++ {
result, err := RunBenchmarkCommand(b, "dcat", "--plain", "--cfg", "none", testFile)
if err != nil {
b.Fatalf("Command failed: %v", err)
}
totalDuration += result.Duration
}
avgDuration := totalDuration / time.Duration(b.N)
throughput := CalculateThroughput(fileSize, avgDuration)
linesPerSec := CalculateLinesPerSecond(lineCount, avgDuration)
// Report metrics
b.ReportMetric(throughput, "MB/sec")
b.ReportMetric(linesPerSec, "lines/sec")
// Save result
benchResult := BenchmarkResult{
Timestamp: time.Now(),
Tool: "dcat",
Operation: fmt.Sprintf("Simple_%s", size),
FileSize: fileSize,
Duration: avgDuration,
Throughput: throughput,
LinesPerSec: linesPerSec,
}
SaveResults([]BenchmarkResult{benchResult})
})
}
}
// BenchmarkDCatMultipleFiles benchmarks reading multiple files
func BenchmarkDCatMultipleFiles(b *testing.B) {
cleanup := SetupBenchmark(b)
defer cleanup()
numFiles := []int{10, 50, 100}
fileSize := Small / 10 // 1MB each
for _, num := range numFiles {
b.Run(fmt.Sprintf("Files=%d", num), func(b *testing.B) {
// Generate test files
var testFiles []string
totalSize := int64(0)
totalLines := 0
for i := 0; i < num; i++ {
config := TestDataConfig{
Size: FileSize(fileSize),
Format: SimpleLogFormat,
Compression: NoCompression,
LineVariation: 50,
}
testFile := GenerateTestFile(b, config)
testFiles = append(testFiles, testFile)
defer os.Remove(testFile)
size, _ := GetFileSize(testFile)
lines, _ := CountFileLines(testFile)
totalSize += size
totalLines += lines
}
// Warmup
args := append([]string{"--plain", "--cfg", "none"}, testFiles...)
WarmupCommand(b, "dcat", args...)
b.ResetTimer()
// Run benchmark
totalDuration := time.Duration(0)
for i := 0; i < b.N; i++ {
result, err := RunBenchmarkCommand(b, "dcat", args...)
if err != nil {
b.Fatalf("Command failed: %v", err)
}
totalDuration += result.Duration
}
avgDuration := totalDuration / time.Duration(b.N)
throughput := CalculateThroughput(totalSize, avgDuration)
linesPerSec := CalculateLinesPerSecond(totalLines, avgDuration)
// Report metrics
b.ReportMetric(throughput, "MB/sec")
b.ReportMetric(linesPerSec, "lines/sec")
b.ReportMetric(float64(num), "files")
// Save result
benchResult := BenchmarkResult{
Timestamp: time.Now(),
Tool: "dcat",
Operation: fmt.Sprintf("MultiFile_%d", num),
FileSize: totalSize,
Duration: avgDuration,
Throughput: throughput,
LinesPerSec: linesPerSec,
}
SaveResults([]BenchmarkResult{benchResult})
})
}
}
// BenchmarkDCatCompressed benchmarks reading compressed files
func BenchmarkDCatCompressed(b *testing.B) {
cleanup := SetupBenchmark(b)
defer cleanup()
compressions := []struct {
name string
typ CompressionType
}{
{"none", NoCompression},
{"gzip", GzipCompression},
{"zstd", ZstdCompression},
}
sizes := GetBenchmarkSizes()
if IsQuickMode() {
sizes = []FileSize{Small}
}
for _, size := range sizes {
for _, comp := range compressions {
b.Run(fmt.Sprintf("Size=%s/Compression=%s", size, comp.name), func(b *testing.B) {
// Generate test file
config := TestDataConfig{
Size: size,
Format: SimpleLogFormat,
Compression: comp.typ,
LineVariation: 50,
}
testFile := GenerateTestFile(b, config)
defer os.Remove(testFile)
// Get uncompressed size for throughput calculation
uncompressedSize := int64(size)
compressedSize, _ := GetFileSize(testFile)
compressionRatio := float64(uncompressedSize) / float64(compressedSize)
// Estimate line count (compressed files are harder to count)
approxLineCount := int(size) / 150
// Warmup
WarmupCommand(b, "dcat", "--plain", "--cfg", "none", testFile)
b.ResetTimer()
// Run benchmark
totalDuration := time.Duration(0)
for i := 0; i < b.N; i++ {
result, err := RunBenchmarkCommand(b, "dcat", "--plain", "--cfg", "none", testFile)
if err != nil {
b.Fatalf("Command failed: %v", err)
}
totalDuration += result.Duration
}
avgDuration := totalDuration / time.Duration(b.N)
// Throughput based on uncompressed size
throughput := CalculateThroughput(uncompressedSize, avgDuration)
linesPerSec := CalculateLinesPerSecond(approxLineCount, avgDuration)
// Report metrics
b.ReportMetric(throughput, "MB/sec")
b.ReportMetric(linesPerSec, "lines/sec")
b.ReportMetric(compressionRatio, "compression_ratio")
// Save result
benchResult := BenchmarkResult{
Timestamp: time.Now(),
Tool: "dcat",
Operation: fmt.Sprintf("Compressed_%s_%s", comp.name, size),
FileSize: uncompressedSize,
Duration: avgDuration,
Throughput: throughput,
LinesPerSec: linesPerSec,
}
SaveResults([]BenchmarkResult{benchResult})
})
}
}
}
// BenchmarkDCatServerMode benchmarks server mode vs serverless
func BenchmarkDCatServerMode(b *testing.B) {
cleanup := SetupBenchmark(b)
defer cleanup()
// Skip if dserver binary doesn't exist
dserverPath := filepath.Join("..", "dserver")
if _, err := os.Stat(dserverPath); err != nil {
b.Skip("dserver binary not found, skipping server mode benchmarks")
}
modes := []struct {
name string
server bool
}{
{"serverless", false},
{"server", true},
}
sizes := GetBenchmarkSizes()
if IsQuickMode() {
sizes = []FileSize{Small}
}
for _, size := range sizes {
for _, mode := range modes {
b.Run(fmt.Sprintf("Size=%s/Mode=%s", size, mode.name), func(b *testing.B) {
// Generate test file
config := TestDataConfig{
Size: size,
Format: SimpleLogFormat,
Compression: NoCompression,
LineVariation: 50,
}
testFile := GenerateTestFile(b, config)
defer os.Remove(testFile)
fileSize, _ := GetFileSize(testFile)
lineCount, _ := CountFileLines(testFile)
var args []string
if mode.server {
// Start dserver
// Note: In a real implementation, we'd need to:
// 1. Start dserver in background
// 2. Wait for it to be ready
// 3. Run dcat with --servers flag
// 4. Stop dserver after benchmark
// For now, we'll skip the actual server mode implementation
b.Skip("Server mode benchmarking requires additional setup")
} else {
args = []string{"--plain", "--cfg", "none", testFile}
}
// Warmup
WarmupCommand(b, "dcat", args...)
b.ResetTimer()
// Run benchmark
totalDuration := time.Duration(0)
for i := 0; i < b.N; i++ {
result, err := RunBenchmarkCommand(b, "dcat", args...)
if err != nil {
b.Fatalf("Command failed: %v", err)
}
totalDuration += result.Duration
}
avgDuration := totalDuration / time.Duration(b.N)
throughput := CalculateThroughput(fileSize, avgDuration)
linesPerSec := CalculateLinesPerSecond(lineCount, avgDuration)
// Report metrics
b.ReportMetric(throughput, "MB/sec")
b.ReportMetric(linesPerSec, "lines/sec")
// Save result
benchResult := BenchmarkResult{
Timestamp: time.Now(),
Tool: "dcat",
Operation: fmt.Sprintf("%s_%s", mode.name, size),
FileSize: fileSize,
Duration: avgDuration,
Throughput: throughput,
LinesPerSec: linesPerSec,
}
SaveResults([]BenchmarkResult{benchResult})
})
}
}
}
|