Skip to content

Add opt-out for 1ms minimum simulated sleep #259

Description

@astrobliss

Hi, I’m using madsim for queueing/load simulations where sub-millisecond sleeps are meaningful. In particular, I have a simulated open-loop client which samples exponential inter-arrival times. At rates like 500-1000 req/s, many sampled inter-arrivals are below 1ms, but madsim currently clamps every sleep/sleep_until to at least 1ms.

This behavior was added in #199 to fix #198, matching Tokio’s practical behavior for zero-duration sleeps. That makes sense as a default, but it changes simulator semantics for simulated systems that intentionally model sub-ms virtual time.

In my case, the clamp caused a relative-sleep open-loop load generator to under-offer load substantially:
configured 550 req/s -> about 488 req/s actually issued
configured 900 req/s -> about 689 req/s actually issued

Would you consider adding a feature flag or runtime config option to disable the 1ms minimum and allow simulated sleeps below 1ms?

Default behavior could remain unchanged, preserving the fix from #199, while some users could opt into higher time resolution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions