Download:Introduction to Performance Testing -Jmeter tools and monitoring built from scratch

Through the study of this course, I can master the most popular and practical technical solutions of performance testing, complete performance testing independently, and lead the team to solve enterprise-level performance problems

Technical reserve requirements

Before learning this course, you are expected to have the foundation of Java language, at least familiar with the syntax and features of Java, preferably have written some code, MySQL, Linux basic knowledge

This course does not cover the basics. func AsyncAdd(run func() error) { //TODO: Go run()} func GetInstance(CTX context. context, ID uint64) (string, error) { data,err := GetFromRedis(ctx,id) if err ! = nil && err ! Nil{return “”, err} if err == redis.Nil{data,err = GetFromDB(CTX,id) if err! = nil{ return “”, err } AsyncAdd(func() error{ return UpdateCache(ctx,id,data) }) } return data,nil } func GetFromRedis(ctx context.Context,id uint64) (string,error) { // TODO: Return “”,nil} func GetFromDB(CTX context. context,id uint64) (string,error) {// TODO: Return “”,nil} func UpdateCache(CTX context. context,id interface{},data string) error {// TODO: Return nil} func main() {CTX,cancel := context.withtimeout (context.background (), 3 * time.Second) defer cancel() _,err := GetInstance(ctx,2021) if err ! = nil{return}} parse let’s just parse, what does this piece of code do? In fact, it is very simple. If we want to get a piece of information, we will first get it from the cache. If we can’t get it from the cache, we will get it from DB. Isn’t the whole design great, but in practice, asynchronous cache updates have never been successful?

The recipe for failure lies in this code:

AsyncAdd(func() error{
        return UpdateCache(ctx,id,data)
    })
Copy the code

There is only one cause of error, this is CTX, if changed to this, nothing is wrong.

AsyncAdd(func() error{

ctxAsync,cancel := context.WithTimeout(context.Background(),3 * time.Second)

defer cancel()

return UpdateCache(ctxAsync,id,data)

})