nim-chronos icon indicating copy to clipboard operation
nim-chronos copied to clipboard

[WIP] introduce the virtual clock for simulations

Open cskiraly opened this issue 2 years ago • 3 comments

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

Used in https://github.com/codex-storage/nim-libp2p-dht/pull/57

cskiraly avatar Jun 12 '23 08:06 cskiraly

Could you please add more explanation to this topic?

cheatfate avatar Jun 12 '23 08:06 cheatfate

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.

cskiraly avatar Jul 07 '23 11:07 cskiraly

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

cskiraly avatar Aug 23 '23 09:08 cskiraly