Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
|
|
5 years ago | |
|---|---|---|
| .. | ||
| README.md | 5 years ago | |
| semaphore.go | 5 years ago | |
concurrent utils for golang
// concurrent.semaphore
BenchmarkSemaphore(TryAcquire()&&Release()) 20000000 89.6 ns/op
BenchmarkSemaphoreConcurrent(TryAcquire()&&Release()) 20000000 89.9 ns/op
package main
import(
"fmt"
"time"
nsema "github.com/niean/gotools/concurrent/semaphore"
)
func main(){
// init sema
concurrentNum := 2 // 5,10..
sema := nsema.NewSemaphore(concurrentNum)
// use sema
for i:=0; i<100; i++ {
go func(num int){
if !sema.TryAcquire() {
fmt.Printf("%d, get sema, fail\n", num)
return
}
defer sema.Release()
time.Sleep(1*time.Nanosecond)
fmt.Printf("%d, get sema, ok\n", num)
}(i)
}
// keep alive
time.Sleep(2*time.Second)
}
TODO
类似 Grafana 可接入多种数据源,Grafana 擅长可视化,夜莺擅长告警管理
Go SQL Text Python PLSQL other