Code Monkey home page Code Monkey logo

Comments (6)

kokizzu avatar kokizzu commented on May 30, 2024

for that 14.83s part, probably replacing with https://github.com/kpango/fastime works
or probably increase the time resolution will result in better performance (eg. only check time every 20ms)

for the selectgo part probably there's select channel but with default (it would eat CPU time)

from ttlcache.

ReneKroon avatar ReneKroon commented on May 30, 2024

OK, will check this out. Definitely hasn't received attention so far

from ttlcache.

ReneKroon avatar ReneKroon commented on May 30, 2024

Are you running with a very low TTL ? I find 'meaningful' cpu usage for example if the global TTL is set to 1 milisecond. It would be nice to know your configuration and usage pattern.

from ttlcache.

kokizzu avatar kokizzu commented on May 30, 2024

I'm using 30s-90s TTL
only calling SetExpirationReasonCallback, the rest are default

from ttlcache.

ReneKroon avatar ReneKroon commented on May 30, 2024

When checking one of my production services that does 1-3 cache lookups per REST request, and then some queries, i don't see significant usage. When i create a synthetic case with SetExpirationReasonCallback i do see some usage. However the time spent is in a different part than you show.

I'm using Go 1.16 and latest version of the library on Darwin. Is your deployment also on latest versions?
Screenshot 2021-06-23 at 21 00 08

Bench:

package main

import (
	"fmt"
	"log"
	"math/rand"
	"os"
	"runtime"
	"runtime/pprof"
	"time"

	"github.com/ReneKroon/ttlcache/v2"
)

var notFound = ttlcache.ErrNotFound

func main() {
	cache := ttlcache.NewCache()
	cache.SetExpirationReasonCallback(func(key string, reason ttlcache.EvictionReason, value interface{}) {
		if key == value {
			reason = 0
		}
	})
	f, err := os.Create("barf.pprof")
	if err != nil {
		log.Fatal(err)
	}
	pprof.StartCPUProfile(f)
	defer pprof.StopCPUProfile()

	cache.SetTTL(time.Second * 3)

	for j := 1; j < 30; j++ {
		for i := 1; i < 10000; i++ {

			cache.SetWithTTL(fmt.Sprintf("%d", i), "MyValue", time.Millisecond*time.Duration(rand.Int31n(10)))
			cache.Set("MyNumber", 1000)

			if val, err := cache.Get(fmt.Sprintf("%d", i)); err != notFound {
				a := val
				if a == "ADF" {

				}
			}

		}
		time.Sleep(time.Millisecond * 10)
	}

	cache.Purge()

	cache.Close()
}

With a usage of 0.47s on 2.94s of total usage in the program.

from ttlcache.

ReneKroon avatar ReneKroon commented on May 30, 2024

I think you were looking at the 'blocking' profile instead of cpu profile?

from ttlcache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.