apache/beam · error · ValueError

Sleep time per input record must be at least 1e-3…

Error message

Sleep time per input record must be at least 1e-3. Received: %r

What it means

After converting the configured per-record delay from milliseconds to seconds, SyntheticSource rejects any positive sleep time smaller than 1e-3 seconds (1 ms), since sub-millisecond sleeps are not meaningful/reliable. Only 0 (disabled) or values >= 1ms are accepted.

Solutions

  1. Increase the 'const' value to at least 1 (millisecond).
  2. Set 'const' to 0 (or omit delayDistribution) to disable per-record delay.
  3. Round/quantize generated configs so delay values are 0 or >= 1 ms.

Example fix

// before
input_spec = {'delayDistribution': {'type': 'const', 'const': 0.5}}
// after
input_spec = {'delayDistribution': {'type': 'const', 'const': 1}}
Defensive patterns

Strategy: validation

Validate before calling

dd = input_spec.get('delayDistribution') or {}
const_ms = dd.get('const', 0)
if const_ms and float(const_ms) / 1000 < 1e-3:
    raise ValueError('per-record delay must be 0 or >= 1 ms')

Type guard

def is_valid_delay(dd) -> bool:
    v = dd.get('const', 0)
    return not v or float(v) / 1000 >= 1e-3

Try / catch

try:
    source = SyntheticStep(input_spec, ...)
except ValueError as e:
    if 'Sleep time per input record' in str(e):
        input_spec['delayDistribution']['const'] = max(input_spec['delayDistribution']['const'], 1)
        source = SyntheticStep(input_spec, ...)
    else:
        raise

Prevention

When it happens

Trigger: Setting input_spec['delayDistribution'] = {'type': 'const', 'const': 0.5} (0.5 ms) — the converted sleep time 0.0005 is truthy but < 1e-3, raising ValueError. A const of exactly 0 or missing key is fine.

Common situations: Trying to configure sub-millisecond simulated latency; unit confusion (passing seconds like 0.0005 where milliseconds like 5 are expected); generating configs programmatically with fractional ms values.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/bdb84d70b5e083d3. Report an issue: GitHub.

Appendix: source

Thrown at sdks/python/apache_beam/testing/synthetic_pipeline.py:392

            'Received %r.',
            self._initial_splitting_distribution_parameter)
    else:
      self._initial_splitting_distribution_parameter = 0
    self._dynamic_splitting = (
        'none' if (
            'splitPointFrequencyRecords' in input_spec and
            input_spec['splitPointFrequencyRecords'] == 0) else 'perfect')
    if 'delayDistribution' in input_spec:
      if input_spec['delayDistribution']['type'] != 'const':
        raise ValueError(
            'SyntheticSource currently only supports delay '
            'distributions of type \'const\'. Received %s.',
            input_spec['delayDistribution']['type'])
      self._sleep_per_input_record_sec = (
          float(input_spec['delayDistribution']['const']) / 1000)
      if (self._sleep_per_input_record_sec and
          self._sleep_per_input_record_sec < 1e-3):
        raise ValueError(
            'Sleep time per input record must be at least 1e-3.'
            ' Received: %r',
            self._sleep_per_input_record_sec)
    else:
      self._sleep_per_input_record_sec = 0

    # algorithm of the generator
    self.gen_algo = input_spec.get('algorithm', None)
    if self.gen_algo not in (None, 'builtin', 'lcg'):
      raise ValueError(
          'Unknown algorithm for input_spec: %s. Supported '
          'algorithms are "builtin" and "lcg".',
          self.gen_algo)

  @property
  def element_size(self):
    return self._key_size + self._value_size

View on GitHub (pinned to 12126d8942)