本文整理匯總了Golang中sync/atomic.LoadInt64函數的典型用法代碼示例。如果您正苦於以下問題:Golang LoadInt64函數的具體用法?Golang LoadInt64怎麽用?Golang LoadInt64使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了LoadInt64函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: IsReadyForMessages
func (c *ClientV2) IsReadyForMessages() bool {
if c.Channel.IsPaused() {
return false
}
readyCount := atomic.LoadInt64(&c.ReadyCount)
errCnt := atomic.LoadInt64(&c.subErrCnt)
if errCnt > 3 {
// slow down this client if has some error
readyCount = 1
}
inFlightCount := atomic.LoadInt64(&c.InFlightCount)
deferCnt := atomic.LoadInt64(&c.DeferredCount)
if nsqLog.Level() > 1 {
nsqLog.LogDebugf("[%s] state rdy: %4d inflt: %4d, errCnt: %d",
c, readyCount, inFlightCount, errCnt)
}
// deferCnt should consider as not in flight
if inFlightCount >= readyCount+deferCnt || readyCount <= 0 {
return false
}
if deferCnt > readyCount*100 || deferCnt > 1000 {
nsqLog.Infof("[%s] too much deferred message : %v rdy: %4d inflt: %4d",
c, deferCnt, readyCount, inFlightCount)
return false
}
return true
}
示例2: logThrottling
// logThrottling handles logging of throttled events and has to be started as a
// goroutine. It stops once s.loopStopping is closed.
//
// Logging strategy: Whenever Throttle() is called and returns true, an signal
// is sent to s.throttled. If that happens for the first time, an Error is
// logged that the storage is now throttled. As long as signals continues to be
// sent via s.throttled at least once per minute, nothing else is logged. Once
// no signal has arrived for a minute, an Info is logged that the storage is not
// throttled anymore. This resets things to the initial state, i.e. once a
// signal arrives again, the Error will be logged again.
func (s *memorySeriesStorage) logThrottling() {
timer := time.NewTimer(time.Minute)
timer.Stop()
// Signal exit of the goroutine. Currently only needed by test code.
defer close(s.logThrottlingStopped)
for {
select {
case <-s.throttled:
if !timer.Reset(time.Minute) {
log.
With("chunksToPersist", s.getNumChunksToPersist()).
With("maxChunksToPersist", s.maxChunksToPersist).
With("memoryChunks", atomic.LoadInt64(&numMemChunks)).
With("maxToleratedMemChunks", int(float64(s.maxMemoryChunks)*toleranceFactorMemChunks)).
Error("Storage needs throttling. Scrapes and rule evaluations will be skipped.")
}
case <-timer.C:
log.
With("chunksToPersist", s.getNumChunksToPersist()).
With("maxChunksToPersist", s.maxChunksToPersist).
With("memoryChunks", atomic.LoadInt64(&numMemChunks)).
With("maxToleratedMemChunks", int(float64(s.maxMemoryChunks)*toleranceFactorMemChunks)).
Info("Storage does not need throttling anymore.")
case <-s.loopStopping:
return
}
}
}
示例3: ReportMsg
func (k *KafkaInput) ReportMsg(msg *message.Message) error {
message.NewInt64Field(msg, "ProcessMessageCount",
atomic.LoadInt64(&k.processMessageCount), "count")
message.NewInt64Field(msg, "ProcessMessageFailures",
atomic.LoadInt64(&k.processMessageFailures), "count")
return nil
}
示例4: Stats
// Stats returns current aggregate statistics about an ongoing or completed run.
// It is safe to call from concurrent goroutines.
func (f *Fetcher) Stats() FetcherStats {
return FetcherStats{
ItemsRead: atomic.LoadInt64(&f.itemsRead),
BytesRead: atomic.LoadInt64(&f.bytesRead),
CapacityUsed: float64(atomic.LoadInt64(&f.capacityUsed)) / 10,
}
}
示例5: GetServerStatus
// GetServerStatus represents a tracker status request
func GetServerStatus() ServerStatus {
// Get system hostname
hostname, _ := os.Hostname()
// Get current memory profile
mem := &runtime.MemStats{}
runtime.ReadMemStats(mem)
// Report memory usage in MB
memMb := float64((float64(mem.Alloc) / 1000) / 1000)
// Build status struct
status := ServerStatus{
os.Getpid(),
hostname,
runtime.GOOS,
runtime.GOARCH,
runtime.NumCPU(),
runtime.NumGoroutine(),
memMb,
atomic.LoadInt64(&Static.HTTP.Total),
atomic.LoadInt64(&Static.HTTP.Current),
}
// Return status struct
return status
}
示例6: statusHandler
func statusHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
http.Error(w, "Method Not Allowed", 405)
return
}
stat := statusInfo{
AppStartTime: startTime,
Connections: getLoginCount(),
Querys: getQueryCount(false),
QuerysPerSec: atomic.LoadInt64(&querysPerSec),
Recvs: getRecvCount(false),
RecvsPerSec: atomic.LoadInt64(&recvsPerSec),
ConnConfig: int64(_Count),
ConnStepOn: int64(atomic.LoadInt64(&connIndex)),
Communicating: 1 == atomic.LoadInt32(&allGo),
}
body, err := json.MarshalIndent(stat, "", "\t")
if err != nil {
glog.Errorf("Failed to Marshal, content: %v, error: %v\n", stat, err)
w.WriteHeader(500)
return
}
w.Header().Add("Content-Type", "application/json;charset=UTF-8")
if _, err := w.Write(body); err != nil {
glog.Errorf("w.Write(\"%s\") error(%v)\n", string(body), err)
}
}
示例7: Ticks
// returns ticks of current and previous seconds
func (t *QpsTracker) Ticks() (c1, e1, c2, e2 int32) {
c1 = atomic.LoadInt32(&t.c[int((atomic.LoadInt64(&t.active)+int64(1))%2)])
e1 = atomic.LoadInt32(&t.e[int((atomic.LoadInt64(&t.active)+int64(1))%2)])
c2 = atomic.LoadInt32(&t.c[int((atomic.LoadInt64(&t.active))%2)])
e2 = atomic.LoadInt32(&t.e[int((atomic.LoadInt64(&t.active))%2)])
return
}
示例8: gcRunner
//
// for test only, run GC for profile GC in huge map
func (eng *Engine) gcRunner(interval int) {
tk := time.NewTicker(time.Duration(interval) * time.Second)
defer tk.Stop()
var pre, cnt int64
var iopre, iocnt int64
var rwpre, rwcnt int64
var norepeatgc bool
for {
//
cnt = atomic.LoadInt64(eng.aliveCount)
iocnt = atomic.LoadInt64(eng.newCount)
rwcnt = atomic.LoadInt64(eng.rwCount)
if cnt > 0 {
if eng.conf.gctest && (pre != cnt || iopre != iocnt || rwpre != rwcnt) {
fmt.Printf("GC with %d connections.\n", cnt)
runtime.GC()
//fmt.Printf("GC done.\n")
pre = cnt
}
norepeatgc = false
} else if norepeatgc == false {
// even if eng.conf.gctest == false, still call FreeOSMemory when connections == 0
norepeatgc = true
fmt.Printf("FreeOSMemory with %d connections.\n", cnt)
// free memory
debug.FreeOSMemory()
//fmt.Printf("FreeOSMemory done.\n")
pre = cnt
}
<-tk.C
}
}
示例9: tryWithTimeout
func (r *Retryable) tryWithTimeout() error {
errors := &multierror.Error{}
errChan := make(chan error, r.maxAttemptTimes)
timer := time.NewTimer(r.maxDelay)
count := r.maxAttemptTimes
go func() {
for atomic.LoadInt64(&count) > 0 {
atomic.AddInt64(&count, -1)
errChan <- r.f()
r.wait()
}
}()
for {
select {
case err := <-errChan:
errors = multierror.Append(errors, err)
if err == nil {
atomic.StoreInt64(&count, 0)
return nil
}
if atomic.LoadInt64(&count) <= 0 {
return errors.ErrorOrNil()
}
case <-timer.C:
return ErrTimeout
}
}
}
示例10: Accepted
// Accepted checks if query at this moment should be accepted or rejected.
// If accepted, the EMA rate limiter updates its current EMA
func (e *emaRateLimiter) Accepted() bool {
now := time.Now().UnixNano()
instWaiting := now - atomic.LoadInt64(&e.timeOfLastRequest)
for {
avgWaitingNs := atomic.LoadInt64(&e.avgWaitingNs)
newavgWaitingNs := int64((1.-wq)*float64(avgWaitingNs) + wq*float64(instWaiting))
// glog.V(3).Infof("avgWaitingNs %d newavgWaitingNs %d", avgWaitingNs, newavgWaitingNs)
if newavgWaitingNs < e.targetWaitingNs {
atomic.AddInt64(&e.requestThrottledCount, 1)
return false
}
// if(pendingRequests.size()>maxPendingQueueLength) {
// pendingTooLongDiscarded.incrementAndGet();
// return false;
// }
atomic.StoreInt64(&e.timeOfLastRequest, now)
newavgWaitingNs2 := newavgWaitingNs
if !atomic.CompareAndSwapInt64(&e.avgWaitingNs, avgWaitingNs, newavgWaitingNs) {
continue
}
if newavgWaitingNs2 < e.minWaitingNs {
e.minWaitingNs = newavgWaitingNs2
}
atomic.AddInt64(&e.requestAcceptedCount, 1)
break
}
return true
}
示例11: TryGet
// Get will return the next available resource. If none is available, and capacity
// has not been reached, it will create a new one using the factory. Otherwise,
// it will return nil with no error.
func (self *RoundRobin) TryGet() (resource Resource, err error) {
self.mu.RLock()
defer self.mu.RUnlock()
idleTimeout := time.Duration(atomic.LoadInt64(&self.idleTimeout))
for {
select {
case fw := <-self.resources:
if idleTimeout > 0 && fw.timeUsed.Add(idleTimeout).Sub(time.Now()) < 0 {
fw.resource.Close()
atomic.AddInt64(&self.size, -1)
continue
}
return fw.resource, nil
default:
if atomic.LoadInt64(&self.size) >= int64(cap(self.resources)) {
return nil, nil
}
// Prevent thundering herd: optimistically increment
// size before creating resource
atomic.AddInt64(&self.size, 1)
if resource, err = self.factory(); err != nil {
atomic.AddInt64(&self.size, -1)
}
return resource, err
}
}
panic("unreachable")
}
示例12: GetTok
// request a token; returns true if token obtained, false otherwise
func (tbq *TBucketQ) GetTok() bool {
// attempt to obtain token from bucket
for {
if toks := atomic.LoadInt64(&tbq.tokens); toks > 0 {
if atomic.CompareAndSwapInt64(&tbq.tokens, toks, toks-1) {
return true
}
continue
}
break
}
// no tokens in the bucket, attempt to get on the queue
var done bool
for !done {
if qcnt := atomic.LoadInt64(&tbq.qcnt); qcnt < tbq.maxq {
done = atomic.CompareAndSwapInt64(&tbq.qcnt, qcnt, qcnt+1)
} else {
// queue is full, return false
return false
}
}
// on queue, wait until token received
<-tbq.qch
return true
}
示例13: ReportMsg
func (input *S3OffsetInput) ReportMsg(msg *message.Message) error {
message.NewInt64Field(msg, "ProcessMessageCount", atomic.LoadInt64(&input.processMessageCount), "count")
message.NewInt64Field(msg, "ProcessMessageFailures", atomic.LoadInt64(&input.processMessageFailures), "count")
message.NewInt64Field(msg, "ProcessMessageBytes", atomic.LoadInt64(&input.processMessageBytes), "B")
return nil
}
示例14: getStatus
func getStatus(w http.ResponseWriter, r *http.Request) {
status := make(map[string]interface{})
sessionMut.Lock()
status["numSessions"] = len(sessions)
sessionMut.Unlock()
status["numConnections"] = atomic.LoadInt64(&numConnections)
status["numProxies"] = atomic.LoadInt64(&numProxies)
status["bytesProxied"] = atomic.LoadInt64(&bytesProxied)
status["goVersion"] = runtime.Version()
status["goOS"] = runtime.GOOS
status["goAarch"] = runtime.GOARCH
status["goMaxProcs"] = runtime.GOMAXPROCS(-1)
status["kbps10s1m5m15m30m60m"] = []int64{
rc.rate(10/10) * 8 / 1000,
rc.rate(60/10) * 8 / 1000,
rc.rate(5*60/10) * 8 / 1000,
rc.rate(15*60/10) * 8 / 1000,
rc.rate(30*60/10) * 8 / 1000,
rc.rate(60*60/10) * 8 / 1000,
}
bs, err := json.MarshalIndent(status, "", " ")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(bs)
}
示例15: stat
func (eng *Engine) stat() {
tk := time.NewTicker(time.Duration(eng.conf.interval) * time.Second)
defer tk.Stop()
var preTs = time.Now()
var pre, cnt int64
var iopre, iocnt int64
var rwpre, rwcnt int64
for {
<-tk.C
//
cnt = atomic.LoadInt64(eng.aliveCount)
iocnt = atomic.LoadInt64(eng.newCount)
rwcnt = atomic.LoadInt64(eng.rwCount)
if pre != cnt || iopre != iocnt || rwpre != rwcnt {
//
esp := time.Now().Sub(preTs)
if esp <= 0 {
esp = 1
}
qps := float64((cnt-pre)*int64(time.Second)) / float64(esp)
ioqps := float64((iocnt-iopre)*int64(time.Second)) / float64(esp)
rwqps := float64((rwcnt-rwpre)*int64(time.Second)) / float64(esp)
fmt.Printf("concurrent %d/%d, esp %v, connection change %f/s, new connection %f/s, read-write %f/s.\n", cnt, eng.conf.maxConcurrent, esp, qps, ioqps, rwqps)
pre = cnt
iopre = iocnt
rwpre = rwcnt
preTs = time.Now()
}
}
}