SlideShare a Scribd company logo
Brought to you by
Capturing NIC and Kernel
Tx/Rx Timestamps for
Packets in Go
Blain Smith
Staff Software Engineer at Rocket Science
Blain Smith
Staff Software Engineer | Professor of Rocket Systems, Rocket Science
■ 10+ years building AAA online game services (AmongUs,
Unity, WB, Riot, 2K)
■ Low level networking and distributed systems
■ Competitive powerlifter and strongman
■ Multiplayer Games Engineering Specialists!
■ Led, advised or invested in many of the industry’s largest
companies including Unity, PUBG, Multiplay, Vivox among
others as well as building solutions for the biggest games
out there.
■ Publishers around the globe trust us and our expert team to
design and deliver planet-scale online services for the
world’s biggest games such as Rocket League, League of
Legends, DOOM, and many more!
3 Basic Measurements
There are 3 basic measurements we want to know about given any 2 computers
on a network.
■ Latency - time it takes for a packet move from computer A to computer B
■ Jitter - variation of latency over a given timeframe
■ Packet Loss - percentage of packets that were lost over a given timeframe
ping
> ping rocketscience.gg
PING rocketscience.gg (76.76.21.21) 56(84) bytes of data.
64 bytes from 76.76.21.21 (76.76.21.21): icmp_seq=1 ttl=119 time=24.6 ms
64 bytes from 76.76.21.21 (76.76.21.21): icmp_seq=2 ttl=119 time=22.2 ms
64 bytes from 76.76.21.21 (76.76.21.21): icmp_seq=3 ttl=119 time=24.6 ms
64 bytes from 76.76.21.21 (76.76.21.21): icmp_seq=4 ttl=119 time=23.0 ms
64 bytes from 76.76.21.21 (76.76.21.21): icmp_seq=5 ttl=119 time=23.9 ms
^C
--- rocketscience.gg ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4012ms
rtt min/avg/max/mdev = 22.184/23.666/24.618/0.935 ms
ping with Go
// using https://github.com/go-ping/ping
pinger, err := ping.NewPinger("rocketscience.gg")
if err != nil {
panic(err)
}
pinger.Count = 3
err = pinger.Run()
if err != nil {
panic(err)
}
stats := pinger.Statistics() // get send/receive/duplicate/rtt stats
HTTP Timestamp with Go
// http_server.go
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
log.Println(time.Now().UnixNano(), r.Method, r.URL.String())
w.WriteHeader(http.StatusOK)
io.Copy(w, r.Body)
})
http.ListenAndServe(":8080", nil)
// Client
> curl -d 'testing' localhost:8080
Testing
// Server Logs
2022/05/23 19:41:44 1653349304362572711 POST /
TCP Timestamp with Go
// tcp_server.go
ln, _ := net.Listen("tcp", ":8080")
for {
conn, _ := ln.Accept()
go func(conn net.Conn) {
log.Println(time.Now().UnixNano(), conn.RemoteAddr().String())
io.Copy(conn, conn)
}(conn)
}
// Client
> netcat localhost 8080
hi
hi
// Server Logs
2022/05/23 20:52:31 1653353551565391099 [::1]:53648
UDP Timestamp with Go
// udp_server.go
conn, _ := net.ListenPacket("udp", ":8080")
for {
data := make([]byte, 1024)
n, src, _ := conn.ReadFrom(data)
log.Println(time.Now().UnixNano(), src.String())
conn.WriteTo(data[:n], src)
}
// Client
> netcat -u localhost 8080
hi
hi
// Server Logs
2022/05/23 20:57:43 1653353863894400940 [::1]:48194
Problems with time.Time in Go
Every time you call tcpconn.(Read|Write) or udpconn.(ReadFrom|WriteTo)
your Go process makes a Linux system call send or recv via the kernel so it can
put the data into the NIC queue to be sent out onto or read in from the wire. These
system calls and queues all take time.
Sample Ping Sequence
■ Latency = Rx - Tx in
userspace
■ Includes kernel time (green)
● Go runtime context switching
● OS context switching
■ Includes NIC queue (blue)
● Tx/Rx buffers
■ We want just wire time
(orange)
Packet Sequence with Control Messages
■ Full Latency = Rx - Tx in userspace
■ Kernel Tx: is when packet makes it into the
kernel from userspace
■ NIC Tx is when the packet gets placed onto
the wire (if supported by hardware)
■ Kernel Rx is when the packet enters the
kernel from the NIC
■ NIC Rx is when the packet comes in from the
wire into the NIC
AF_PACKET
■ Requires we manually construct each layer of our packet and wrap our data
(Layer 1, 2, 3, and 4) manually
■ The great github.com/mdlayher/socket library makes working with raw
sockets very idiomatic
socket, err := socket.Socket(unix.AF_PACKET, unix.SOCK_RAW, 0, "socket", nil)
socket.ReadFrom(...)
socket.WriteTo(...)
Manually Creating Packet []byte
■ Use github.com/google/gopacket
■ Allows you to encode/decode packet layers
l1 := layers.Ethernet{SrcMAC: smac, DstMAC: dmac EthernetType: layers.EthernetTypeIPv4}
l2 := layers.IPv4{Version: 4, TTL: 64, Protocol: layers.IPProtocolUDP, SrcIP: saddr, DstIP: daddr}
l3 := layers.UDP{SrcPort: layers.UDPPort(sport), DstPort: layers.UDPPort(dport)}
l4 := []byte("this is my application data")
pkt := gopacket.NewSerializeBuffer()
gopacket.SerializeLayers(pkt, nil, l1, l2, l4, gopacket.Payload(l4))
fullpkt := pkt.Bytes()
socket.Write(fullpkt)
SO_TIMESTAMPING for Control Messages
Control messages are extra information provided by the Linux kernel about the socket.
Timestamp information is transmitted with these control messages using specific types.
Accessing these control messages are available with Resvmsg on a socket to "receive a
message" from the kernel once SO_TIMESTAMPING is enabled on the socket.
https://www.kernel.org/doc/html/latest/networking/timestamping.html
data := make([]byte, 1024)
cmsg := make([]byte, 1024)
// read incoming data from the RX queue (normally conn.Read)
socket.Recvmsg(data, cmsg, 0)
// read outgoing data from the TX queue (sent with conn.Write)
socket.Recvmsg(data, cmg, unix.MSG_ERRQUEUE)
Parsing the Timestamps in Control Messages
Socket kernel and NIC timestamp information can be parsed from these control
messages.
msgs, _ := unix.ParseSocketControlMessage(cmsg)
if msg.Header.Level != unix.SOL_SOCKET && msg.Header.Type != SocketOptTimestamping {
return ts, fmt.Errorf("no timestamp control messages")
}
var ts SocketTimestamps
ts.Software = time.Unix(int64(binary.LittleEndian.Uint64(msg.Data[0:])),
int64(binary.LittleEndian.Uint64(msg.Data[8:]))) // kernel timestamp
ts.Hardware = time.Unix(int64(binary.LittleEndian.Uint64(msg.Data[32:])),
int64(binary.LittleEndian.Uint64(msg.Data[40:]))) // NIC timestamp (if supported by NIC hardware)
Use blainsmith/fast_afpacket
■ Implements net.PacketConn
■ Sets up the AF_PACKET & SO_TIMESTAMPING options for you
■ Offer convenient RecvTxTimestamps() & RecvRxTimestamps()
// create a socket and bind it directly to the interface
// named eth0 and send/recv all IPv4/v6 TCP/UDP traffic!
iface, _ := net.InterfaceByName("eth0")
socket, _ := fastafpacket.Listen(iface, unix.SOCK_RAW, unix.ETH_P_ALL, nil)
Packet Sender/Receiver
for range ticker.C {
packet, _ := encodePacket(srcmac, srcip, srcport, dstmac, dstip, dstport, data)
_, _ = conn.WriteTo(packet, &fastafpacket.Addr{HardwareAddr: dstmac})
}
for {
packet := make([]byte, 1024)
_, _, ts, _ := conn.RecvTxTimestamps(packet)
log.Println(“tx”, ts.Hardware.UnixNano(), ts.Software.UnixNano())
}
// tx 1652138203507654453 1652138202507654453
for {
packet := make([]byte, 1024)
n, _, ts, _ := conn.RecvRxTimestamps(packet)
log.Println(“rx”, ts.Hardware.UnixNano(), ts.Software.UnixNano(), ts.Hardware.Sub(time.Now()))
}
// rx 1652138204508141040 1652138203508141040 -423.796µs
Use Cases
■ One-way latency NIC A -> NIC B
● Asymmetric measurements
● NIC B -> NIC A might be different
■ Observability into time being spent processing packets
● in/out kernel
● in/out NIC queues
■ Wire only
● Subtract kernel and NIC timestamps from userspace timestamps
● Removes jitter introduced from context switching (both Go runtime and OS) and NIC queuing
■ Target specific NICs
● Target which NIC the packet goes out and which destination NIC on the receiving side
● Expose slow NIC queues when comparing to other NICs on the same machine
Timestamp Delays
Once we have kernel and NIC timestamp information we can calculate the delays
between each of the layers.
■ tx.Software.Sub(userspaceTxTime) = outgoing kernel delay
■ tx.Hardware.Sub(userspaceTxTime) = outgoing NIC delay
■ rx.Software.Sub(userspaceRxTime) = incoming kernel delay
■ rx.Hardware.Sub(userspaceRxTime) = incoming NIC delay
Timestamping Support
■ Kernel timestamping should be able for most, but hardware timestamps
depends on NIC hardware
■ Mellanox (owned by NVIDIA) NICs have support
■ Use ethtool to check your own hardware
> ethtool -T eth0
Time stamping parameters for eth0:
Capabilities:
hardware-transmit (SOF_TIMESTAMPING_TX_HARDWARE)
software-transmit (SOF_TIMESTAMPING_TX_SOFTWARE)
hardware-receive (SOF_TIMESTAMPING_RX_HARDWARE)
software-receive (SOF_TIMESTAMPING_RX_SOFTWARE)
software-system-clock (SOF_TIMESTAMPING_SOFTWARE)
hardware-raw-clock (SOF_TIMESTAMPING_RAW_HARDWARE)
PTP Hardware Clock: 0
Hardware Transmit Timestamp Modes:
off (HWTSTAMP_TX_OFF)
on (HWTSTAMP_TX_ON)
Further Reading
■ AF_PACKET: https://man7.org/linux/man-pages/man7/packet.7.html
■ SO_TIMESTAMPING: https://www.kernel.org/doc/html/latest/networking/timestamping.html
■ One-way Delay: https://api.semanticscholar.org/CorpusID:5433866
■ Clock and Time Sync: https://arxiv.org/abs/2106.16140
■ NTP: http://www.ntp.org
Brought to you by
Blain Smith
@blainsmith
blainsmith.com
rocketscience.gg

