Skip to content

Commit aff0dcd

Browse files
Added max and min to histogram output. Standardized database and collection in query and collection definitions
1 parent 2a4bec4 commit aff0dcd

File tree

8 files changed

+38
-94
lines changed

8 files changed

+38
-94
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
__pycache__*
22
todo.txt
3+
demo.tape
34
# Binaries
45
# Ignore all binaries in the bin folder
56
bin/

README.md

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -225,64 +225,8 @@ When executed, genMongoLoad performs the following steps:
225225
* Prints a detailed summary table at the end of the run.
226226

227227
### Sample Output
228-
```text
229-
./bin/genMongoLoad
230-
Enter Password for user 'root':
231-
232-
genMongoLoad v1.1.0-dirty
233-
--------------------------------------------------
234-
Database: airline
235-
Workers: 40 active
236-
Duration: 10s
237-
Report Freq: 1s
238-
239-
WORKLOAD DEFINITION
240-
--------------------------------------------------
241-
Batch Size: 1000
242-
Mode: Default Workload
243-
Distribution: Select (60%) Update (20%)
244-
Insert (10%) Delete (10%)
245-
Agg (0%)
246-
247-
[INFO] Loaded 1 collection definition(s)
248-
[INFO] Loaded 2 query templates(s)
249-
[INFO] Skipping sharding for 'flights': Cluster is not sharded (Replica Set)
250-
[INFO] Created 4 indexes on 'flights'
251-
[INFO] Skipping data seeding (configured)
252-
253-
> Starting Workload...
254-
255-
TIME | TOTAL OPS | SELECT | INSERT | UPDATE | DELETE | AGG
256-
---------------------------------------------------------------
257-
00:01 | 8,300 | 5,004 | 798 | 1,650 | 848 | 0
258-
00:02 | 8,048 | 4,736 | 773 | 1,694 | 845 | 0
259-
00:03 | 8,168 | 4,728 | 824 | 1,737 | 879 | 0
260-
00:04 | 8,182 | 4,893 | 817 | 1,695 | 777 | 0
261-
00:05 | 8,504 | 5,047 | 843 | 1,724 | 890 | 0
262-
00:06 | 8,776 | 5,271 | 851 | 1,757 | 897 | 0
263-
00:07 | 8,546 | 5,145 | 880 | 1,699 | 822 | 0
264-
00:08 | 8,365 | 4,945 | 828 | 1,753 | 839 | 0
265-
00:09 | 8,733 | 5,208 | 907 | 1,716 | 902 | 0
266-
00:10 | 6,084 | 3,718 | 551 | 1,236 | 579 | 0
267-
268-
> Workload Finished.
269-
270-
SUMMARY
271-
--------------------------------------------------
272-
Runtime: 10.00s
273-
Total Ops: 81,746
274-
Avg Rate: 8,174 ops/sec
275-
276-
LATENCY DISTRIBUTION (ms)
277-
--------------------------------------------------
278-
TYPE AVG P95 P99
279-
---- --- --- ---
280-
SELECT 1.24 ms 4.00 ms 9.00 ms
281-
INSERT 12.11 ms 66.00 ms 73.00 ms
282-
UPDATE 9.71 ms 65.00 ms 71.00 ms
283-
DELETE 9.60 ms 65.00 ms 72.00 ms
284-
AGG - - -
285-
```
228+
229+
![genMongoLoad Demo](./genMongoLoadDemo.gif)
286230

287231
---
288232

