本文整理匯總了Golang中github.com/netflix/rend/timer.Now函數的典型用法代碼示例。如果您正苦於以下問題:Golang Now函數的具體用法?Golang Now怎麽用?Golang Now使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Now函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Prepend
func (l *L1L2BatchOrca) Prepend(req common.SetRequest) error {
//log.Println("prepend", string(req.Key))
metrics.IncCounter(MetricCmdPrependL2)
start := timer.Now()
err := l.l2.Prepend(req)
metrics.ObserveHist(HistPrependL2, timer.Since(start))
if err != nil {
// Prepending in L2 did not succeed. Don't try in L1 since this means L2
// may not have succeeded.
if err == common.ErrItemNotStored {
metrics.IncCounter(MetricCmdPrependNotStoredL2)
metrics.IncCounter(MetricCmdPrependNotStored)
return err
}
metrics.IncCounter(MetricCmdPrependErrorsL2)
metrics.IncCounter(MetricCmdPrependErrors)
return err
}
// L2 succeeded, so it's time to try L1. If L1 fails with a not found, we're
// still good since L1 is allowed to not have the data when L2 does. If
// there's an error, we need to fail because we're not in an unknown state
// where L1 possibly doesn't have the Prepend when L2 does. We don't recover
// from this but instead fail the request and let the client retry.
metrics.IncCounter(MetricCmdPrependL1)
start = timer.Now()
err = l.l1.Prepend(req)
metrics.ObserveHist(HistPrependL1, timer.Since(start))
if err != nil {
// Not stored in L1 is still fine. There's a possibility that a
// concurrent delete happened or that the data has just been pushed out
// of L1. Prepend will not bring data back into L1 as it's not necessarily
// going to be immediately read.
if err == common.ErrItemNotStored || err == common.ErrKeyNotFound {
metrics.IncCounter(MetricCmdPrependNotStoredL1)
metrics.IncCounter(MetricCmdPrependStored)
return l.res.Prepend(req.Opaque, req.Quiet)
}
metrics.IncCounter(MetricCmdPrependErrorsL1)
metrics.IncCounter(MetricCmdPrependErrors)
return err
}
metrics.IncCounter(MetricCmdPrependStoredL1)
metrics.IncCounter(MetricCmdPrependStored)
return l.res.Prepend(req.Opaque, req.Quiet)
}
示例2: Add
func (l *L1L2BatchOrca) Add(req common.SetRequest) error {
//log.Println("add", string(req.Key))
// Add in L2 first, since it has the larger state
metrics.IncCounter(MetricCmdAddL2)
start := timer.Now()
err := l.l2.Add(req)
metrics.ObserveHist(HistAddL2, timer.Since(start))
if err != nil {
// A key already existing is not an error per se, it's a part of the
// functionality of the add command to respond with a "not stored" in
// the form of a ErrKeyExists. Hence no error metrics.
if err == common.ErrKeyExists {
metrics.IncCounter(MetricCmdAddNotStoredL2)
metrics.IncCounter(MetricCmdAddNotStored)
return err
}
// otherwise we have a real error on our hands
metrics.IncCounter(MetricCmdAddErrorsL2)
metrics.IncCounter(MetricCmdAddErrors)
return err
}
metrics.IncCounter(MetricCmdAddStoredL2)
// Replace the entry in L1.
metrics.IncCounter(MetricCmdAddReplaceL1)
start = timer.Now()
err = l.l1.Replace(req)
metrics.ObserveHist(HistReplaceL1, timer.Since(start))
if err != nil {
if err == common.ErrKeyNotFound {
// For a replace not stored in L1, there's no problem.
// There is no hot data to replace
metrics.IncCounter(MetricCmdAddReplaceNotStoredL1)
} else {
metrics.IncCounter(MetricCmdAddReplaceErrorsL1)
metrics.IncCounter(MetricCmdAddErrors)
return err
}
} else {
metrics.IncCounter(MetricCmdAddReplaceStoredL1)
}
metrics.IncCounter(MetricCmdAddStored)
return l.res.Add(req.Opaque, req.Quiet)
}
示例3: Set
func (l *L1L2Orca) Set(req common.SetRequest) error {
//log.Println("set", string(req.Key))
// Try L2 first
metrics.IncCounter(MetricCmdSetL2)
start := timer.Now()
err := l.l2.Set(req)
metrics.ObserveHist(HistSetL2, timer.Since(start))
// If we fail to set in L2, don't set in L1
if err != nil {
metrics.IncCounter(MetricCmdSetErrorsL2)
metrics.IncCounter(MetricCmdSetErrors)
return err
}
metrics.IncCounter(MetricCmdSetSuccessL2)
// Now set in L1. If L1 fails, we log the error and fail the request.
// If a user was writing a new piece of information, the error would be OK,
// since the next GET would be able to put the L2 information back into L1.
// In the case that the user was overwriting information, a failed set in L1
// and successful one in L2 would leave us inconsistent. If the response was
// positive in this situation, it would look like the server successfully
// processed the request but didn't store the information. Clients will
// retry failed writes. In this case L2 will get two writes for the same key
// but this is better because it is more correct overall, though less
// efficient. Note there are no retries at this level.
//
// It should be noted that errors on a straight set are nearly always fatal
// for the connection. It's likely that if this branch is taken that the
// connections to everyone will be severed (for this one client connection)
// and that the client will reconnect to try again.
metrics.IncCounter(MetricCmdSetL1)
start = timer.Now()
err = l.l1.Set(req)
metrics.ObserveHist(HistSetL1, timer.Since(start))
if err != nil {
metrics.IncCounter(MetricCmdSetErrorsL1)
metrics.IncCounter(MetricCmdSetErrors)
return err
}
metrics.IncCounter(MetricCmdSetSuccessL1)
metrics.IncCounter(MetricCmdSetSuccess)
return l.res.Set(req.Opaque, req.Quiet)
}
示例4: TestMonoTimeIsNeverTheSame
func TestMonoTimeIsNeverTheSame(t *testing.T) {
prev := timer.Now()
same := 0
for i := 0; i < 100000000; i++ {
now := timer.Now()
if now == prev {
same++
}
prev = now
}
t.Logf("Times were the same %d times", same)
}
示例5: Touch
func (l *L1OnlyOrca) Touch(req common.TouchRequest) error {
//log.Println("touch", string(req.Key))
metrics.IncCounter(MetricCmdTouchL1)
start := timer.Now()
err := l.l1.Touch(req)
metrics.ObserveHist(HistTouchL1, timer.Since(start))
if err == nil {
metrics.IncCounter(MetricCmdTouchHitsL1)
metrics.IncCounter(MetricCmdTouchHits)
l.res.Touch(req.Opaque)
} else if err == common.ErrKeyNotFound {
metrics.IncCounter(MetricCmdTouchMissesL1)
metrics.IncCounter(MetricCmdTouchMisses)
} else {
metrics.IncCounter(MetricCmdTouchMissesL1)
metrics.IncCounter(MetricCmdTouchMisses)
}
return err
}
示例6: Gat
func (l *L1OnlyOrca) Gat(req common.GATRequest) error {
//log.Println("gat", string(req.Key))
metrics.IncCounter(MetricCmdGatL1)
start := timer.Now()
res, err := l.l1.GAT(req)
metrics.ObserveHist(HistGatL1, timer.Since(start))
if err == nil {
if res.Miss {
metrics.IncCounter(MetricCmdGatMissesL1)
// TODO: Account for L2
metrics.IncCounter(MetricCmdGatMisses)
} else {
metrics.IncCounter(MetricCmdGatHits)
metrics.IncCounter(MetricCmdGatHitsL1)
}
l.res.GAT(res)
// There is no GetEnd call required here since this is only ever
// done in the binary protocol, where there's no END marker.
// Calling l.res.GetEnd was a no-op here and is just useless.
//l.res.GetEnd(0, false)
} else {
metrics.IncCounter(MetricCmdGatErrors)
metrics.IncCounter(MetricCmdGatErrorsL1)
}
return err
}
示例7: main
func main() {
var prot common.Prot
if f.Binary {
prot = binprot.BinProt{}
} else {
prot = textprot.TextProt{}
}
wg := new(sync.WaitGroup)
wg.Add(f.NumWorkers)
extraOps := f.NumOps % f.NumWorkers
opsPerWorker := f.NumOps / f.NumWorkers
start := timer.Now()
// spawn worker goroutines
for i := 0; i < f.NumWorkers; i++ {
numops := opsPerWorker
if i == 0 {
numops += extraOps
}
go worker(numops, prot, wg)
}
wg.Wait()
log.Println("Total comm time:", timer.Since(start))
}
示例8: Add
func (l *L1OnlyOrca) Add(req common.SetRequest) error {
//log.Println("add", string(req.Key))
metrics.IncCounter(MetricCmdAddL1)
start := timer.Now()
err := l.l1.Add(req)
metrics.ObserveHist(HistAddL1, timer.Since(start))
if err == nil {
metrics.IncCounter(MetricCmdAddStoredL1)
metrics.IncCounter(MetricCmdAddStored)
err = l.res.Add(req.Opaque, req.Quiet)
} else if err == common.ErrKeyExists {
metrics.IncCounter(MetricCmdAddNotStoredL1)
metrics.IncCounter(MetricCmdAddNotStored)
} else {
metrics.IncCounter(MetricCmdAddErrorsL1)
metrics.IncCounter(MetricCmdAddErrors)
}
return err
}
示例9: Replace
func (l *L1OnlyOrca) Replace(req common.SetRequest) error {
//log.Println("replace", string(req.Key))
metrics.IncCounter(MetricCmdReplaceL1)
start := timer.Now()
err := l.l1.Replace(req)
metrics.ObserveHist(HistReplaceL1, timer.Since(start))
if err == nil {
metrics.IncCounter(MetricCmdReplaceStoredL1)
metrics.IncCounter(MetricCmdReplaceStored)
err = l.res.Replace(req.Opaque, req.Quiet)
} else if err == common.ErrKeyNotFound {
metrics.IncCounter(MetricCmdReplaceNotStoredL1)
metrics.IncCounter(MetricCmdReplaceNotStored)
} else {
metrics.IncCounter(MetricCmdReplaceErrorsL1)
metrics.IncCounter(MetricCmdReplaceErrors)
}
return err
}
示例10: Delete
func (l *L1OnlyOrca) Delete(req common.DeleteRequest) error {
//log.Println("delete", string(req.Key))
metrics.IncCounter(MetricCmdDeleteL1)
start := timer.Now()
err := l.l1.Delete(req)
metrics.ObserveHist(HistDeleteL1, timer.Since(start))
if err == nil {
metrics.IncCounter(MetricCmdDeleteHits)
metrics.IncCounter(MetricCmdDeleteHitsL1)
l.res.Delete(req.Opaque)
} else if err == common.ErrKeyNotFound {
metrics.IncCounter(MetricCmdDeleteMissesL1)
metrics.IncCounter(MetricCmdDeleteMisses)
} else {
metrics.IncCounter(MetricCmdDeleteErrorsL1)
metrics.IncCounter(MetricCmdDeleteErrors)
}
return err
}
示例11: TestRegularIntervalsTimer
func TestRegularIntervalsTimer(t *testing.T) {
for i := 0; i < 100; i++ {
start := timer.Now()
time.Sleep(10 * time.Millisecond)
dur := timer.Since(start)
t.Logf("10 ms sleep took %d nanoseconds with timer", dur)
}
}
示例12: Set
func (l *L1L2BatchOrca) Set(req common.SetRequest) error {
//log.Println("set", string(req.Key))
// Try L2 first
metrics.IncCounter(MetricCmdSetL2)
start := timer.Now()
err := l.l2.Set(req)
metrics.ObserveHist(HistSetL2, timer.Since(start))
// If we fail to set in L2, don't do anything in L1
if err != nil {
metrics.IncCounter(MetricCmdSetErrorsL2)
metrics.IncCounter(MetricCmdSetErrors)
return err
}
metrics.IncCounter(MetricCmdSetSuccessL2)
// Replace the entry in L1.
metrics.IncCounter(MetricCmdSetReplaceL1)
start = timer.Now()
err = l.l1.Replace(req)
metrics.ObserveHist(HistReplaceL1, timer.Since(start))
if err != nil {
if err == common.ErrKeyNotFound {
// For a replace not stored in L1, there's no problem.
// There is no hot data to replace
metrics.IncCounter(MetricCmdSetReplaceNotStoredL1)
} else {
metrics.IncCounter(MetricCmdSetReplaceErrorsL1)
metrics.IncCounter(MetricCmdSetErrors)
return err
}
} else {
metrics.IncCounter(MetricCmdSetReplaceStoredL1)
}
metrics.IncCounter(MetricCmdSetSuccess)
return l.res.Set(req.Opaque, req.Quiet)
}
示例13: communicator
func communicator(prot common.Prot, conn net.Conn, tasks <-chan *common.Task, metrics chan<- metric, comms *sync.WaitGroup) {
r := rand.New(rand.NewSource(common.RandSeed()))
rw := bufio.NewReadWriter(bufio.NewReader(conn), bufio.NewWriter(conn))
for item := range tasks {
var err error
start := timer.Now()
switch item.Cmd {
case common.Set:
err = prot.Set(rw, item.Key, item.Value)
case common.Add:
err = prot.Add(rw, item.Key, item.Value)
case common.Replace:
err = prot.Replace(rw, item.Key, item.Value)
case common.Append:
err = prot.Append(rw, item.Key, item.Value)
case common.Prepend:
err = prot.Prepend(rw, item.Key, item.Value)
case common.Get:
_, err = prot.Get(rw, item.Key)
case common.Gat:
_, err = prot.GAT(rw, item.Key)
case common.Bget:
bk := batchkeys(r, item.Key)
_, err = prot.BatchGet(rw, bk)
bkpool.Put(bk)
case common.Delete:
err = prot.Delete(rw, item.Key)
case common.Touch:
err = prot.Touch(rw, item.Key)
}
if err != nil {
// don't print get misses, adds not stored, and replaces not stored
if !isMiss(err) {
fmt.Printf("Error performing operation %s on key %s: %s\n", item.Cmd, item.Key, err.Error())
}
// if the socket was closed, stop. Otherwise keep on hammering.
if err == io.EOF {
break
}
}
m := metricPool.Get().(metric)
m.d = timer.Since(start)
m.op = item.Cmd
m.miss = isMiss(err)
metrics <- m
taskPool.Put(item)
}
conn.Close()
comms.Done()
}
示例14: TestMonotonicAndWallTimerDifference
func TestMonotonicAndWallTimerDifference(t *testing.T) {
start := time.Now().UnixNano()
monostart := timer.Now()
for i := 0; i < 10; i++ {
diff := time.Now().UnixNano() - start
monodiff := timer.Since(monostart)
t.Logf("Wall: %d", diff)
t.Logf("Mono: %d", monodiff)
time.Sleep(1 * time.Second)
}
}
示例15: Set
func (l *L1OnlyOrca) Set(req common.SetRequest) error {
//log.Println("set", string(req.Key))
metrics.IncCounter(MetricCmdSetL1)
start := timer.Now()
err := l.l1.Set(req)
metrics.ObserveHist(HistSetL1, timer.Since(start))
if err == nil {
metrics.IncCounter(MetricCmdSetSuccessL1)
metrics.IncCounter(MetricCmdSetSuccess)
err = l.res.Set(req.Opaque, req.Quiet)
} else {
metrics.IncCounter(MetricCmdSetErrorsL1)
metrics.IncCounter(MetricCmdSetErrors)
}
return err
}