More Related Content

What's hot

BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and more
Brendan Gregg
 
Linux BPF Superpowers
Linux BPF SuperpowersLinux BPF Superpowers
Linux BPF Superpowers
Brendan Gregg
 
LinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughLinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking Walkthrough
Thomas Graf
 
Linux Linux Traffic Control
Linux Linux Traffic ControlLinux Linux Traffic Control
Linux Linux Traffic Control
SUSE Labs Taipei
 
Intel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsIntel DPDK Step by Step instructions
Intel DPDK Step by Step instructions
Hisaki Ohara
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
艾鍗科技
 
Dpdk performance
Dpdk performanceDpdk performance
Dpdk performance
Stephen Hemminger
 
Using eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in CiliumUsing eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in Cilium
ScyllaDB
 
Dpdk applications
Dpdk applicationsDpdk applications
Dpdk applications
Vipin Varghese
 
Faster packet processing in Linux: XDP
Faster packet processing in Linux: XDPFaster packet processing in Linux: XDP
Faster packet processing in Linux: XDP
Daniel T. Lee
 
Advanced Debugging with GDB
Advanced Debugging with GDBAdvanced Debugging with GDB
Advanced Debugging with GDB
David Khosid
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
Kernel TLV
 
DevConf 2014 Kernel Networking Walkthrough
DevConf 2014   Kernel Networking WalkthroughDevConf 2014   Kernel Networking Walkthrough
DevConf 2014 Kernel Networking Walkthrough
Thomas Graf
 
