-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
|
||
"github.com/eclipse/paho.golang/autopaho" | ||
) | ||
|
||
func main() { | ||
// used to calculate the number of iterations | ||
const interationBase = 1 | ||
|
||
backoffStrategy := autopaho.DefaultExponentialBackoffStrategy() | ||
|
||
backoff := backoffStrategy.Backoff() | ||
|
||
minBackoff := int64(math.MaxInt64) | ||
maxBackoff := int64(0) | ||
iterationsTotal := 0 | ||
for i := 0; i < 22; i++ { | ||
iterations := interationBase << i | ||
for j := 0; j < iterations; j++ { | ||
backoffTime := backoff.Next().Milliseconds() | ||
if backoffTime < minBackoff { | ||
minBackoff = backoffTime | ||
} | ||
if backoffTime > maxBackoff { | ||
maxBackoff = backoffTime | ||
} | ||
} | ||
iterationsTotal += iterations | ||
|
||
fmt.Printf("After % 8d iterations, min: %d, max: % 7d\n", iterationsTotal, minBackoff, maxBackoff) | ||
} | ||
} |