Giter Club home page Giter Club logo

fluxcapacitor's Introduction

Fluxcapacitor

Fluxcapacitor is a tool for Linux, originally created to speed up SockJS tests.

It is somewhat similar to tools like:

Instead of patching time libraries in high level programming language, Fluxcapacitor "patches" low-level syscalls using ptrace on Linux.

This approach has a significant advantage: now you can run more than one independent processes that will be affected by speeding up the time. This is especially useful for testing network protocols.

Basic examples

First, compile:

make

For example, these commands should finish instantly:

./fluxcapacitor --libpath=. -- sleep 1
./fluxcapacitor --libpath=. -- python -c "import time; time.sleep(1000)"

How does it work

Fluxcapacitor does two things:

  1. It forces fluxcapacitor_preload.so to be preloaded for the executed command. This library is responsible for two things:

    • It makes sure that clock_gettime will not be used by fast VDSO mechanism, but by the standard system call. (that gives us the opportunity to replace the return value of the system call later).
    • It replaces various time-related libc functions, like time() and gettimeofday() with replacements using clock_gettime underneath.
  2. It runs the command (and its forked children) in a ptrace() sandbox, capturing all the syscalls. Some syscalls - notably clock_gettime will have original results overwritten by faked values. Other syscalls, like select(), poll() and epoll_wait() can be interrupted and its return value (-EINTR) will be rewritten to suggest reaching a timeout.

When it won't work

Fluxcapacitor won't work in a number of cases:

  1. If your code is statically compiled and fluxcapacitor_preload.so can't play its role.

  2. If your code uses non file descriptors event loops, like: signalfd(), sigwait(), wait(), etc. Or if your program relies heavily on signals and things like alert(), setitimer() or timerfd_create().

Basically, for Fluxcapacitor to work all the time queries need to be done using gettimeofday() or clock_gettime() and all the waiting for timeouts must rely on select(), poll() or epoll_wait().

fluxcapacitor's People

Contributors

majek avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.