[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?
NAVER D2
 
Boost UDP Transaction Performance
Boost UDP Transaction PerformanceBoost UDP Transaction Performance
Boost UDP Transaction Performance
LF Events
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux Kernel
Adrian Huang
 
Secret of Intel Management Engine by Igor Skochinsky
Secret of Intel Management Engine  by Igor SkochinskySecret of Intel Management Engine  by Igor Skochinsky
Secret of Intel Management Engine by Igor Skochinsky
CODE BLUE
 
Linux Performance Profiling and Monitoring
Linux Performance Profiling and MonitoringLinux Performance Profiling and Monitoring
Linux Performance Profiling and Monitoring
Georg Schönberger
 
Function Level Analysis of Linux NVMe Driver
Function Level Analysis of Linux NVMe DriverFunction Level Analysis of Linux NVMe Driver
Function Level Analysis of Linux NVMe Driver
인구 강
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Works
Zhen Wei
 

What's hot (20)

BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and more
 
Linux BPF Superpowers
Linux BPF SuperpowersLinux BPF Superpowers
Linux BPF Superpowers
 
LinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughLinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking Walkthrough
 
Linux Linux Traffic Control
Linux Linux Traffic ControlLinux Linux Traffic Control
Linux Linux Traffic Control
 
Intel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsIntel DPDK Step by Step instructions
Intel DPDK Step by Step instructions
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
 
Dpdk performance
Dpdk performanceDpdk performance
Dpdk performance
 
Using eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in CiliumUsing eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in Cilium
 
Dpdk applications
Dpdk applicationsDpdk applications
Dpdk applications
 
Faster packet processing in Linux: XDP
Faster packet processing in Linux: XDPFaster packet processing in Linux: XDP
Faster packet processing in Linux: XDP
 
Advanced Debugging with GDB
Advanced Debugging with GDBAdvanced Debugging with GDB
Advanced Debugging with GDB
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
 
DevConf 2014 Kernel Networking Walkthrough
DevConf 2014   Kernel Networking WalkthroughDevConf 2014   Kernel Networking Walkthrough
DevConf 2014 Kernel Networking Walkthrough
 
[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?
 
Boost UDP Transaction Performance
Boost UDP Transaction PerformanceBoost UDP Transaction Performance
Boost UDP Transaction Performance
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux Kernel
 
Secret of Intel Management Engine by Igor Skochinsky
Secret of Intel Management Engine  by Igor SkochinskySecret of Intel Management Engine  by Igor Skochinsky
Secret of Intel Management Engine by Igor Skochinsky
 
Linux Performance Profiling and Monitoring
Linux Performance Profiling and MonitoringLinux Performance Profiling and Monitoring
Linux Performance Profiling and Monitoring
 
Function Level Analysis of Linux NVMe Driver
Function Level Analysis of Linux NVMe DriverFunction Level Analysis of Linux NVMe Driver
Function Level Analysis of Linux NVMe Driver
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Works
 

Similar to Capturing NIC and Kernel TX and RX Timestamps for Packets in Go

Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)
Andriy Berestovskyy
 
#2 (UDP)
#2 (UDP)#2 (UDP)
#2 (UDP)
Ghadeer AlHasan
 
Pycon - Python for ethical hackers
Pycon - Python for ethical hackers Pycon - Python for ethical hackers
Pycon - Python for ethical hackers
Mohammad Reza Kamalifard
 
Gpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cudaGpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cuda
Ferdinand Jamitzky
 
Please help with the below 3 questions, the python script is at the.pdf
Please help with the below 3  questions, the python script is at the.pdfPlease help with the below 3  questions, the python script is at the.pdf
Please help with the below 3 questions, the python script is at the.pdf
support58
 
LSFMM 2019 BPF Observability
LSFMM 2019 BPF ObservabilityLSFMM 2019 BPF Observability
LSFMM 2019 BPF Observability
Brendan Gregg
 
So you think you can stream.pptx
So you think you can stream.pptxSo you think you can stream.pptx
So you think you can stream.pptx
Prakash Chockalingam
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eve
chiportal
 
Ping to Pong
Ping to PongPing to Pong
Ping to Pong
Matt Provost
 
A22 Introduction to DTrace by Kyle Hailey
A22 Introduction to DTrace by Kyle HaileyA22 Introduction to DTrace by Kyle Hailey
A22 Introduction to DTrace by Kyle Hailey
Insight Technology, Inc.
 
Understanding DPDK
Understanding DPDKUnderstanding DPDK
Understanding DPDK
Denys Haryachyy
 
Stress your DUT
Stress your DUTStress your DUT
Stress your DUT
Redge Technologies
 
PLNOG20 - Paweł Małachowski - Stress your DUT–wykorzystanie narzędzi open sou...
PLNOG20 - Paweł Małachowski - Stress your DUT–wykorzystanie narzędzi open sou...PLNOG20 - Paweł Małachowski - Stress your DUT–wykorzystanie narzędzi open sou...
PLNOG20 - Paweł Małachowski - Stress your DUT–wykorzystanie narzędzi open sou...
PROIDEA
 
Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing Landscape
Sasha Goldshtein
 
Open stack pike-devstack-tutorial
Open stack pike-devstack-tutorialOpen stack pike-devstack-tutorial
Open stack pike-devstack-tutorial
Eueung Mulyana
 
Osol Pgsql
Osol PgsqlOsol Pgsql
Osol Pgsql
Emanuel Calvo
 
How to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking NeedsHow to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking Needs
DigitalOcean
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
Tushar B Kute
 
Cassandra 2.1 boot camp, Overview
Cassandra 2.1 boot camp, OverviewCassandra 2.1 boot camp, Overview
Cassandra 2.1 boot camp, Overview
Joshua McKenzie
 
Ns network simulator
Ns network simulatorNs network simulator
Ns network simulator
Dr. Edwin Hernandez
 

Similar to Capturing NIC and Kernel TX and RX Timestamps for Packets in Go (20)

Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)
 
