https://github.com/copyleftdev/randexc
A Go library for executing actions at random times within specified durations. Perfect for load testing, simulating real-world events, and implementing jittered backoff strategies.
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (8.3%) to scientific vocabulary
Keywords
Repository
A Go library for executing actions at random times within specified durations. Perfect for load testing, simulating real-world events, and implementing jittered backoff strategies.
Basic Info
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
randexc: Random Execution Library for Go
randexc is a powerful and flexible Go library for executing actions at random times within a specified duration. It provides both synchronous and asynchronous execution options, making it suitable for a wide range of applications including load testing, simulating real-world events, and implementing sophisticated retry mechanisms.
Features
- 🕒 Execute actions within a random time frame
- 🔄 Support for both synchronous and asynchronous execution
- 🛠 Configurable through functional options
- 🧪 Easy to test with custom random sources
- 📦 Lightweight with no external dependencies
Installation
bash
go get github.com/copyleftdev/randexc
Quick Start
```go package main
import ( "context" "fmt" "log"
"github.com/copyleftdev/randexc/pkg/randexc"
)
func main() { executor, err := randexc.New("1m") if err != nil { log.Fatalf("Failed to create executor: %v", err) }
err = executor.Execute(context.Background(), func() error {
fmt.Println("Action executed at a random time within 1 minute!")
return nil
})
if err != nil {
log.Printf("Execution failed: %v", err)
}
} ```
Use Cases
Load Testing
Simulate realistic user behavior in load tests by executing actions at random intervals:
```go func performRequest() error { // Simulate HTTP request time.Sleep(100 * time.Millisecond) return nil }
executor, _ := randexc.New("5s")
for i := 0; i < 100; i++ { go func() { err := executor.Execute(context.Background(), performRequest) if err != nil { log.Printf("Request failed: %v", err) } }() } ```
Jittered Exponential Backoff
Implement a jittered exponential backoff strategy for retrying operations:
```go func retryWithBackoff(operation func() error) error { baseDelay := 100 * time.Millisecond maxDelay := 10 * time.Second maxAttempts := 5
for attempt := 0; attempt < maxAttempts; attempt++ {
jitteredDelay := time.Duration(float64(baseDelay) * (1 + rand.Float64()))
if jitteredDelay > maxDelay {
jitteredDelay = maxDelay
}
executor, _ := randexc.New(jitteredDelay.String())
err := executor.Execute(context.Background(), operation)
if err == nil {
return nil
}
baseDelay *= 2
}
return fmt.Errorf("operation failed after %d attempts", maxAttempts)
} ```
Simulating Real-world Events
Create more realistic simulations by introducing randomness in event timing:
```go func simulateIoTDevice(deviceID string) { executor, _ := randexc.New("1h")
for {
executor.Execute(context.Background(), func() error {
temperature := 20 + rand.Float64()*10
humidity := 30 + rand.Float64()*20
fmt.Printf("Device %s: Temp: %.2f°C, Humidity: %.2f%%\n", deviceID, temperature, humidity)
return nil
})
}
}
// Simulate multiple IoT devices for i := 0; i < 5; i++ { go simulateIoTDevice(fmt.Sprintf("device_%d", i)) } ```
Documentation
For more detailed documentation and advanced usage examples, please see the usage guide.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Owner
- Name: Donald Johnson
- Login: copyleftdev
- Kind: user
- Location: Los Angeles
- Repositories: 39
- Profile: https://github.com/copyleftdev
GitHub Events
Total
- Watch event: 1
Last Year
- Watch event: 1
Issues and Pull Requests
Last synced: 12 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- actions/checkout v4 composite
- actions/setup-go v4 composite