当前位置: 首页>>代码示例>>Golang>>正文


Golang atomic.LoadInt64函数代码示例

本文整理汇总了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
}
开发者ID:absolute8511,项目名称:nsq,代码行数:31,代码来源:client_v2.go

示例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
		}
	}
}
开发者ID:yershalom,项目名称:prometheus,代码行数:40,代码来源:storage.go

示例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
}
开发者ID:intoximeters,项目名称:heka,代码行数:7,代码来源:kafka_input.go

示例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,
	}
}
开发者ID:gwatts,项目名称:dyndump,代码行数:9,代码来源:fetcher.go

示例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
}
开发者ID:nickpresta,项目名称:goat,代码行数:28,代码来源:status.go

示例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)
	}
}
开发者ID:ljvblfz,项目名称:slot-golang,代码行数:30,代码来源:wsclient.go

示例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
}
开发者ID:xianxu,项目名称:gostrich,代码行数:8,代码来源:gostrich.go

示例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
	}
}
开发者ID:jmptrader,项目名称:tcpengine,代码行数:34,代码来源:tcpengine.go

示例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
		}
	}
}
开发者ID:yumimobi,项目名称:retrying,代码行数:32,代码来源:retrying.go

示例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
}
开发者ID:kzadorozhny,项目名称:backplane,代码行数:31,代码来源:qps.go

示例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")
}
开发者ID:seacoastboy,项目名称:vitess,代码行数:31,代码来源:roundrobin.go

示例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
}
开发者ID:ryanfowler,项目名称:ratelim,代码行数:26,代码来源:tokenbucketqueue.go

示例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
}
开发者ID:bsmedberg,项目名称:data-pipeline,代码行数:7,代码来源:s3offset_input.go

示例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)
}
开发者ID:rumpelsepp,项目名称:relaysrv,代码行数:31,代码来源:status.go

示例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()
		}
	}
}
开发者ID:jmptrader,项目名称:tcpengine,代码行数:32,代码来源:tcpengine.go


注:本文中的sync/atomic.LoadInt64函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。