#2 (UDP)
#2 (UDP)#2 (UDP)
#2 (UDP)
 
Pycon - Python for ethical hackers
Pycon - Python for ethical hackers Pycon - Python for ethical hackers
Pycon - Python for ethical hackers
 
Gpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cudaGpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cuda
 
Please help with the below 3 questions, the python script is at the.pdf
Please help with the below 3  questions, the python script is at the.pdfPlease help with the below 3  questions, the python script is at the.pdf
Please help with the below 3 questions, the python script is at the.pdf
 
LSFMM 2019 BPF Observability
LSFMM 2019 BPF ObservabilityLSFMM 2019 BPF Observability
LSFMM 2019 BPF Observability
 
So you think you can stream.pptx
So you think you can stream.pptxSo you think you can stream.pptx
So you think you can stream.pptx
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eve
 
Ping to Pong
Ping to PongPing to Pong
Ping to Pong
 
A22 Introduction to DTrace by Kyle Hailey
A22 Introduction to DTrace by Kyle HaileyA22 Introduction to DTrace by Kyle Hailey
A22 Introduction to DTrace by Kyle Hailey
 
Understanding DPDK
Understanding DPDKUnderstanding DPDK
Understanding DPDK
 
Stress your DUT
Stress your DUTStress your DUT
Stress your DUT
 
PLNOG20 - Paweł Małachowski - Stress your DUT–wykorzystanie narzędzi open sou...
PLNOG20 - Paweł Małachowski - Stress your DUT–wykorzystanie narzędzi open sou...PLNOG20 - Paweł Małachowski - Stress your DUT–wykorzystanie narzędzi open sou...
PLNOG20 - Paweł Małachowski - Stress your DUT–wykorzystanie narzędzi open sou...
 
Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing Landscape
 
Open stack pike-devstack-tutorial
Open stack pike-devstack-tutorialOpen stack pike-devstack-tutorial
Open stack pike-devstack-tutorial
 
