Skip to content

Commit

Permalink
docs: added details about memoru alignment in structs
Browse files Browse the repository at this point in the history
  • Loading branch information
geolffreym committed Apr 16, 2024
1 parent 00a7ae8 commit ca4f28e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
3 changes: 1 addition & 2 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
// byteToString convert an array of bytes to a string with no-copy strategy.
func bytesToString(b []byte) string {
// Optimizing space with ordered types.
// perf: no allocation/copy to convert to string.
// instead take the already existing byte slice to create a string struct.
// perf: no allocation/copy to convert to string instead take the already existing byte slice to create a string struct.
// WARNING: use this approach with caution and only if we are sure that the bytes slice is not gonna change.
return *(*string)(unsafe.Pointer(&b))
}
Expand Down
25 changes: 17 additions & 8 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ package noise
// We can add any method related to adaptive lookup logic here.
// Please see [docs] for more information.
//
// !IMPORTANT The order of byte size needed for each type in structs matter and impact the struct size.
// The fields are distributed in a way that ensures their alignment in 8-byte blocks.
// For instance on a 64-bit CPU, alignment blocks are 8 bytes.
//
// 0: [latency, bandwidth, nonce, sent], // 8 bytes
// 1: [recv, handshakeTime, 2bytespadding], // 8 bytes
// 2: [bytesRecv], // 8 bytes
// 3: [bytesSent], // 8 bytes
//
// [docs]: https://arxiv.org/pdf/1509.04417.pdf
type metrics struct {
bytesRecv uint64 // bytes received
bytesSent uint64 // bytes sent
handshakeTime uint32 // how long took the handshake to complete.
latency uint16 // rtt in ms
bandwidth uint16 // remote peer bandwidth
nonce uint16 // nonce ordering factor
sent uint16 // counter sent messages
recv uint16 // counter received messages
latency uint16 // rtt in ms: 2bytes
bandwidth uint16 // remote peer bandwidth: 2bytes
nonce uint16 // nonce ordering factor: 2bytes
sent uint16 // counter sent messages: 2bytes
recv uint16 // counter received messages: 2bytes
handshakeTime uint32 // how long took the handshake to complete.: 4bytes
bytesRecv uint64 // bytes received: 8bytes
bytesSent uint64 // bytes sent: 8 bytes
}

// TODO https://community.f5.com/t5/technical-articles/introducing-tcp-analytics/ta-p/290873
Expand Down

0 comments on commit ca4f28e

Please sign in to comment.