本文整理匯總了Golang中sync/atomic.AddUint64函數的典型用法代碼示例。如果您正苦於以下問題:Golang AddUint64函數的具體用法?Golang AddUint64怎麽用?Golang AddUint64使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了AddUint64函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CountAnAssetRequest
func CountAnAssetRequest(original http.Handler) http.Handler {
return http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
atomic.AddUint64(&totalRequestCount, 1)
atomic.AddUint64(&assetRequestCount, 1)
original.ServeHTTP(response, request)
})
}
示例2: GetOutBuffer
func (pool *bufferPool) GetOutBuffer() (out *OutBuffer) {
var ptr unsafe.Pointer
for {
ptr = atomic.LoadPointer(&pool.out)
if ptr == nil {
break
}
if atomic.CompareAndSwapPointer(&pool.out, ptr, ((*OutBuffer)(ptr)).next) {
break
}
}
atomic.AddUint64(&pool.outGet, 1)
if ptr == nil {
atomic.AddUint64(&pool.outNew, 1)
out = &OutBuffer{Data: make([]byte, 0, pool.bufferInitSize), pool: pool}
} else {
out = (*OutBuffer)(ptr)
atomic.AddInt64(&pool.size, -int64(cap(out.Data)))
}
out.isFreed = false
out.isBroadcast = false
out.refCount = 0
return out
}
示例3: Read
func (c *countingReader) Read(bs []byte) (int, error) {
n, err := c.Reader.Read(bs)
atomic.AddUint64(&c.tot, uint64(n))
atomic.AddUint64(&totalIncoming, uint64(n))
atomic.StoreInt64(&c.last, time.Now().UnixNano())
return n, err
}
示例4: RecycleBuf
// RecycleBuf will put a used buffer into the recycling queue for the given BufferSize. It can block, so you should always call it from its own goroutine.
func RecycleBuf(b []float32, op OutputParams) {
// pc, filename, line, ok := runtime.Caller(1)
// var logstr string
// if ok {
// f := runtime.FuncForPC(pc)
// logstr = fmt.Sprintf("%s:%d:%s", filename, line, f.Name())
// } else {
// logstr = "???"
// }
if len(b) == op.BufferSize && cap(b) == op.BufferSize {
recyclers.RLock()
var ok bool
if _, ok = recyclers.m[op.BufferSize]; !ok {
recyclers.RUnlock()
MakeRecycleChannel(op)
recyclers.RLock()
}
select {
case recyclers.m[op.BufferSize] <- b:
// logger.Println("sending buffer to recycler for",logstr)
atomic.AddUint64(&RecycleStats.Recycled, 1)
default:
// logger.Println("dropping buffer from",logstr)
atomic.AddUint64(&RecycleStats.Lost, 1)
// logger.Println("recycling channel full", len(recyclers.m[op.BufferSize]))
}
recyclers.RUnlock()
} else {
// logger.Println("no recycler for buffer from",logstr)
atomic.AddUint64(&RecycleStats.Lost, 1)
}
}
示例5: Do
// Do generates load using the given function.
func (gen *Generator) Do(f func() error) error {
ticker := time.NewTicker(gen.period)
defer ticker.Stop()
timeout := time.After(gen.duration + gen.warmup)
warmed := time.Now().Add(gen.warmup)
for {
select {
case start := <-ticker.C:
err := f()
if start.After(warmed) {
if err == nil {
// record success
elapsed := us(time.Now().Sub(start))
if err := gen.hist.RecordCorrectedValue(elapsed, us(gen.period)); err != nil {
log.Println(err)
}
atomic.AddUint64(gen.success, 1)
} else {
// record failure
atomic.AddUint64(gen.failure, 1)
}
}
case <-timeout:
return nil
}
}
}
示例6: handleNQuads
func (s *state) handleNQuads(wg *sync.WaitGroup) {
for nq := range s.cnq {
edge, err := nq.ToEdge(s.instanceIdx, s.numInstances)
for err != nil {
// Just put in a retry loop to tackle temporary errors.
if err == posting.E_TMP_ERROR {
time.Sleep(time.Microsecond)
} else {
glog.WithError(err).WithField("nq", nq).
Error("While converting to edge")
return
}
edge, err = nq.ToEdge(s.instanceIdx, s.numInstances)
}
// Only handle this edge if the attribute satisfies the modulo rule
if farm.Fingerprint64([]byte(edge.Attribute))%s.numInstances ==
s.instanceIdx {
key := posting.Key(edge.Entity, edge.Attribute)
plist := posting.GetOrCreate(key, dataStore)
plist.AddMutation(edge, posting.Set)
atomic.AddUint64(&s.ctr.processed, 1)
} else {
atomic.AddUint64(&s.ctr.ignored, 1)
}
}
wg.Done()
}
示例7: newSmolderingCouchTermFieldReader
func newSmolderingCouchTermFieldReader(indexReader *IndexReader, term []byte, field uint16, includeFreq, includeNorm, includeTermVectors bool) (*SmolderingCouchTermFieldReader, error) {
dictionaryRow := NewDictionaryRow(term, field, 0)
val, err := indexReader.kvreader.Get(dictionaryRow.Key())
if err != nil {
return nil, err
}
if val == nil {
atomic.AddUint64(&indexReader.index.stats.termSearchersStarted, uint64(1))
return &SmolderingCouchTermFieldReader{
count: 0,
term: term,
tfrNext: &TermFrequencyRow{},
field: field,
}, nil
}
err = dictionaryRow.parseDictionaryV(val)
if err != nil {
return nil, err
}
tfrk := TermFrequencyRowStart(term, field, []byte{})
it := indexReader.kvreader.PrefixIterator(tfrk)
atomic.AddUint64(&indexReader.index.stats.termSearchersStarted, uint64(1))
return &SmolderingCouchTermFieldReader{
indexReader: indexReader,
iterator: it,
count: dictionaryRow.count,
term: term,
tfrNext: &TermFrequencyRow{},
field: field,
}, nil
}
示例8: mgetHandler
func (s *httpServer) mgetHandler(w http.ResponseWriter, req *http.Request) {
req.ParseForm()
if len(req.Form["key"]) == 0 {
http.Error(w, "MISSING_ARG_KEY", 400)
return
}
startTime := time.Now()
atomic.AddUint64(&s.Requests, 1)
atomic.AddUint64(&s.MgetRequests, 1)
w.Header().Set("Content-Type", "text/plain")
var numFound int
for _, key := range req.Form["key"] {
needle := append([]byte(key), s.ctx.db.RecordSeparator)
line := s.ctx.db.Search(needle)
if len(line) != 0 {
numFound += 1
w.Write(line)
w.Write([]byte{s.ctx.db.LineEnding})
}
}
if numFound == 0 {
atomic.AddUint64(&s.MgetMisses, 1)
w.WriteHeader(200)
} else {
atomic.AddUint64(&s.MgetHits, 1)
}
s.MgetMetrics.Status(startTime)
}
示例9: getHandler
func (s *httpServer) getHandler(w http.ResponseWriter, req *http.Request) {
key := req.FormValue("key")
if key == "" {
http.Error(w, "MISSING_ARG_KEY", 400)
return
}
startTime := time.Now()
atomic.AddUint64(&s.Requests, 1)
atomic.AddUint64(&s.GetRequests, 1)
needle := append([]byte(key), s.ctx.db.RecordSeparator)
line := s.ctx.db.Search(needle)
if len(line) == 0 {
atomic.AddUint64(&s.GetMisses, 1)
http.Error(w, "NOT_FOUND", 404)
} else {
// we only output the 'value'
line = line[len(needle):]
atomic.AddUint64(&s.GetHits, 1)
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Content-Length", strconv.Itoa(len(line)+1))
w.Write(line)
w.Write([]byte{s.ctx.db.LineEnding})
}
s.GetMetrics.Status(startTime)
}
示例10: Send
func (pipeline *mk_itemPipeline) Send(item base.MKItem) []error {
atomic.AddUint64(&pipeline.processingNumber, 1)
defer atomic.AddUint64(&pipeline.processingNumber, ^uint64(0))
atomic.AddUint64(&pipeline.sent, 1)
errs := make([]error, 0)
if item == nil {
errs = append(errs, errors.New("無效條目!"))
return errs
}
atomic.AddUint64(&pipeline.accepted, 1)
var currentItem base.MKItem = item
for _, itemProcessor := range pipeline.itemProcessors {
processedItem, err := itemProcessor(currentItem)
if err != nil {
errs = append(errs, err)
if pipeline.failFast {
break
}
}
if processedItem != nil {
currentItem = processedItem
}
}
atomic.AddUint64(&pipeline.processed, 1)
return errs
}
示例11: monkey
func (z *zeroSum) monkey(tableID uint32, d time.Duration) {
r := newRand()
zipf := z.accountDistribution(r)
for {
time.Sleep(time.Duration(rand.Float64() * float64(d)))
key := keys.MakeTablePrefix(tableID)
key = encoding.EncodeVarintAscending(key, int64(zipf.Uint64()))
key = keys.MakeRowSentinelKey(key)
switch r.Intn(2) {
case 0:
if err := z.Split(z.RandNode(r.Intn), key); err != nil {
if strings.Contains(err.Error(), "range is already split at key") ||
strings.Contains(err.Error(), storage.ErrMsgConflictUpdatingRangeDesc) {
continue
}
z.maybeLogError(err)
} else {
atomic.AddUint64(&z.stats.splits, 1)
}
case 1:
if transferred, err := z.TransferLease(z.RandNode(r.Intn), r, key); err != nil {
z.maybeLogError(err)
} else if transferred {
atomic.AddUint64(&z.stats.transfers, 1)
}
}
}
}
示例12: applyNode
func (ptree *ptree) applyNode(n *node, adds, deletes []*keyBundle) {
for _, kb := range deletes {
if n.keys.len() == 0 {
break
}
deleted := n.keys.delete(kb.key)
if deleted != nil {
atomic.AddUint64(&ptree.number, ^uint64(0))
}
}
for _, kb := range adds {
if n.keys.len() == 0 {
oldKey, _ := n.keys.insert(kb.key)
if n.isLeaf && oldKey == nil {
atomic.AddUint64(&ptree.number, 1)
}
if kb.left != nil {
n.nodes.push(kb.left)
n.nodes.push(kb.right)
}
continue
}
oldKey, index := n.keys.insert(kb.key)
if n.isLeaf && oldKey == nil {
atomic.AddUint64(&ptree.number, 1)
}
if kb.left != nil {
n.nodes.replaceAt(index, kb.left)
n.nodes.insertAt(index+1, kb.right)
}
}
}
示例13: workerStart
// A worker connects to one data manager server.
func (d *bucketDataSource) workerStart(server string, workerCh chan []uint16) {
backoffFactor := d.options.DataManagerBackoffFactor
if backoffFactor <= 0.0 {
backoffFactor = DefaultBucketDataSourceOptions.DataManagerBackoffFactor
}
sleepInitMS := d.options.DataManagerSleepInitMS
if sleepInitMS <= 0 {
sleepInitMS = DefaultBucketDataSourceOptions.DataManagerSleepInitMS
}
sleepMaxMS := d.options.DataManagerSleepMaxMS
if sleepMaxMS <= 0 {
sleepMaxMS = DefaultBucketDataSourceOptions.DataManagerSleepMaxMS
}
// Use exponential backoff loop to handle reconnect retries to the server.
go func() {
atomic.AddUint64(&d.stats.TotWorkerStart, 1)
ExponentialBackoffLoop("cbdatasource.worker-"+server,
func() int { return d.worker(server, workerCh) },
sleepInitMS, backoffFactor, sleepMaxMS)
atomic.AddUint64(&d.stats.TotWorkerDone, 1)
}()
}
示例14: managedLogError
// mangedLogError will take an error and log it to the host, depending on the
// type of error and whether or not the DEBUG flag has been set.
func (h *Host) managedLogError(err error) {
// Determine the type of error and the number of times that this error has
// been logged.
var num uint64
var probability int // Error will be logged with 1/probability chance.
switch err.(type) {
case ErrorCommunication:
num = atomic.LoadUint64(&h.atomicCommunicationErrors)
probability = errorCommunicationProbability
case ErrorConnection:
num = atomic.LoadUint64(&h.atomicConnectionErrors)
probability = errorConnectionProbability
case ErrorConsensus:
num = atomic.LoadUint64(&h.atomicConsensusErrors)
probability = errorConsensusProbability
case ErrorInternal:
num = atomic.LoadUint64(&h.atomicInternalErrors)
probability = errorInternalProbability
default:
num = atomic.LoadUint64(&h.atomicNormalErrors)
probability = errorNormalProbability
}
// If num > logFewLimit, substantially decrease the probability that the error
// gets logged.
if num > logFewLimit {
probability = probability * 25
}
// If we've seen less than logAllLimit of that type of error before, log
// the error as a normal logging statement. Otherwise, probabilistically
// log the statement. In debugging mode, log all statements.
logged := false
rand, randErr := crypto.RandIntn(probability + 1)
if randErr != nil {
h.log.Critical("random number generation failed")
}
if num < logAllLimit || rand == probability {
logged = true
h.log.Println(err)
} else {
h.log.Debugln(err)
}
// If the error was logged, increment the log counter.
if logged {
switch err.(type) {
case ErrorCommunication:
atomic.AddUint64(&h.atomicCommunicationErrors, 1)
case ErrorConnection:
atomic.AddUint64(&h.atomicConnectionErrors, 1)
case ErrorConsensus:
atomic.AddUint64(&h.atomicConsensusErrors, 1)
case ErrorInternal:
atomic.AddUint64(&h.atomicInternalErrors, 1)
default:
atomic.AddUint64(&h.atomicNormalErrors, 1)
}
}
}
示例15: Send
// This does the actual send of a buffer, which has already been formatted
// into bytes of ES formatted bulk data
func (b *BulkIndexer) Send(buf *bytes.Buffer) error {
type responseStruct struct {
Took int64 `json:"took"`
Errors bool `json:"errors"`
Items []map[string]interface{} `json:"items"`
}
response := responseStruct{}
body, err := b.conn.DoCommand("POST", fmt.Sprintf("/_bulk?refresh=%t", b.Refresh), nil, buf)
if err != nil {
atomic.AddUint64(&b.numErrors, 1)
return err
}
// check for response errors, bulk insert will give 200 OK but then include errors in response
jsonErr := json.Unmarshal(body, &response)
if jsonErr == nil {
if response.Errors {
atomic.AddUint64(&b.numErrors, uint64(len(response.Items)))
return fmt.Errorf("Bulk Insertion Error. Failed item count [%d]", len(response.Items))
}
}
return nil
}