当前位置:网站首页>22-05-26 Xi'an interview question (01) preparation
22-05-26 Xi'an interview question (01) preparation
2022-07-03 08:48:00 【£ small feather】
I. Copy of object : Deep copy and light copy
An object exists 2 There are two types of properties , One is basic data type , One is the reference of instance object
Shallow copy refers to : Copy the value of the basic data type and the reference address of the instance object , It will not copy the object pointed to by a reference object , That is, the objects that are copied out , Internal reference attributes refer to objects in the same heap in memory .
Deep copy : Copy the value of the basic data type and the object pointed to by the reference address of the instance object , Both will copy . Deeply copied objects , The internal reference attribute points to an object in the same heap no longer as the object pointed to before copying
II. thread deadlock
Conditions to be satisfied by the lock
- A resource can only be used by one thread at a time
- A thread is blocking waiting for a resource , Do not release occupied resources
- A thread has obtained resources , Before use , Can't be forcibly deprived of
Deadlock is to add a necessary condition to the lock
4. A number of threads form end-to-end loops waiting for resource relationships
How to avoid deadlock in the development process ?
Pay attention to the locking sequence , Ensure that each thread locks in the same order
Pay attention to the locking time limit , Set a timeout for the lock
Pay attention to deadlock checking , It's a preventive mechanism , Ensure that deadlocks are discovered and resolved at the first time
III.redis Eliminate key The algorithm of LRU and LFU difference
LRU Algorithm ( Least recently used ,recently):
Eliminate data that has not been accessed for a long time , Take the latest visit time as a reference
LFU Algorithm ( The least used ,frequently)
Eliminate the data that has been accessed the least in recent time , Take the number of times as a reference
In most cases, we can use LRU Strategy , When there is a large amount of hotspot cache data ,LFU Better .
IV. Why use caching
cache purpose : High performance 、 High concurrency .
High performance : Suppose there are many read requests , Then directly put the results of the query in the cache , Just read the cache directly later !
High concurrency : The concurrency of a single cache is mysql Dozens of times of single machine . Cache is memory driven , Memory naturally supports high concurrency .
V: How to ensure the data consistency between cache and database ?
Serialization ensures that no inconsistencies will occur , But it will also cause the throughput of the system to be greatly reduced .
Cache Aside Pattern
- When reading , Read cache first , If there is no cache , Reading database , Then take out the data and put it into the cache , Return response at the same time .
- When it's updated , Update the database first , Then delete the cache .
VI What is? Redis The avalanche of 、 Penetration and breakdown ?
Cache avalanche and penetration , The two biggest problems in caching , Or it doesn't show up , When it does, it's fatal
Cache avalanche : The cache machine went down unexpectedly . The cache is down , here 1 second 5000 Requests all drop to database , Database can't bear it , It will call the police , And then I hung up
Cache penetration : database id It's from 1 At the beginning , As a result, the request from the hacker id All negative numbers . In this case , Not in cache , Request every time “ View cache in nothing ”, Direct query database . The cache penetration in this malicious attack scenario will directly kill the database .
Cache breakdown : That is to say, some key Very hot , Very frequent visits , Centralized high concurrent access , When this key At the moment of failure , A large number of requests break down the cache , Direct request database , It's like making a hole in a barrier .
边栏推荐
- [RPC] RPC remote procedure call
- PHP uses foreach to get a value in a two-dimensional associative array (with instances)
- Simple demo of solving BP neural network by gradient descent method
- Collection interface
- Unity editor expansion - window, sub window, menu, right-click menu (context menu)
- Unity editor expansion - controls, layouts
- [rust notes] 09- special types and generics
- Introduction to Base64 coding
- PHP mnemonic code full text 400 words to extract the first letter of each Chinese character
- [rust notes] 11 practical features
猜你喜欢
Allocation exception Servlet
100 GIS practical application cases (78) - Multi compliance database design and data warehousing
Data analysis exercises
单调栈-42. 接雨水
Monotonic stack -503 Next bigger Element II
Collection interface
[updating] wechat applet learning notes_ three
Concurrent programming (VI) ABA problems and solutions under CAS
Constraintlayout's constraintset dynamically modifies constraints
[concurrent programming] consistency hash
随机推荐
Annotations simplify configuration and loading at startup
[rust notes] 11 practical features
Installation of PHP FPM software +openresty cache construction
796 · unlock
Message queue for interprocess communication
[public key cryptography] ECC elliptic cryptosystem (implementing ElGamal encryption method)
Drawing maze EasyX library with recursive backtracking method
单调栈-503. 下一个更大元素 II
Message pack in C deserializes array objects
Redux - learning notes
Visual Studio (VS) shortcut keys
【Rust 笔记】10-操作符重载
How does unity fixedupdate call at a fixed frame rate
[rust notes] 05 error handling
Constraintlayout's constraintset dynamically modifies constraints
Mysql容器化(1)Docker安装MySQL
[concurrent programming] concurrent security
Unity editor expansion - the design idea of imgui
Unity Editor Extension - Outline
Find the intersection of line segments