# How do I model handling times with an occasional very long one?

Manual work is usually quick, with now and then a job that takes far longer. A lognormal service time has that shape. The script below runs the same packing queue twice, once with a lognormal time and once with a constant of the same mean.

```python
import math

from nagasim import build as nb


def wait_with(service):
    m = nb.Model(time_limit=480, warmup=0)
    m.add_resource(name="Packer")
    arrive = m.create(distribution=nb.Exponential(rate=0.5))
    arrive >> m.process(resource_name="Packer", distribution=service) >> m.dispose()
    return m.run(replications=20, seed=1).kpi("resource/Packer/Time in Queue Avg")


# mu and sigma belong to the underlying normal, so the mean is exp(mu + sigma^2 / 2).
mu, sigma = 0.1, 0.8
mean = math.exp(mu + sigma ** 2 / 2)
print(f"lognormal(mu={mu}, sigma={sigma}) has mean {mean:.2f} minutes")
print(f"lognormal service: mean wait {wait_with(nb.Lognormal(mu=mu, sigma=sigma)):.2f} minutes")
print(f"constant service:  mean wait {wait_with(nb.Constant(value=mean)):.2f} minutes")

```

Save it as `recipe-lognormal-tail.py` and run it with `python`. The script seeds itself, so the numbers below are the same on your machine.

```text
lognormal(mu=0.1, sigma=0.8) has mean 1.52 minutes
lognormal service: mean wait 3.72 minutes
constant service:  mean wait 2.23 minutes

```

## How it works

1. `Lognormal(mu, sigma)` takes the mean and spread of the logarithm of the time, so its own mean is `exp(mu + sigma^2 / 2)`.
2. Both services average 1.52 minutes, but the lognormal queue waits longer, because the long jobs hold the packer while others line up.
3. Use it when your data are positive and right-skewed; the [fit recipe](../../goals/fit-input-distributions.md) shows how to test that.

## Elements used

- Distributions: [Lognormal](../../reference/distributions/lognormal.md), [Exponential](../../reference/distributions/exponential.md), [Constant](../../reference/distributions/constant.md).
- Blocks: [CREATE](../../reference/blocks/create.md), [PROCESS](../../reference/blocks/process.md), [DISPOSE](../../reference/blocks/dispose.md).
- Python: [`Model`](../../reference/api/Model.md).

Back to all [recipes](index.md).
