In terms of cache stability, basically, every cache-related article and share on the web talks about three key points.

  • Cache penetration
  • Cache Breakdown
  • Cache Avalanche

Why talk about cache stability in the first place? You can recall when we introduce caching? Usually it is when the DB is under pressure or even frequently hit and hung that we introduce caching, so we first introduced the caching system to solve the stability problem.

Cache Penetration

The reason for the existence of cache penetration is the request for non-existent data, from the figure we can see that request 1 for the same data will…


Photo by Icons8 Team on Unsplash

Problems

  • If the response time is too long, the users may have left this page, but the server is still consuming resources to process, and the result obtained is meaningless.
  • Too long server-side processing will cost too much resources, resulting in a decline in concurrency, and even service unavailability

Why Go timeout control is necessary?

Go is normally used to write backend services. Generally, a request is completed by multiple serial or parallel subtasks. Each subtask may issue another internal request. When the request times out, it’s better to return quickly and release the occupied resources, such as goroutines, file descriptors, etc.


1. choose a simple linux image

For example alpine, it's only about 5MB.

2. set timezone if necessary

RUN apk add --no-cache tzdata
ENV TZ America/New_York

3. multi-stage build

  • the first stage to build the binary, ensure the binary is dev box independent
  • use the binary in the first stage to build the final image

4. the simplest way to write Dockerfile

  • first of all, install the tool goctl

GO111MODULE=on go get -u github.com/tal-tech/go-zero/tools/goctl

  • in project greet, create a service called hello

goctl api new hello

  • file structure listed below:
greet
├── go.mod
├── go.sum
└── service
└── hello
├── etc…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store