30-day check-in for interview questions-day11

1. What are the isolation levels of MySQL transactions, what are their characteristics, and what is the default isolation level of MySQL?

  1. Read uncommitted: read uncommitted (the lowest isolation level) "You can read before submitting"

    • Transaction A can read to transaction BunsubmittedThe data
    • Dirty read, non-repeatable, and phantom reading may occur
    • theoretically
  2. Read committed: read committed (can only be read after submission)

    • Transaction A can only read transaction Bafter submissionThe data
    • Dirty reads are solved, but it is non-repeatable read data
    • The data read each time is real data
  3. Repeatable read: repeatable read (you can't read it after committing: read the data when the transaction is started. The data will not change until the transaction ends)

    • After transaction A is started, the data read in transaction A is consistent every time. Even if transaction B modifies the data, the data read in transaction A remains unchanged.
    • Solved the problem of non-repeatable reading
    • Phantom reading occurs: the data read is fantasy
  4. Serialization/Serialization: serializable (highest isolation level)

    • Highest efficiency, solve all problems

    • Transactions need to be queued and cannot be concurrent. The concurrent performance is low and the overhead is high.

By default, MySQL's isolation level is repeatable read

When the interviewer asks this question, he may want to know how much you know about the MySQL transaction isolation level, as well as your understanding of the impact of the transaction isolation level on data, how to choose an appropriate isolation level, and so on. At the same time, it may also examine your mastery of the basic concepts and principles of the database.

2. Tell me about the single-threaded model of Redis. What is IO multiplexing?

Redis is a memory-based high-performance key-value database. Its single-threaded model means that Redis processes client requests and internal tasks through an event loop in the main thread. The Redis main thread implements asynchronous event processing by blocking listening to file descriptors. This single-threaded model can avoid problems such as competition and locking among multiple threads, and also allows Redis to easily achieve high-concurrency and high-throughput processing.

The IO multiplexing in the Redis single-threaded model refers to the use of some characteristics of the operating system to realize the simultaneous processing of I/O operations for multiple connections by monitoring multiple file descriptors at the same time. In Redis, by using multiplexing technology, the main thread can monitor the connections of multiple clients at the same time. When an I/O event occurs in a client connection, the main thread can process the event in a timely manner, thereby improving I/O efficiency of Redis.

In Redis's single-threaded model, although there is only one main thread, it can simultaneously process the I/O operations of multiple connections through IO multiplexing technology, thereby achieving efficient asynchronous event processing.

3. What are BIO, NIO, AIO?

BIO, NIO, and AIO are all I/O models for network programming in Java.

BIO (Blocking IO) is the traditional IO model before JDK1.4. It is characterized by synchronous blocking and waiting for data. The result will not be returned until the data is read. The thread will always be blocked on the method and cannot process other IO read/writerequests. Its concurrency The performance is relatively poor.

NIO (Non-Blocking IO) is a new IO model after Java 1.4, which supports synchronous non-blocking IO operations. NIO uses a multiplexer to process IO requests, and processes multiple IO requests through one thread to achieve high concurrent processing. NIO has three core concepts: Selector, Channel, and Buffer. Selector is responsible for monitoring events on multiple Channels. Channel can be understood as the encapsulation of original IO, and Buffer is the encapsulation of data.

AIO (Asynchronous IO) is a new IO model after Java 1.7, which supports asynchronous non-blocking IO operations. Different from NIO, AIO does not need to keep polling like NIO when performing read and write operations. Instead, it notifies the application to read the data after the data is ready through the callback function, which can make more efficient use of the system. resources and increase throughput. But AIO does not perform as well as NIO when dealing with small files and small data volumes.

The difference between the three

BIO AIO NIO
How to handle IO blocking IO non-blocking IO Asynchronous I/O
shortcoming poor concurrency performance achieve fu'z Although it makes up for the concurrency capability, the NIO code is more complicated
suitable for the scene The number of connections is small and fixed The number of links is very large and the link time is relatively long Many connections and few changes

Guess you like

Origin blog.csdn.net/qq_56098191/article/details/130356908