Why notifications matter in Jenkins - Performance Analysis
We want to understand how the time it takes to send notifications grows as we add more notifications in Jenkins.
How does the number of notifications affect the total time Jenkins spends sending them?
Analyze the time complexity of the following code snippet.
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
post {
always {
script {
def recipients = ['dev1@example.com', 'dev2@example.com', 'dev3@example.com']
for (email in recipients) {
mail to: email, subject: 'Build Notification', body: 'Build completed'
}
}
}
}
}
This pipeline sends an email notification to each recipient after the build stage finishes.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Sending an email notification inside a loop.
- How many times: Once for each recipient in the list.
As the number of recipients grows, the total time to send notifications grows proportionally.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 emails sent |
| 100 | 100 emails sent |
| 1000 | 1000 emails sent |
Pattern observation: Doubling the number of recipients doubles the work of sending emails.
Time Complexity: O(n)
This means the time to send notifications grows directly with the number of recipients.
[X] Wrong: "Sending notifications happens instantly no matter how many recipients there are."
[OK] Correct: Each notification takes time, so more recipients mean more total time spent.
Understanding how notification time grows helps you design pipelines that scale well and keep teams informed efficiently.
"What if we sent notifications in parallel instead of one by one? How would the time complexity change?"