Skip to content

Feature/sticktable write support#28

Merged
fionera merged 7 commits intomasterfrom
feature/sticktable-write-support
Mar 4, 2026
Merged

Feature/sticktable write support#28
fionera merged 7 commits intomasterfrom
feature/sticktable-write-support

Conversation

@awlx
Copy link
Contributor

@awlx awlx commented Mar 3, 2026

This adds stick-table write support to the library.

I've added a few e2e tests as well:

  • one general write
  • one which writes with expiry
  • one which does a bulk update.

Performance:

=== peers Writer performance test ===
Entries: 300000 | Table: perftest_table

Building perftest binary...
3796d0dfb30d5854db428e9a154a1a9c35a86033bded256907977a4789cb58ea
Starting perftest pusher at 10.5.0.2...
Starting HAProxy at 10.5.0.13 (haproxy:alpine)...
Waiting for HAProxy...
HAProxy ready.
Table entries before: 266643

Pushing 300000 entries...
---
perftest: listening on 0.0.0.0:22001, will push 300000 entries to table "perftest_table"
perftest: waiting for 1 peer connection(s)...
perftest: peer connected: 10.5.0.13:59624 (local=local-perftest)
perftest: 1 peer(s) connected, starting push of 300000 entries...
perftest: peer 0: pushed 50000/300000 entries (1541528 entries/s, 32ms elapsed)
perftest: peer 0: pushed 100000/300000 entries (1113436 entries/s, 90ms elapsed)
perftest: peer 0: pushed 150000/300000 entries (1205078 entries/s, 124ms elapsed)
perftest: peer 0: pushed 200000/300000 entries (1255861 entries/s, 159ms elapsed)
perftest: peer 0: pushed 250000/300000 entries (1151428 entries/s, 217ms elapsed)
perftest: peer 0: pushed 300000/300000 entries (1048966 entries/s, 286ms elapsed)

=== Results ===
Entries per peer:  300000
Peers:             1
Total entries:     300000
Wall time:         286ms
Rate (per peer):   1048866 entries/s
Rate (total):      1048866 entries/s

perftest: waiting 60s for HAProxy to process entries (connection stays alive)...
---

Polling HAProxy table count...
  poll 1/30: 300000 entries
  poll 2/30: 300000 entries
  poll 3/30: 300000 entries
  poll 4/30: 300000 entries

Table entries after: 300000
✅ All 300000 entries present in HAProxy

=== Done ===
Cleaning up...
perftest-haproxy
perftest-pusher
perftest-net

awlx added 2 commits March 3, 2026 15:24
This adds stick-table writing to the library.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds stick-table write/push support to the peers library so handlers can send stick-table definitions and entry updates back to HAProxy over the existing peer connection, with accompanying unit + e2e coverage and a usage example.

Changes:

  • Introduce peers.Writer and expose it via WriterFromContext(ctx) for pushing stick-table updates.
  • Fix stick-table entry marshaling to encode map data correctly when sending updates.
  • Add unit tests, e2e tests, and a runnable example demonstrating pushing entries (including timed/expiry and bulk).

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
peers/writer.go New writer implementation to send stick-table protocol messages.
peers/peers.go Injects Writer into handler context via a new context key.
peers/sticktable/sticktables.go Fixes entry marshaling to call MapData.Marshal (write path).
peers/protocol.go Accepts update-ack messages silently (needed when pushing to HAProxy).
peers/writer_test.go Adds writer-focused tests plus a round-trip decode test.
peers/e2e_test.go Adds e2e coverage for pushing entries, timed expiry, and bulk updates.
peers/example/push/main.go New example showing how to push stick-table entries from a handler.
peers/example/push/go.mod Example module wiring (replace to local repo).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

awlx added 4 commits March 3, 2026 15:35
- Handle short writes in Writer.writeMessage with a write loop
- Share write mutex between Writer and protocolClient to prevent interleaved frames
- Fix SendEntry to not mutate caller's EntryUpdate and protect ID assignment
- Use bufio.Reader in helperDialPeer for reliable TCP status line reading
- Fix push example to use IPv4AddressKey instead of StringKey for IP tables
- Wrap the connection in a 64KB bufio.Writer to reduce syscalls
- Reuse a scratch buffer on the Writer instead of allocating per message
- Add Flush() method for explicit flush control
- Add SendEntries() for batch writes with a single lock and flush
- SendEntry() auto-flushes for backward compat
- Update protocolGilantClient to share the buffered writer
@fionera fionera merged commit 2865f3f into master Mar 4, 2026
4 checks passed
@fionera fionera deleted the feature/sticktable-write-support branch March 4, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants