当前位置:网站首页>redis-0. Introduction to redis and NiO principle (random talk)
redis-0. Introduction to redis and NiO principle (random talk)
2022-06-13 07:12:00 【Floating across the sea】
reids
redis Introduce
common sense
First of all, common sense , The data in the computer is stored in disk , There are actually two dimensional indicators
1. Addressing :ms It's on the millisecond level
2. bandwidth :G/M How many? G How many? M
Memory
1. Addressing :ns Nanosecond level
2. bandwidth : It's big
second > millisecond > Microsecond > nanosecond . Disk is slower than memory 10W times , On addressing
I/O buffer: The question of cost
The disk has tracks , A sector , One sector 512Byte Bring a larger index of costs
4K Operating system default , No matter how much you read , It's all the least 4k From disk .
So the file becomes larger and the speed becomes slower
Relational database

And the database appears data page Size is 4k, It just matches the size of the hardware disk . It can be reduced by a certain amount io The operation of , Avoid waste , Because whatever it is 4k. But the database is still slow , So there are indexes in the database , As shown above , The index corresponds to each of these page, Faster than retrieval .B+T What is stored inside is an interval , such as 1,7,10, If you inquire 6 Will fall into the first data page Indexes , Find the corresponding in the index data page data
Create tables for relational databases : Must give schema type : Byte width memory : Prefer row level storage
Interview questions database : The watch is big , Performance degradation ? If the table has an index, add, delete, or change Slow queries ( Maintain data index , So it slows down )
How about the speed ?1,1 One or a few queries are still very fast 2, When the concurrency is large, the speed will be affected by the bandwidth of the hard disk
Non relational database
In fact, there is also an in memory database SAP–HANA . But this kind of family charges , There is a knowledge that : The volume of data on disk and memory is different .
This kind of situation occurs when people do not want to pay and do not want their own services to be slow redis Non relational row database of cache class , Based on two infrastructures
Basic knowledge of computer :2 Infrastructure 1, The hardware of von Neumann system 2, Ethernet ,tcp/ip Network of ( The subtext is instability )
If the above two infrastructures are completed , There will be no more non relational types
https://db-engines.com/en/ This website also sees the ranking of the database 
You can also see the current PostgreSQL The hot
redis
redis Chinese official website :http://redis.cn/
Redis It's open source (BSD The license ) Of , Data structure storage system in memory , It can be used as a database 、 Caching and message middleware . It supports multiple types of data structures , Such as character string (strings), hash (hashes), list (lists), aggregate (sets), Ordered set (sorted sets) And scope query , bitmaps, hyperloglogs and Geographical space (geospatial) Index radius query . Redis Built in Copy (replication),LUA Script (Lua scripting), LRU Driving events (LRU eviction), Business (transactions) And different levels of Disk persistence (persistence), And pass Redis sentry (Sentinel) And automatic Partition (Cluster) Provide high availability (high availability).

Actually redis Type is not very important , It is important to redis Of server There are methods for each type in index()lpop
redis It's a single process , Single thread , Single instance , How requests become fast when concurrent , The operating system has a kernel (kernel) The concept of , The user enters the kernel first , Kernel in epoll ( Multiplexing ) to redis

The client to Linux It's in milliseconds ,Linux Memory interaction is nanoscale
io Technology is evolving
BIO
In the early days, the kernel only had read fd fd( representative Linux File descriptor ), This is the time socket It's blocked , When the thread is processing , The remaining threads can only wait

NIO
yum install man man-pages Install it. man User manual
# see read Method
main 2 read
linux Everything inside is a document

# see redis
ps -ef|grep redis
# Enter... Under the change process fd file
cd /proc/20094/fd

man 2 socket see socket Operation manual , We can see socket It can be non blocking , Before BIO yes block Of

Synchronous nonblocking
NIO Multiplexing
above nio Because the user process needs to poll constantly kernel operation , At this time, the user space can do nothing , The kernel is required to operate the upgrade
# see select operation
man 2 select

kernel select The main thing is to monitor more fds File descriptor

In the past, I wrote an endless loop , Now it's time to stop writing dead cycles , If there is 1000, Just put this 1000 Pass it on to you , If there is any change, it will be returned to user space , Then go on read operation , Reduce user status , Kernel state switching

epoll false AIO
window Realized AIO operation
main 2 mmap

This is the time mmap There is ,mmap It's a way to map files in memory , Mapping a file or other object to the address space of a process , Realize the one-to-one mapping between the file disk address and the virtual address space of a process .

man epoll
see epoll
Actually epoll It doesn't use mmap It's just using Red black tree and linked list Easy to read and find quickly
kafka Of io operation ,nginx gossip


边栏推荐
猜你喜欢

全志V3S环境编译开发流程

How to make a development board from scratch? Illustrated and illustrated, step by step operation for you to see.

Tikv key performance parameters and optimization

Detailed description of drawing ridge plot, overlapping densities of overlapping kernel density estimation curve, facetgrid object and function sns Kdeplot, function facetgrid map

June 12, 2022: if there are n*n pieces in an n*n square chessboard, each grid can have exactly one piece. But now some pieces are gathered on a grid, such as 2030100300. The above two-dimensional arra

Simple understanding of basic language of C language

对绘制丘岭密度图ridge plot的详细说明、重叠核密度估计曲线overlapping densities、FacetGrid对象、函数sns.kdeplot、函数FacetGrid.map

Reflection of C # Foundation

How worker threads in the thread pool are recycled

Priority analysis of list variables in ansible playbook and how to separate and summarize list variables
随机推荐
Ticdc synchronization task
Relevant knowledge under WinForm
【RS-422与RS-485】RS-422与RS-485串行接口标准
Interview questions must be asked - Optimization of large table Pagination
c#高級編程-特性篇
Upper computer development (code debugging of firmware download software)
Fundamentals of assembly language: register and addressing mode
C # Advanced Programming - Feature Section
Lightning breakpoint continuation
Simple understanding of basic language of C language
杭州网上开户是安全的吗?
What is the new business model of Taishan crowdfunding in 2022?
Monotone stack top31 of interview must brush algorithm top101
关于c#委托、事件相关问题
Tidb implementation plan -- I
Tidb data migration (DM) Introduction
Is it safe for Hangzhou Securities to open an account?
汇编语言基础:寄存器和寻址方式
C Advanced Programming - features
怎么写出一份令人惊叹的设计文档?
