Little’s law

Johannes Hoff, November 2017

Little’s law is a very simple formula from queuing theory that you might already have used when playing Factorio, although perhaps without knowing its name or even think that it would be worthy of calling a «law». It gets more interesting when you use it for averages.

Little’s law is

where

Basic example

You might have used this equation without the average part to find the number of electric furnaces needed to fill a regular transport belt with copper plates. In this case, «the system» can be the ore that’s currently being smelted. We don’t consider anything outside of the system (e.g. inserters, the buffered copper ore, etc).

If we want to fill a transport belt, the throughput out of the system has to be 13.33 units/second. The throughput into the system is the same since one copper ore becomes one copper plate. So in this case .

We can find the smelting rate in the factorio wiki to be 0.57/sec. We need the wait time (smelting time), which is the inverse of that: .

Now we can solve for to get

Since we can’t build a third of a furnace, we’ll just round up to 24 furnaces. With that, you should be able to saturate a transport belt. If that doesn’t work, the problem is not the number of furnaces, but the fact that the system is not supplied with ore fast enough or plates are not extracted fast enough.

copper production

Averages

In the previous example we didn’t use the «average» part of Little’s law¹. This can come in handy when talking about bigger system. An example of this is when we’re transporting goods from one base to another with trains. Let’s say we want to fill a transport belt with electronic circuits in the receiving base. Is it possible? How many cargo wagons do we need? How long can the trip be?

Obviously, to fill a transport belt in the receiving base, we need to continuously fill one in the sending base. And since the train won’t be at the station at all times, we need chests for buffering so the belt can continue to deliver at 13.33/s.

The rate at which electronic circuits arrive to our buffers is 13.33/s. The rate at which they are loaded onto the train is different. If the train is away, the rate is 0. If the train is at the station, it’s considerably higher. However, we don’t need to calculate the exact rate when the train is at the station. We can instead use the average rate in Little’s law, and that will also be 13.33/s.

The system we will consider starts and end with the train and train tracks, so we only care that somehow the train can be supplied at this rate.

train input is 13.33 per second

The same calculations hold true for the receiving side.

train output is 13.33 per second

A prerequisite for using Little’s law, is that the system must be stable. The opposite would in this case be if electronic circuits stopped flowing in at 13.33/s or if the chests filled up. This would happen if for example the train couldn’t get rid of items fast enough. Let’s assume it’s stable for now.

Now, to save a lot of math work, I’m just going to use a stopwatch to see how long the train takes to do one round of the system. It doesn’t matter exactly where I start and stop the timing; it should all be the same. Measuring the time from leaving the receiving station once to leaving the same station next time takes 45 seconds. This is our average wait time . Specifically, it’s the average wait time for each item in the train. To convince yourself, imagine that the first item to be loaded on the train is also the first one to be unloaded. In that case, the wait time is the same for all items, 45 seconds.

train round takes 45 seconds

Now we can calculate the number of items in the system:

So for a stable system that fills a transport belt with electronic units, we need to fill the cargo wagon with 599 units. Since the stack size is 200, that means 3 slots in the wagon should be enough. However, it doesn’t hurt to have more, it just means a larger buffer (and better resiliency should the train have to yield for another train, making the time longer).

Another approach we could take would be to find the maximum loop time with a full cargo wagon. A cargo wagon holds 40 stacks, so units. For a stable system, that wait time would be

That is 600 seconds, or 10 minutes! That’s a pretty large base.

We could also see how many transport belts, , we could fill given the 45 second travel time above () and a full cargo wagon (). The throughput will be .

So at most 13 transport belts could be filled with this setup.

Conclusion

Hopefully this shows you that what you’ve probably used before goes under the name of Little’s law, and that it can be extended to averages over time for stable systems.

Let me know what you think on reddit or twitter.