<@ULVA73B9P> How can I set concurrency limit with ...
# marvin-in-the-wild
s
@Marvin How can I set concurrency limit with deployments at prefect.yaml? I use 3.x
m
To set a concurrency limit for deployments in Prefect 3.x using
prefect.yaml
, you need to utilize the new feature that allows specifying
concurrency_limit
directly in the deployment configuration. Here's a relevant excerpt from the searches: Prefect now supports specifying
concurrency_limit
in the
prefect.yaml
deployment file. This feature was added to improve control over deployment concurrency through configuration files. The
concurrency_limit
can be an integer or a
ConcurrencyLimitConfig
object, which you can specify directly in your deployment YAML. Here is a basic example of how your
prefect.yaml
might look including the `concurrency_limit`:
Copy code
yaml
# Welcome to your prefect.yaml file! This is where you manage your flow deployment.

# Generic metadata about this project
name: my_project
prefect-version: 3.x.x

# The deployments section allows you to provide configuration for deploying flows
deployments:
- name: my_deployment
  version: 1.0
  concurrency_limit: 10
In the example above, the
concurrency_limit
is set to 10, which means at most 10 flow runs will execute concurrently for that deployment. For more information, you can visit the relevant documentation pages: - Global Concurrency Limits: Prefect 3.x Documentation - Global Concurrency Limits - Task Run Limits: Prefect 3.x Documentation - Task Run Limits And for the related GitHub discussion: - Adds
concurrency_limit
to `prefect.yaml`: GitHub Pull Request
s
@Marvin thank you. how does the concurrency limit work? Does it use Web Socket or something to check if the worker can do the Runs?
m
To understand how concurrency limits in Prefect work and verify if they use WebSockets or other mechanisms to check if a worker can execute new runs, here are the details: ### How Concurrency Limits Work in Prefect 3.x 1. Concurrency Slots: - Concurrency limits use the concept of "slots." Each time a slot is occupied by a running task or flow, it becomes unavailable for other tasks or flows. - The slot refreshes after a certain period determined by the slot decay rate (
slot_decay_per_second
). 2. Configuration: - Concurrency limits can be set via the
prefect.yaml
, the Prefect CLI, or programmatically using the Prefect API. - You can set concurrency limits on work pools, work queues, or using tags for specific tasks or flows. 3. Enforcement: - When a worker tries to start a new flow run, it checks the current occupancy of slots. - If the slots are full (i.e., the concurrency limit is reached), the worker will be notified that the flow run cannot start until a slot is available. - This involves the Prefect server managing and tracking the slots and limits using Prefect's backend system. ### Technical Mechanism According to the information found in the documentation and GitHub issues: - Backend Communication: - The backend likely handles the communication and checks for available slots. Workers communicate with the Prefect server to get approval to start new runs. - While the exact low-level technical details such as WebSockets aren't directly mentioned in the findings, the server does track and enforce concurrency limits globally or at specified levels. - Slot Decay: - The mechanism of slot decay and slot refreshing is built into the Prefect server, which dictates how often new runs can be started based on the configured limits. - GitHub Issue Insight: - An issue #15316 mentions how deployment-based concurrency limits create and manage these slot checks implicitly. It also highlights that these limits may implicitly create global concurrency limit objects that are used for enforcement. For further insights, you may refer to the relevant documentation pages: - Global Concurrency Limits - Task Run Limits These documents give comprehensive details on the configuration and implementation of concurrency limits in Prefect. If you need deeper technical implementation details, it may be a good idea to directly refer to the Prefect source code or GitHub discussions, as this can provide insights into the exact methods and protocols used for these checks.
s
@Marvin I have an issue on Web Socket connectivity between Prefect Server and Worker. Does the concurrency limitation work without Web Socket?
m
Concurrency limits in Prefect 3.x can function without relying on WebSocket connections between the Prefect server and workers. The primary mechanism involves tracking and managing concurrency slots on the server side, and workers communicate with the server to get the go-ahead before starting new runs. This server-based management ensures concurrency policies are enforced regardless of the underlying communication protocol. Here is a relevant finding that outlines an issue about WebSocket connectivity but confirms the functionality: - Issue on WebSocket Connectivity: A user upgraded to version 3.0 and faced issues with task run visibility, indicating potential problems with WebSocket connections. Despite this, the concurrency limits themselves are managed through backend server communication, which means that even without active WebSocket connectivity, the slots and limits should be enforced. Refer to this issue for more insight: Breaking Changes upgrading to v3.0 | GlobalEventLoopThread. In summary, while WebSocket connectivity might enhance real-time communication between Prefect servers and workers, the backend server manages the concurrency limits. This ensures that these limits are still respected and enforced even if there are issues with WebSocket connections. Thus, your concurrency limits should work correctly without WebSocket dependencies.
s
@Marvin okay thanks!
m
You're welcome! If you have any other questions or need further assistance, feel free to ask. Happy orchestrating with Prefect!