Devlog #1: Writing fake traffic generator
TL;DR: Wrote a fake event generator for normal events, still need to do it for DNS and connections. Had trouble with
time.sleep()
Goal for this session
Write a bigger part of fake event generator
What I did
- Wrote helper functions for queueing, making states of processes and making packets from states
- Wrote a function that using them all adds packets to queue
- Implemented the burst functionality into it
Problems I hit
The output was not smooth. During 5 seconds it was sometimes generating much less packets than expected. It was because time.sleep(0.01) is not exactly 0.01s but at least 0.01s.
Fix:
measure the real time since the last iteration dt and scale by it, so the packet count follows real time, not loop speed. The fractional part is handled with a random coin flip, since I can’t send 0.033 of a packet:
expected = state["rate"] * mult * dt
n = int(expected)
if random.random() < (expected - n):
n = n + 1
for _ in range(n):
put(q, make_packet(name, prof, state))
What I learned
- That time.sleep can’t be trusted
- What threading is
- What queues are
Next up
- Add DNS and connection events to this
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.