Osol Pgsql
Osol PgsqlOsol Pgsql
Osol Pgsql
 
How to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking NeedsHow to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking Needs
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Cassandra 2.1 boot camp, Overview
Cassandra 2.1 boot camp, OverviewCassandra 2.1 boot camp, Overview
Cassandra 2.1 boot camp, Overview
 
Ns network simulator
Ns network simulatorNs network simulator
Ns network simulator
 

More from ScyllaDB

Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
ScyllaDB
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
ScyllaDB
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
ScyllaDB
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
ScyllaDB
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
ScyllaDB
 
What Developers Need to Unlearn for High Performance NoSQL
What Developers Need to Unlearn for High Performance NoSQLWhat Developers Need to Unlearn for High Performance NoSQL
What Developers Need to Unlearn for High Performance NoSQL
ScyllaDB
 
Low Latency at Extreme Scale: Proven Practices & Pitfalls
Low Latency at Extreme Scale: Proven Practices & PitfallsLow Latency at Extreme Scale: Proven Practices & Pitfalls
Low Latency at Extreme Scale: Proven Practices & Pitfalls
ScyllaDB
 
Dissecting Real-World Database Performance Dilemmas
Dissecting Real-World Database Performance DilemmasDissecting Real-World Database Performance Dilemmas
Dissecting Real-World Database Performance Dilemmas
ScyllaDB
 
Beyond Linear Scaling: A New Path for Performance with ScyllaDB
Beyond Linear Scaling: A New Path for Performance with ScyllaDBBeyond Linear Scaling: A New Path for Performance with ScyllaDB
Beyond Linear Scaling: A New Path for Performance with ScyllaDB
ScyllaDB
 
Dissecting Real-World Database Performance Dilemmas
Dissecting Real-World Database Performance DilemmasDissecting Real-World Database Performance Dilemmas
Dissecting Real-World Database Performance Dilemmas
ScyllaDB
 
Database Performance at Scale Masterclass: Workload Characteristics by Felipe...
Database Performance at Scale Masterclass: Workload Characteristics by Felipe...Database Performance at Scale Masterclass: Workload Characteristics by Felipe...
Database Performance at Scale Masterclass: Workload Characteristics by Felipe...
ScyllaDB
 
Database Performance at Scale Masterclass: Database Internals by Pavel Emelya...
Database Performance at Scale Masterclass: Database Internals by Pavel Emelya...Database Performance at Scale Masterclass: Database Internals by Pavel Emelya...
Database Performance at Scale Masterclass: Database Internals by Pavel Emelya...
ScyllaDB
 
Database Performance at Scale Masterclass: Driver Strategies by Piotr Sarna
Database Performance at Scale Masterclass: Driver Strategies by Piotr SarnaDatabase Performance at Scale Masterclass: Driver Strategies by Piotr Sarna
Database Performance at Scale Masterclass: Driver Strategies by Piotr Sarna
ScyllaDB
 
Replacing Your Cache with ScyllaDB
Replacing Your Cache with ScyllaDBReplacing Your Cache with ScyllaDB
Replacing Your Cache with ScyllaDB
ScyllaDB
 
Powering Real-Time Apps with ScyllaDB_ Low Latency & Linear Scalability
Powering Real-Time Apps with ScyllaDB_ Low Latency & Linear ScalabilityPowering Real-Time Apps with ScyllaDB_ Low Latency & Linear Scalability
Powering Real-Time Apps with ScyllaDB_ Low Latency & Linear Scalability
ScyllaDB
 
7 Reasons Not to Put an External Cache in Front of Your Database.pptx
7 Reasons Not to Put an External Cache in Front of Your Database.pptx7 Reasons Not to Put an External Cache in Front of Your Database.pptx
7 Reasons Not to Put an External Cache in Front of Your Database.pptx
ScyllaDB
 
Getting the most out of ScyllaDB
Getting the most out of ScyllaDBGetting the most out of ScyllaDB
Getting the most out of ScyllaDB
ScyllaDB
 
NoSQL Database Migration Masterclass - Session 2: The Anatomy of a Migration
NoSQL Database Migration Masterclass - Session 2: The Anatomy of a MigrationNoSQL Database Migration Masterclass - Session 2: The Anatomy of a Migration
NoSQL Database Migration Masterclass - Session 2: The Anatomy of a Migration
ScyllaDB
 
NoSQL Database Migration Masterclass - Session 3: Migration Logistics
NoSQL Database Migration Masterclass - Session 3: Migration LogisticsNoSQL Database Migration Masterclass - Session 3: Migration Logistics
NoSQL Database Migration Masterclass - Session 3: Migration Logistics
ScyllaDB
 
NoSQL Data Migration Masterclass - Session 1 Migration Strategies and Challenges
NoSQL Data Migration Masterclass - Session 1 Migration Strategies and ChallengesNoSQL Data Migration Masterclass - Session 1 Migration Strategies and Challenges
NoSQL Data Migration Masterclass - Session 1 Migration Strategies and Challenges
ScyllaDB
 

