Parallelism

Parallelism is the number of parallel instances in which Flink runs the tasks of a job. A higher parallelism can process more data per second, and it uses more slots.

In a Flink job, the work is split into parallel instances. You set the parallelism of a SQL job in the job settings, in Job Parallelism (threads). Each parallel instance uses a slot in the Flink cluster. Start with a low value and raise it over time if the job cannot keep up with the input rate.

Maximum parallelism

The maximum parallelism sets the number of key groups into which Flink divides the keyed state. A key group is a partition of the state of an operator. The number of key groups determines how data is distributed among the parallel instances. If the key groups are not distributed evenly, the data distribution is uneven.

Consider the following when you set the maximum parallelism:

  • The number must be large enough for the load increases that you expect. You cannot change it without starting from an empty state.
  • If P is the parallelism of the job, use a maximum parallelism that is divisible by P, to distribute state evenly.
  • A larger maximum parallelism costs more on the state backend side. For large production jobs, measure the size of the state before you change it.

Choose a number with many divisors, such as 120, 180, 240, 360, 720, 840, or 1260. This makes it easier to tune the parallelism later.

Parallelism and savepoints

When a job restores state from a savepoint, Flink redistributes the key groups among the new number of parallel instances. You can change the parallelism of a job between runs, as long as it does not exceed the maximum parallelism that the state was created with.

Reference values

The following table lists the approximate throughput for each parallel instance:

Table 1. Approximate throughput for each parallel instance
Stateless In-memory state RocksDB state
1 million records per second per core 100,000 records per second per core 10,000 records per second per core