This commit is contained in:
Dongho Kim
2026-05-17 18:34:02 +02:00
parent a221870b70
commit 375f40756e
7 changed files with 168 additions and 69 deletions
+40 -24
View File
@@ -19,7 +19,8 @@ func main() {
listScheds := flag.Bool("list-schedulers", false, "List available schedulers")
addr := flag.String("addr", "127.0.0.1:4242", "Server address")
duration := flag.Int("duration", 10, "Duration in seconds")
payloadSize := flag.Int("payload-size", 1024, "Size of the payload in bytes (min 20)")
messageSize := flag.Int("message-size", 1024, "Size of the full application message in bytes (min 36)")
chunkSize := flag.Int("chunk-size", 0, "Chunk size. If > 0, splits message-size into multiple chunks (min 36)")
flag.Parse()
if *listScheds {
@@ -30,8 +31,8 @@ func main() {
return
}
if *payloadSize < 20 {
*payloadSize = 20 // 4 bytes length, 8 bytes seq, 8 bytes timestamp
if *messageSize < 36 {
*messageSize = 36 // 4 len + 8 seq + 8 ts + 8 chunk_idx + 8 tot_chunks
}
tlsConf := &tls.Config{
@@ -60,37 +61,52 @@ func main() {
log.Fatal(err)
}
fmt.Printf("Stream opened, sending data for %d seconds (Payload Size: %d bytes)...\n", *duration, *payloadSize)
fmt.Printf("Stream opened, sending data for %d seconds (Message Size: %d bytes, Chunk Size: %d)...\n", *duration, *messageSize, *chunkSize)
end := time.Now().Add(time.Duration(*duration) * time.Second)
payload := make([]byte, *payloadSize)
// Frame structure:
// [0:4] uint32 Total Length
// [4:12] uint64 Sequence Number
// [12:20] uint64 Send Timestamp (nanoseconds)
// [20:] Padding (dummy data)
binary.BigEndian.PutUint32(payload[0:4], uint32(*payloadSize))
var seqNum uint64 = 0
var msgId uint64 = 0
totalBytes := 0
totalChunksSent := 0
actualChunkSize := *messageSize
if *chunkSize > 36 && *chunkSize <= *messageSize {
actualChunkSize = *chunkSize
}
totalChunks := uint64((*messageSize + actualChunkSize - 1) / actualChunkSize)
// Target sending rate: we don't want to lock the CPU entirely in a busy loop.
// We yield slightly to allow the network stack to process.
// But to measure max throughput we just send as fast as stream.Write allows.
for time.Now().Before(end) {
seqNum++
msgId++
sendTime := uint64(time.Now().UnixNano())
binary.BigEndian.PutUint64(payload[4:12], seqNum)
binary.BigEndian.PutUint64(payload[12:20], sendTime)
bytesLeft := *messageSize
n, err := stream.Write(payload)
if err != nil {
log.Fatal("Stream write error:", err)
for chunkIdx := uint64(0); chunkIdx < totalChunks; chunkIdx++ {
currentLength := actualChunkSize
if bytesLeft < actualChunkSize {
currentLength = bytesLeft
}
if currentLength < 36 {
currentLength = 36
}
payload := make([]byte, currentLength)
binary.BigEndian.PutUint32(payload[0:4], uint32(currentLength))
binary.BigEndian.PutUint64(payload[4:12], msgId)
binary.BigEndian.PutUint64(payload[12:20], sendTime)
binary.BigEndian.PutUint64(payload[20:28], chunkIdx)
binary.BigEndian.PutUint64(payload[28:36], totalChunks)
n, err := stream.Write(payload)
if err != nil {
log.Fatal("Stream write error:", err)
}
totalBytes += n
bytesLeft -= currentLength
totalChunksSent++
}
totalBytes += n
}
fmt.Printf("Finished sending %d packets, %d bytes (%.2f MB)\n", seqNum, totalBytes, float64(totalBytes)/1024/1024)
fmt.Printf("Finished sending %d messages (%d chunks), %d bytes (%.2f MB)\n", msgId, totalChunksSent, totalBytes, float64(totalBytes)/1024/1024)
}