More from ScyllaDB (20)

Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
What Developers Need to Unlearn for High Performance NoSQL
What Developers Need to Unlearn for High Performance NoSQLWhat Developers Need to Unlearn for High Performance NoSQL
What Developers Need to Unlearn for High Performance NoSQL
 
Low Latency at Extreme Scale: Proven Practices & Pitfalls
Low Latency at Extreme Scale: Proven Practices & PitfallsLow Latency at Extreme Scale: Proven Practices & Pitfalls
Low Latency at Extreme Scale: Proven Practices & Pitfalls
 
Dissecting Real-World Database Performance Dilemmas
Dissecting Real-World Database Performance DilemmasDissecting Real-World Database Performance Dilemmas
Dissecting Real-World Database Performance Dilemmas
 
Beyond Linear Scaling: A New Path for Performance with ScyllaDB
Beyond Linear Scaling: A New Path for Performance with ScyllaDBBeyond Linear Scaling: A New Path for Performance with ScyllaDB
Beyond Linear Scaling: A New Path for Performance with ScyllaDB
 
Dissecting Real-World Database Performance Dilemmas
Dissecting Real-World Database Performance DilemmasDissecting Real-World Database Performance Dilemmas
Dissecting Real-World Database Performance Dilemmas
 
Database Performance at Scale Masterclass: Workload Characteristics by Felipe...
Database Performance at Scale Masterclass: Workload Characteristics by Felipe...Database Performance at Scale Masterclass: Workload Characteristics by Felipe...
Database Performance at Scale Masterclass: Workload Characteristics by Felipe...
 
Database Performance at Scale Masterclass: Database Internals by Pavel Emelya...
Database Performance at Scale Masterclass: Database Internals by Pavel Emelya...Database Performance at Scale Masterclass: Database Internals by Pavel Emelya...
Database Performance at Scale Masterclass: Database Internals by Pavel Emelya...
 
Database Performance at Scale Masterclass: Driver Strategies by Piotr Sarna
Database Performance at Scale Masterclass: Driver Strategies by Piotr SarnaDatabase Performance at Scale Masterclass: Driver Strategies by Piotr Sarna
Database Performance at Scale Masterclass: Driver Strategies by Piotr Sarna
 
Replacing Your Cache with ScyllaDB
Replacing Your Cache with ScyllaDBReplacing Your Cache with ScyllaDB
Replacing Your Cache with ScyllaDB
 
Powering Real-Time Apps with ScyllaDB_ Low Latency & Linear Scalability
Powering Real-Time Apps with ScyllaDB_ Low Latency & Linear ScalabilityPowering Real-Time Apps with ScyllaDB_ Low Latency & Linear Scalability
Powering Real-Time Apps with ScyllaDB_ Low Latency & Linear Scalability
 
7 Reasons Not to Put an External Cache in Front of Your Database.pptx
7 Reasons Not to Put an External Cache in Front of Your Database.pptx7 Reasons Not to Put an External Cache in Front of Your Database.pptx
7 Reasons Not to Put an External Cache in Front of Your Database.pptx
 
Getting the most out of ScyllaDB
Getting the most out of ScyllaDBGetting the most out of ScyllaDB
Getting the most out of ScyllaDB
 
NoSQL Database Migration Masterclass - Session 2: The Anatomy of a Migration
NoSQL Database Migration Masterclass - Session 2: The Anatomy of a MigrationNoSQL Database Migration Masterclass - Session 2: The Anatomy of a Migration
NoSQL Database Migration Masterclass - Session 2: The Anatomy of a Migration
 
NoSQL Database Migration Masterclass - Session 3: Migration Logistics
NoSQL Database Migration Masterclass - Session 3: Migration LogisticsNoSQL Database Migration Masterclass - Session 3: Migration Logistics
NoSQL Database Migration Masterclass - Session 3: Migration Logistics
 
NoSQL Data Migration Masterclass - Session 1 Migration Strategies and Challenges
NoSQL Data Migration Masterclass - Session 1 Migration Strategies and ChallengesNoSQL Data Migration Masterclass - Session 1 Migration Strategies and Challenges
NoSQL Data Migration Masterclass - Session 1 Migration Strategies and Challenges
 

Recently uploaded

Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
TIPNGVN2
 

Recently uploaded (20)

Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
 

