Interview question
How is the cache used in the project? Why use a cache? What are the consequences of improper use of the cache?
Interviewer psychoanalysis
This problem, Internet companies must ask, if a person is not even clear about the cache, it is rather embarrassing.
As long as you ask the cache, the first question is, first of all, ask you where to use the cache? Why use it? Don't you have to work? What are the possible consequences if used later?
This is to see if you have any thoughts on the back of the cache. If you are stupid and can't give the interviewer a reasonable answer, then the interviewer will not be very good at you. I think you usually think too little. I know how to work.
Analysis of interview questions
How is the cache used in the project?
This, you need to combine the business of your own project.
Why use a cache?
With caching, there are two main uses: high performance , high concurrency .
high performance
Assuming such a scenario, you have an operation, a request comes over, you are arbitrarily operating mysql, and a result is found for half a day, which takes 600ms. But this result may not change in the next few hours, or it may not need to be immediately feed back to the user. So what do you do at this time?
Cache it, need 600ms to get result, throw it to cache and responds a key to value, next time someone asked, it not spend 600ms to get result again but directly from cache. It's only 2ms. Performance is increased by 300 times.
That is to say, for some results that require complicated operations and time-consuming detection, and it is determined that the latter call does not change much, but there are many read requests, then directly put the results of the query in the cache, and then directly read the cache.
High concurrency
Mysql is such a heavy database, the design is not to let you play high concurrency, although you can play, but natural support is not good. mysql single supported to
2000QPSbe easy to start the alarm.
So if you have a system, there are 10,000 requests coming in one second during the peak period, and that one mysql single machine will definitely die. You can only cache on this time, put a lot of data in the cache, do not put mysql. Caching feature simple, it means
key-valueoperation, the amount of concurrent easy one second stand-alone support tens of thousands of hundreds of thousands, support high concurrency so easy. The single-machine bearer is tens of times more than the mysql stand-alone.The cache is memory-bound, and the memory naturally supports high concurrency.
What are the consequences of using the cache?
Common cache issues are as follows:
- Cache is inconsistent with database double write
- Cache avalanche, cache penetration
- Cache concurrent competition
This will be described in detail later.
Nhận xét
Đăng nhận xét