当前位置:网站首页>Design experience of log file IO system
Design experience of log file IO system
2022-07-23 12:47:00 【liangdu_ Zuker】
Record the log file once IO System design experience
bytebuffer How to use it .
bytebuffer The essence of is caching , We can think of it as the concept of comparative physical layer , For example, if we don't plan the mapping access , Or the file index is not well designed , It is easy to create many file handles , Eventually, it is easy to cause the operating system inode Light consumption .
So I want to learn bytebuffer The key is to master Position and capacity Use skills .
secondly , Is to do a good job in file indexing and mapping range control , The common method is to segment the file segment, Then index the segment .
Of course, you can control the business scope, file recycling strategy and later use shell Write a compact The script of logic ( Compress large files into small files ) As compensation .
Use of locks
The place where we need to lock the whole system manually is the opening and closing of files .
If the file is opened and created without locking , It is easy to create many files , Even destroy our business logic , trigger BUG. This is ERROR Grade .
The second is to close the file and lock it , If the closed file is not locked , When recycling files or unmapping, it is easy to hold them because of concurrency " It's been shut down " Handle to the file , So as to throw the exception of missing handle . This is just WARN Grade .
For the part of business code , Locking is not recommended because it will reduce performance . Considering the document IO Less resources , therefore Multithreading + Synchronous write lock scheme , It's better to use one-way programming , Using thread pool to queue asynchronously . One is simple code , The difficulty of monitoring and maintenance is also low , The performance can be said to be quite . Also reduced CPU The cost of context switching .
The use of thread pools
Most of our projects use SpringBoot, So we decided to give the thread pool to Spring Bean trusteeship .
The second is to improve the isolation of business , At the same time, the performance problem is also considered , Because we have divided multiple files for writing according to business , therefore , We decided to give each document 【 Try to 】 Allocate a thread .
We applied for a set of thread pools , Each thread pool has a thread and a bounded synchronous blocking queue .
Then we do according to the file name hash, according to Hash To allocate thread pools .
In this way, basically every file has an independent working thread .
Later we can also consider using actuator Monitor the performance of thread pool .
边栏推荐
猜你喜欢

C#:快速排序,有相同的数字会忽略,然后继续先前的寻找方向去找下一个满足要求的数字进行替换

@RequiredArgsConstructor注解使用

GameFramework:资源热更代码分析,检查版本信息,下载版本文件,校验版本文件,得到更新文件数量,下载文件,TaskPool

Explanation of websocket protocol

Hcip--- BGP related configuration

C语言也能写植物大战僵尸

OSPF和RIP的路由扩展配置

Unity3d:UGUI,UI与特效粒子层级,2018.2以上版本BakeMesh,粒子在两个Image之间且在ScrollView

Common sort -- merge sort (recursive and non recursive) + count sort
![[fee of AUTOSAR (difference between nonvolatile memory flash and EEPROM)]](/img/cc/34bfcc450d82befab24173b0cb132d.png)
[fee of AUTOSAR (difference between nonvolatile memory flash and EEPROM)]
随机推荐
Basic knowledge of high voltage technology
URL查询参数编码问题(golang)
C custom queue set
C # custom stack
C语言数据库:基于tcp多进程的在线词典,有详细的步骤已经图解,欢迎大家来观看
Hcip--- BGP related configuration
C # custom bidirectional linked list
HCIP---BGP相关配置
C# 自定义集合
Unity3d:特效对象池,超时删除池内GameObject,GC权值
Summary of video coding and decoding related data
Explain various network protocols in detail
如何用普通的文本编辑器写Web页面
OSPF的链路扩展配置
剑指 Offer做题总结
HCIP---条件匹配和OSPF协议
C#(CSharp) 微信公众号开发一 基本配置
Analysis of Internet Protocol (II)
2小时1000人吃饭,要多少台座椅?
详解TCP连接的释放