4 ms·
An example usage from the article: $ time sleep 12 real 0m12.003s $ time ./fluxcapacitor -- sleep 12 real 0m0.057s In the author's word
by abetusk 9y ago
An example usage from the article:
$ time sleep 12
real 0m12.003s
$ time ./fluxcapacitor -- sleep 12
real 0m0.057s
In the author's words:
Fluxcapacitor is really good at speeding
up client/server or protocol tests.
Actually fluxcapacitor was originally
created to speed up the sockjs-protocol
test suite. It wasn't possible to mock
up a time library - we needed to run
the tests against any sockjs http server,
whether it's in erlang, node.js or
python. It turns out the only way to run
timeout-related tests in a reasonable
time is to use fluxcapacitor.
You might ask how fluxcapacitor works.
In short - it uses ptrace to catch
syscalls like clock_gettime or
gettimeofday and overwrite the kernel
response with a fake time.
Additionally it short-circuits
syscalls that can block for a timeout
like select or poll. For technical
details see the README.
It seems that this library might be useful to anyone needing to test communication protocols by helping tickle those edge cases that happen with timing.
- thaumaturgy 9y agoYeah, this is amazing. It allows for a whole different aspect of troubleshooting (or maybe even fuzzing?). What happens if two different pieces of software have to communicate but can't agree on the time? Is there an annoying caching bug that normally only gets triggered every few days?
- majke 9y ago(author here) That's the intention! Protocol development, protocol testing. Think - leap seconds. While we don't support having different timer for each process yet, this is easy to imagine. Also - this is somewhat similar to golang race detector in spirit - looking for explicit synchronizations. The general idea is that you should be able to run multiple processes within the thing, and that they should be able to just talk to each other freely. There are a number of "protocol simulators" out there, but I always found them academic. I wanted to build a tool that will allow me run and test and do code coverage of my code, without having to wait forever for timeouts and timers to kick in to test rare branches.
- glossbar 9y agoTry using it for consensus debugging. Like wrapping a few zookeeper or console processes with FC. Time is a fun one to debug, slips are not fun to debug in prod even though one thinks ntp is always reliable.
- Bromskloss 9y ago> it uses ptrace to catch syscalls like clock_gettime or gettimeofday and overwrite the kernel response with a fake time I would love to hear more about how this works, or get pointers to where one can learn about doing that kind of thing.
- ant6n 9y agoI'd start with this tutorial on how to write a debugger using ptrace, it's not too difficult to go to spoofing syscalls from there: https://eli.thegreenplace.net/2011/01/23/how-debuggers-work-part-1 https://eli.thegreenplace.net/2011/01/23/how-debuggers-work-...
- loeg 9y agoDoesn't 0.05s still seem like quite a long runtime for something like this? I wonder what it is doing under the hood that takes so long. For start, it seems like they hijack a bunch of clock calls with LD_PRELOAD and then redirect vdso ones to syscalls just so they can interpose with ptrace. Why not do the manipulation in the PRELOAD? I guess using the debugger API makes it easier to coordinate a bunch of processes, but you could probably do the same thing with some sort of IPC mechanism between PRELOADED targets. In the common case (single program running under FC, no IPC is needed. It's unclear to me why they force any sleep duration at all, e.g., 10ms: https://github.com/majek/fluxcapacitor/blob/master/src/main.c#L323 https://github.com/majek/fluxcapacitor/blob/master/src/main.... It seems like there is room to optimize here, if one were really inspired :-).