@@ -296,8 +240,8 @@ To run your own workload against your own schema:
296240
```json
297241
[
298242
{
299-
"databaseName": "ecommerce",
300-
"collectionName": "orders",
243+
"database": "ecommerce",
244+
"collection": "orders",
301245
"fields": {
302246
"_id": { "type": "objectid" },
303247
"customer_name": { "type": "string", "provider": "first_name" },

genMongoLoadDemo.gif

543 KB
Loading

internal/config/collections.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ type ShardConfig struct {
3232
}
3333

3434
type CollectionDefinition struct {
35-
DatabaseName string `json:"databaseName"`
36-
Name string `json:"collectionName"`
35+
DatabaseName string `json:"database"`
36+
Name string `json:"collection"`
3737
Fields map[string]CollectionField `json:"fields"`
3838
Indexes []IndexDefinition `json:"indexes,omitempty"`
3939
ShardConfig *ShardConfig `json:"shardConfig,omitempty"`

internal/stats/collector.go

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,23 @@ type LatencyHistogram struct {
2525
Overflow int64
2626
Count int64
2727
Sum float64
28+
Min float64
29+
Max float64
2830
}
2931

3032
func (h *LatencyHistogram) Record(ms float64) {
3133
h.mu.Lock()
3234
defer h.mu.Unlock()
3335
h.Count++
3436
h.Sum += ms
37+
38+
if ms < h.Min {
39+
h.Min = ms
40+
}
41+
if ms > h.Max {
42+
h.Max = ms
43+
}
44+
3545
bucket := int(math.Round(ms))
3646
if bucket < 0 {
3747
bucket = 0
@@ -88,15 +98,16 @@ type Collector struct {
8898

8999
func NewCollector() *Collector {
90100
return &Collector{
91-
FindHist: &LatencyHistogram{},
92-
InsertHist: &LatencyHistogram{},
93-
UpdateHist: &LatencyHistogram{},
94-
DeleteHist: &LatencyHistogram{},
95-
AggHist: &LatencyHistogram{},
101+
FindHist: &LatencyHistogram{Min: math.MaxFloat64},
102+
InsertHist: &LatencyHistogram{Min: math.MaxFloat64},
103+
UpdateHist: &LatencyHistogram{Min: math.MaxFloat64},
104+
DeleteHist: &LatencyHistogram{Min: math.MaxFloat64},
105+
AggHist: &LatencyHistogram{Min: math.MaxFloat64},
96106
startTime: time.Now(),
97107
}
98108
}
99109

110+
// CHANGED: Second argument is now []config.CollectionDefinition instead of dbName string
100111
func PrintConfiguration(appCfg *config.AppConfig, collections []config.CollectionDefinition, version string) {
101112
fmt.Println()
102113
fmt.Printf(" %s\n", logger.CyanString("genMongoLoad %s", version))
@@ -139,28 +150,14 @@ func PrintConfiguration(appCfg *config.AppConfig, collections []config.Collectio
139150
w.Flush()
140151
fmt.Println()
141152

142-
// Logic to extract unique DBs and Namespaces
143-
uniqueDBs := make(map[string]bool)
153+
// Logic to print Namespaces instead of just Database
144154
var namespaces []string
145155
for _, col := range collections {
146-
uniqueDBs[col.DatabaseName] = true
147156
namespaces = append(namespaces, fmt.Sprintf("%s.%s", col.DatabaseName, col.Name))
148157
}
149158

150-
var dbs []string
151-
for db := range uniqueDBs {
152-
dbs = append(dbs, db)
153-
}
154-
sort.Strings(dbs)
155-
sort.Strings(namespaces)
156-
157159
w = tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
158-
159-
// Display Namespaces
160-
if len(namespaces) > 0 {
161-
fmt.Fprintf(w, " Namespaces:\t%s\n", strings.Join(namespaces, ", "))
162-
}
163-
160+
fmt.Fprintf(w, " Namespaces:\t%s\n", strings.Join(namespaces, ", ")) // Changed from Database
164161
fmt.Fprintf(w, " Workers:\t%d active\n", appCfg.Concurrency)
165162
fmt.Fprintf(w, " Duration:\t%s\n", appCfg.Duration)
166163
fmt.Fprintf(w, " Report Freq:\t%ds\n", appCfg.StatusRefreshRateSec)
@@ -303,11 +300,11 @@ func (c *Collector) PrintFinalSummary(duration time.Duration) {
303300
fmt.Println(logger.BoldString(" LATENCY DISTRIBUTION (ms)"))
304301
fmt.Println(logger.CyanString(" --------------------------------------------------"))
305302

306-
const tableLayout = " %-7s %10s %10s %10s"
307-
headerStr := fmt.Sprintf(tableLayout, "TYPE", "AVG", "P95", "P99")
303+
const tableLayout = " %-7s %10s %10s %10s %10s %10s"
304+
headerStr := fmt.Sprintf(tableLayout, "TYPE", "AVG", "MIN", "MAX", "P95", "P99")
308305
fmt.Println(logger.BoldString(headerStr))
309306

310-
separatorStr := fmt.Sprintf(tableLayout, "----", "---", "---", "---")
307+
separatorStr := fmt.Sprintf(tableLayout, "----", "---", "---", "---", "---", "---")
311308
fmt.Println(logger.CyanString(separatorStr))
312309

313310
printLatencyRow(tableLayout, "SELECT", c.FindHist)
@@ -320,14 +317,15 @@ func (c *Collector) PrintFinalSummary(duration time.Duration) {
320317

321318
func printLatencyRow(layout string, label string, h *LatencyHistogram) {
322319
if h.Count == 0 {
323-
fmt.Printf(layout+"\n", label, "-", "-", "-")
320+
fmt.Printf(layout+"\n", label, "-", "-", "-", "-", "-")
324321
return
325322
}
326323
avgMs := h.Sum / float64(h.Count)
327324
p95Ms := h.GetPercentile(95.0)
328325
p99Ms := h.GetPercentile(99.0)
329-
fmt.Printf(layout+"\n", label, formatLatency(avgMs), formatLatency(p95Ms), formatLatency(p99Ms))
326+
fmt.Printf(layout+"\n", label, formatLatency(avgMs), formatLatency(h.Min), formatLatency(h.Max), formatLatency(p95Ms), formatLatency(p99Ms))
330327
}
328+
331329
func formatLatency(ms float64) string {
332330
if ms < 1000.0 {
333331
return fmt.Sprintf("%.2f ms", ms)
@@ -337,6 +335,7 @@ func formatLatency(ms float64) string {
337335
}
338336
return fmt.Sprintf("%.2f m", ms/60000.0)
339337
}
338+
340339
func formatInt(n int64) string {
341340
in := strconv.FormatInt(n, 10)
342341
numOfDigits := len(in)

resources/collections/complex_collection.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
3-
"databaseName": "shop",
4-
"collectionName": "orders",
3+
"database": "shop",
4+
"collection": "orders",
55
"fields": {
66
"_id": {
77
"type": "objectid"

resources/collections/default.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
3-
"databaseName": "airline",
4-
"collectionName": "flights",
3+
"database": "airline",
4+
"collection": "flights",
55
"shardConfig": {
66
"key": {
77
"flight_id": "hashed"

resources/collections/generic.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
3-
"databaseName": "generic",
4-
"collectionName": "sample",
3+
"database": "generic",
4+
"collection": "sample",
55
"shardConfig": {
66
"key": {
77
"field_int32": "hashed"

0 commit comments

Comments
 (0)