Capturing NIC and Kernel TX and RX Timestamps for Packets in Go

  • 1. Brought to you by Capturing NIC and Kernel Tx/Rx Timestamps for Packets in Go Blain Smith Staff Software Engineer at Rocket Science
  • 2. Blain Smith Staff Software Engineer | Professor of Rocket Systems, Rocket Science ■ 10+ years building AAA online game services (AmongUs, Unity, WB, Riot, 2K) ■ Low level networking and distributed systems ■ Competitive powerlifter and strongman
  • 3. ■ Multiplayer Games Engineering Specialists! ■ Led, advised or invested in many of the industry’s largest companies including Unity, PUBG, Multiplay, Vivox among others as well as building solutions for the biggest games out there. ■ Publishers around the globe trust us and our expert team to design and deliver planet-scale online services for the world’s biggest games such as Rocket League, League of Legends, DOOM, and many more!
  • 4. 3 Basic Measurements There are 3 basic measurements we want to know about given any 2 computers on a network. ■ Latency - time it takes for a packet move from computer A to computer B ■ Jitter - variation of latency over a given timeframe ■ Packet Loss - percentage of packets that were lost over a given timeframe
  • 5. ping > ping rocketscience.gg PING rocketscience.gg (76.76.21.21) 56(84) bytes of data. 64 bytes from 76.76.21.21 (76.76.21.21): icmp_seq=1 ttl=119 time=24.6 ms 64 bytes from 76.76.21.21 (76.76.21.21): icmp_seq=2 ttl=119 time=22.2 ms 64 bytes from 76.76.21.21 (76.76.21.21): icmp_seq=3 ttl=119 time=24.6 ms 64 bytes from 76.76.21.21 (76.76.21.21): icmp_seq=4 ttl=119 time=23.0 ms 64 bytes from 76.76.21.21 (76.76.21.21): icmp_seq=5 ttl=119 time=23.9 ms ^C --- rocketscience.gg ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4012ms rtt min/avg/max/mdev = 22.184/23.666/24.618/0.935 ms
  • 6. ping with Go // using https://github.com/go-ping/ping pinger, err := ping.NewPinger("rocketscience.gg") if err != nil { panic(err) } pinger.Count = 3 err = pinger.Run() if err != nil { panic(err) } stats := pinger.Statistics() // get send/receive/duplicate/rtt stats
  • 7. HTTP Timestamp with Go // http_server.go http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { log.Println(time.Now().UnixNano(), r.Method, r.URL.String()) w.WriteHeader(http.StatusOK) io.Copy(w, r.Body) }) http.ListenAndServe(":8080", nil) // Client > curl -d 'testing' localhost:8080 Testing // Server Logs 2022/05/23 19:41:44 1653349304362572711 POST /
  • 8. TCP Timestamp with Go // tcp_server.go ln, _ := net.Listen("tcp", ":8080") for { conn, _ := ln.Accept() go func(conn net.Conn) { log.Println(time.Now().UnixNano(), conn.RemoteAddr().String()) io.Copy(conn, conn) }(conn) } // Client > netcat localhost 8080 hi hi // Server Logs 2022/05/23 20:52:31 1653353551565391099 [::1]:53648
  • 9. UDP Timestamp with Go // udp_server.go conn, _ := net.ListenPacket("udp", ":8080") for { data := make([]byte, 1024) n, src, _ := conn.ReadFrom(data) log.Println(time.Now().UnixNano(), src.String()) conn.WriteTo(data[:n], src) } // Client > netcat -u localhost 8080 hi hi // Server Logs 2022/05/23 20:57:43 1653353863894400940 [::1]:48194
  • 10. Problems with time.Time in Go Every time you call tcpconn.(Read|Write) or udpconn.(ReadFrom|WriteTo) your Go process makes a Linux system call send or recv via the kernel so it can put the data into the NIC queue to be sent out onto or read in from the wire. These system calls and queues all take time.
  • 11. Sample Ping Sequence ■ Latency = Rx - Tx in userspace ■ Includes kernel time (green) ● Go runtime context switching ● OS context switching ■ Includes NIC queue (blue) ● Tx/Rx buffers ■ We want just wire time (orange)
  • 12. Packet Sequence with Control Messages ■ Full Latency = Rx - Tx in userspace ■ Kernel Tx: is when packet makes it into the kernel from userspace ■ NIC Tx is when the packet gets placed onto the wire (if supported by hardware) ■ Kernel Rx is when the packet enters the kernel from the NIC ■ NIC Rx is when the packet comes in from the wire into the NIC
  • 13. AF_PACKET ■ Requires we manually construct each layer of our packet and wrap our data (Layer 1, 2, 3, and 4) manually ■ The great github.com/mdlayher/socket library makes working with raw sockets very idiomatic socket, err := socket.Socket(unix.AF_PACKET, unix.SOCK_RAW, 0, "socket", nil) socket.ReadFrom(...) socket.WriteTo(...)
  • 14. Manually Creating Packet []byte ■ Use github.com/google/gopacket ■ Allows you to encode/decode packet layers l1 := layers.Ethernet{SrcMAC: smac, DstMAC: dmac EthernetType: layers.EthernetTypeIPv4} l2 := layers.IPv4{Version: 4, TTL: 64, Protocol: layers.IPProtocolUDP, SrcIP: saddr, DstIP: daddr} l3 := layers.UDP{SrcPort: layers.UDPPort(sport), DstPort: layers.UDPPort(dport)} l4 := []byte("this is my application data") pkt := gopacket.NewSerializeBuffer() gopacket.SerializeLayers(pkt, nil, l1, l2, l4, gopacket.Payload(l4)) fullpkt := pkt.Bytes() socket.Write(fullpkt)
  • 15. SO_TIMESTAMPING for Control Messages Control messages are extra information provided by the Linux kernel about the socket. Timestamp information is transmitted with these control messages using specific types. Accessing these control messages are available with Resvmsg on a socket to "receive a message" from the kernel once SO_TIMESTAMPING is enabled on the socket. https://www.kernel.org/doc/html/latest/networking/timestamping.html data := make([]byte, 1024) cmsg := make([]byte, 1024) // read incoming data from the RX queue (normally conn.Read) socket.Recvmsg(data, cmsg, 0) // read outgoing data from the TX queue (sent with conn.Write) socket.Recvmsg(data, cmg, unix.MSG_ERRQUEUE)
  • 16. Parsing the Timestamps in Control Messages Socket kernel and NIC timestamp information can be parsed from these control messages. msgs, _ := unix.ParseSocketControlMessage(cmsg) if msg.Header.Level != unix.SOL_SOCKET && msg.Header.Type != SocketOptTimestamping { return ts, fmt.Errorf("no timestamp control messages") } var ts SocketTimestamps ts.Software = time.Unix(int64(binary.LittleEndian.Uint64(msg.Data[0:])), int64(binary.LittleEndian.Uint64(msg.Data[8:]))) // kernel timestamp ts.Hardware = time.Unix(int64(binary.LittleEndian.Uint64(msg.Data[32:])), int64(binary.LittleEndian.Uint64(msg.Data[40:]))) // NIC timestamp (if supported by NIC hardware)
  • 17. Use blainsmith/fast_afpacket ■ Implements net.PacketConn ■ Sets up the AF_PACKET & SO_TIMESTAMPING options for you ■ Offer convenient RecvTxTimestamps() & RecvRxTimestamps() // create a socket and bind it directly to the interface // named eth0 and send/recv all IPv4/v6 TCP/UDP traffic! iface, _ := net.InterfaceByName("eth0") socket, _ := fastafpacket.Listen(iface, unix.SOCK_RAW, unix.ETH_P_ALL, nil)
  • 18. Packet Sender/Receiver for range ticker.C { packet, _ := encodePacket(srcmac, srcip, srcport, dstmac, dstip, dstport, data) _, _ = conn.WriteTo(packet, &fastafpacket.Addr{HardwareAddr: dstmac}) } for { packet := make([]byte, 1024) _, _, ts, _ := conn.RecvTxTimestamps(packet) log.Println(“tx”, ts.Hardware.UnixNano(), ts.Software.UnixNano()) } // tx 1652138203507654453 1652138202507654453 for { packet := make([]byte, 1024) n, _, ts, _ := conn.RecvRxTimestamps(packet) log.Println(“rx”, ts.Hardware.UnixNano(), ts.Software.UnixNano(), ts.Hardware.Sub(time.Now())) } // rx 1652138204508141040 1652138203508141040 -423.796µs
  • 19. Use Cases ■ One-way latency NIC A -> NIC B ● Asymmetric measurements ● NIC B -> NIC A might be different ■ Observability into time being spent processing packets ● in/out kernel ● in/out NIC queues ■ Wire only ● Subtract kernel and NIC timestamps from userspace timestamps ● Removes jitter introduced from context switching (both Go runtime and OS) and NIC queuing ■ Target specific NICs ● Target which NIC the packet goes out and which destination NIC on the receiving side ● Expose slow NIC queues when comparing to other NICs on the same machine
  • 20. Timestamp Delays Once we have kernel and NIC timestamp information we can calculate the delays between each of the layers. ■ tx.Software.Sub(userspaceTxTime) = outgoing kernel delay ■ tx.Hardware.Sub(userspaceTxTime) = outgoing NIC delay ■ rx.Software.Sub(userspaceRxTime) = incoming kernel delay ■ rx.Hardware.Sub(userspaceRxTime) = incoming NIC delay
  • 21. Timestamping Support ■ Kernel timestamping should be able for most, but hardware timestamps depends on NIC hardware ■ Mellanox (owned by NVIDIA) NICs have support ■ Use ethtool to check your own hardware > ethtool -T eth0 Time stamping parameters for eth0: Capabilities: hardware-transmit (SOF_TIMESTAMPING_TX_HARDWARE) software-transmit (SOF_TIMESTAMPING_TX_SOFTWARE) hardware-receive (SOF_TIMESTAMPING_RX_HARDWARE) software-receive (SOF_TIMESTAMPING_RX_SOFTWARE) software-system-clock (SOF_TIMESTAMPING_SOFTWARE) hardware-raw-clock (SOF_TIMESTAMPING_RAW_HARDWARE) PTP Hardware Clock: 0 Hardware Transmit Timestamp Modes: off (HWTSTAMP_TX_OFF) on (HWTSTAMP_TX_ON)
  • 22. Further Reading ■ AF_PACKET: https://man7.org/linux/man-pages/man7/packet.7.html ■ SO_TIMESTAMPING: https://www.kernel.org/doc/html/latest/networking/timestamping.html ■ One-way Delay: https://api.semanticscholar.org/CorpusID:5433866 ■ Clock and Time Sync: https://arxiv.org/abs/2106.16140 ■ NTP: http://www.ntp.org
  • 23. Brought to you by Blain Smith @blainsmith blainsmith.com rocketscience.gg