Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] introduce the virtual clock for simulations #407

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cskiraly
Copy link

This allows running code written for Chronos using
-d:asyncTimer=virtual
, turning it into a simple event-based simulation.

Used in codex-storage/nim-codex-dht#57

This allows running code written for Chronos using
`-d:asyncTimer=virtual`
, turning it into a simple event-based simulation.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
@cheatfate
Copy link
Collaborator

Could you please add more explanation to this topic?

@cskiraly
Copy link
Author

cskiraly commented Jul 7, 2023

I use this virtual timer for testing performance in https://github.com/codex-storage/das-dht-emulator, using UDP only.

The problem it solves for me is the CPU bottleneck when emulating many instances of a process on a single machine.

Normally, CPU gets bottlenecked, and you can't keep up with real time clock. If you use this timer, all CPU operations become 0 virtual time, and thus you can focus on delays and timeouts set up in the event loop. Of course there are more sophisticated approaches, but it achieves what I need with a simple patch, and mostly without modifications to the code on top.

Previous version of virtual timer used minimal modifications.
This one instead implements poll() directly, simplifying execution.
It also enforces one timer each poll, which makes it compatible with
one network even per poll cycle when network events are replaced by
timers for simulation.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
@cskiraly
Copy link
Author

@cheatfate I have largely simplified the code. Purpose is still the same: to run simulations without code change.

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.

None yet

2 participants