C++負載均衡遠程調用學習之負載均衡算法與實現

目錄

01 lars 系統架構回顧

02 lars-lbAgentV0.4-route_lb處理report業務流程

03 lars-lbAgentV0.4-負責均衡判斷參數配置

04 lars-lbAgentV0.4-負載均衡idle節點的失敗率判斷

05 lars-lbAgentV0.4-負載均衡overload節點的成功率判斷

06 lars-lbAgentV0.4-負載均衡上報提交模塊

07 lars-lbAgentV0.4-數據問題修改-上報業務測試

08 lars-lbAgentV0.4-模擬器測試工具

09 lars-lbAgentV0.5-idle連續成功-overload連續失敗的定期窗口重置機制

10 lars-lbAgentV0.6-loadbalance主動更新主機信息功能

11 昨日回顧

12 Lars-LbAgentV0.7-GetRouteAPI實現

13 Lars-LbAgentV0.7-Udp-server-獲取路由服務業務注冊

14 Lars-LbAgentV0.7-Udp-server-API和udpserver的測試


01 lars 系統架構回顧

**啟動 Lars Reporter**

```bash
$ ./run_lars reporter
?

????????▄▄???????????????????????????????????????????????
????????██???????????????????????????????????????????????
????????██?????????▄█████▄???██▄████??▄▄█████▄???????????
????????██?????????? ▄▄▄██???██???????██▄▄▄▄ ????????????
????????██????????▄██???██???██????????????██▄???????????
????????██▄▄▄▄▄▄??██▄▄▄███???██???????█▄▄▄▄▄██???????????
??????????????????????? ?????????????????????????????????
????Load balance And Remote service schedule System?
?????????????????????????????????????????????????????????
????????_____???????????????????????_???????????????????????
???????|??__ \?????????????????????| |
???????| |__) |___ _ __???___??_ __| |_ ___ _ __
???????|??_??// _ \ '_ \ / _ \| '__| __/ _ \ '__|
???????| | \ \??__/ |_) | (_) | |??| ||??__/ |
???????|_|??\_\___| .__/ \___/|_|???\__\___|_|
??????????????????| |
??????????????????|_|

????????????ITCAST(https://www.itcast.cn)
?????????------------------------------------?

create 0 thread
create 1 thread
create 2 thread
create 3 thread
create 4 thread
add msg cb msgid = 3
```





**啟動 Lars dns**

```bash
$ ./run_lars dns
?

????????▄▄???????????????????????????????????????????????
????????██???????????????????????????????????????????????
????????██?????????▄█████▄???██▄████??▄▄█████▄???????????
????????██?????????? ▄▄▄██???██???????██▄▄▄▄ ????????????
????????██????????▄██???██???██????????????██▄???????????
????????██▄▄▄▄▄▄??██▄▄▄███???██???????█▄▄▄▄▄██???????????
??????????????????????? ?????????????????????????????????
????Load balance And Remote service schedule System?
?????????????????????????????????????????????????????????
????????????????_____?
???????????????|??__ \?
???????????????| |??| |_ __??___?
???????????????| |??| | '_ \/ __|
???????????????| |__| | | | \__ \?
???????????????|_____/|_| |_|___/?

????????????ITCAST(https://www.itcast.cn)
?????????------------------------------------?

create 0 thread
create 1 thread
create 2 thread
create 3 thread
create 4 thread
add msg cb msgid = 1
lars dns service ....
now route version is 1574674421
```



**啟動 Lars Lb Agent**

```c
$ ./run_lars lbagent

????????▄▄???????????????????????????????????????????????
????????██???????????????????????????????????????????????
????????██?????????▄█████▄???██▄████??▄▄█████▄???????????
????????██?????????? ▄▄▄██???██???????██▄▄▄▄ ????????????
????????██????????▄██???██???██????????????██▄???????????
????????██▄▄▄▄▄▄??██▄▄▄███???██???????█▄▄▄▄▄██???????????
??????????????????????? ?????????????????????????????????
????Load balance And Remote service schedule System?
?????????????????????????????????????????????????????????
??????_??????_????????????????????????????????_??
?????| |????| |?????????/\???????????????????| |?
?????| |????| |__??????/??\???__ _??___ _ __ | |_?
?????| |????| '_ \????/ /\ \ / _` |/ _ \ '_ \| __|?
?????| |____| |_) |??/ ____ \ (_| |??__/ | | | |_?
?????|______|_.__/??/_/????\_\__, |\___|_| |_|\__|?
??????????????????????????????__/ |?
?????????????????????????????|___/??

????????????ITCAST(https://www.itcast.cn)
?????????------------------------------------?

```

02 lars-lbAgentV0.4-route_lb處理report業務流程

![4-Lars-agent](./pictures/4-Lars-agent.png)



LB Agent擁有5個線程,一個LB算法:

-?UDP Server服務,并運行LB算法,對業務提供節點獲取和節點調用結果上報服務;為了增大系統吞吐量,使用3個UDP Server服務互相獨立運行LB算法:`modid+cmdid % 3 = i`的那些模塊的服務與調度,由第`i+1`個UDP Server線程負責
-?Dns Service Client:是dnsserver的客戶端線程,負責根據需要,向dnsserver獲取一個模塊的節點集合(或稱為獲取路由);UDP Server會按需向此線程的MQ寫入獲取路由請求,DSS Client將MQ到來的請求轉發到dnsserver,之后將dnsserver返回的路由信息更新到對應的UDP Server線程維護的路由信息中
-?Report Service Client:是reporter的客戶端線程,負責將每個模塊下所有節點在一段時間內的調用結果、過載情況上報到reporter Service端,便于觀察情況、做報警;本身消費MQ數據,UDP Server會按需向MQ寫入上報狀態請求

03 lars-lbAgentV0.4-負責均衡判斷參數配置

## 2) 構建Lars-Agent項目????

### 2.1 構建目錄結構

依次創建如下目錄:

> Lars/lars_loadbalance_agent



```bash
lars_loadbalance_agent/
├── bin/
├── conf/
│?? └── lars_lb_agent.conf
├── include/
├── Makefile
└── src/
```



其中Makefile如下:

```makefile
TARGET= bin/lars_lb_agent
CXX=g++
CFLAGS=-g -O2 -Wall -Wno-deprecated

BASE=../base
BASE_H=$(BASE)/include

PROTO = $(BASE)/proto
PROTO_H = $(BASE)/proto

LARS_REACTOR=../lars_reactor
LARS_REACTOR_H =$(LARS_REACTOR)/include
LARS_REACTOR_LIB=$(LARS_REACTOR)/lib??-llreactor

MYSQL=$(BASE)/mysql-connector-c
MYSQL_H=$(MYSQL)/include
MYSQL_LIB=$(MYSQL)/lib/libmysqlclient.a

OTHER_LIB = -lpthread -ldl -lprotobuf
SRC= ./src
INC= -I./include -I$(BASE_H) -I$(LARS_REACTOR_H) -I$(MYSQL_H) -I$(PROTO_H)

LIB= $(MYSQL_LIB) -L$(LARS_REACTOR_LIB) $(OTHER_LIB)?


OBJS = $(addsuffix .o, $(basename $(wildcard $(SRC)/*.cpp)))
OBJS += $(PROTO)/lars.pb.o

$(TARGET): $(OBJS)
????????mkdir -p bin
????????$(CXX) $(CFLAGS) -o $(TARGET) $(OBJS) $(INC) $(LIB)

%.o: %.cpp
????????$(CXX) $(CFLAGS) -c -o $@ $< $(INC)?

.PHONY: clean

clean:
????????-rm -f src/*.o??$(PROTO)/lars.pb.o $(TARGET)
```

?????????實際上reporter、dns相似。

> conf/lars_lb_agent.conf

```ini
[reporter]
ip = 127.0.0.1
port = 7779

[dnsserver]
ip = 127.0.0.1
port = 7778
```

?????????目前的基本配置文件,因為loadbalance_agent是充當reporter和dnsserver的客戶端,所以需要知道對應的reporter和dnsserver的ip和port信息。

04 lars-lbAgentV0.4-負載均衡idle節點的失敗率判斷

### 2.2 主模塊業務搭建

![19-lars-agent_1](./pictures/19-lars-agent_1.png)

?????????首先我們要在主線程中,啟動3個UDP Server線程,這個是提供業務層/API層的服務。然后分別啟動report_client線程,用來和reporter Service進行通信,將請求上報信息發送給Reporter Service。 然后再啟動dns_client線程,用來和dns service通信。

> lars_loadbalance_agent/include/main_server.h?

```c
#pragma once
#include "lars_reactor.h"
#include "lars.pb.h"


//與report_client通信的thread_queue消息隊列
extern thread_queue<lars::ReportStatusRequest>* report_queue;
//與dns_client通信的thread_queue消息隊列
extern thread_queue<lars::GetRouteRequest>* dns_queue;


// 啟動udp server服務,用來接收業務層(調用者/使用者)的消息
void start_UDP_servers(void);

// 啟動lars_reporter client 線程
void start_report_client(void);

// 啟動lars_dns client 線程
void start_dns_client(void);
```

05 lars-lbAgentV0.4-負載均衡overload節點的成功率判斷

> lars_loadbalance_agent/src/main_server.cpp?

```c
#include "main_server.h"
#include "lars.pb.h"

//與report_client通信的thread_queue消息隊列
thread_queue<lars::ReportStatusRequest>* report_queue = NULL;
//與dns_client通信的thread_queue消息隊列
thread_queue<lars::GetRouteRequest>* dns_queue = NULL;

int main(int argc, char **argv)
{
????//1 加載配置文件
????
????//2 啟動udp server服務,用來接收業務層(調用者/使用者)的消息
????start_UDP_servers();
????
????//3 啟動lars_reporter client 線程
????report_queue = new thread_queue<lars::ReportStatusRequest>();
????if (report_queue == NULL) {
????????fprintf(stderr, "create report queue error!\n");
????????exit(1);
????}
????start_report_client();
????
????//4 啟動lars_dns client 線程
????dns_queue = new thread_queue<lars::GetRouteRequest>();
????if (dns_queue == NULL) {
????????fprintf(stderr, "create dns queue error!\n");
????????exit(1);
????}
????start_dns_client();
????

????std::cout <<"done!" <<std::endl;
????while (1) {
????????sleep(10);
????}

????return 0;
}
```

06 lars-lbAgentV0.4-負載均衡上報提交模塊

這里我們分別在main()中 ,開啟以上線程。

?????????其中`report_client`線程需要攜帶`thread_queue<lars::ReportStatusRequest>`消息隊列通道。`agent`負責將上報請求消息`lars::ReportStatusRequest`通過thread_queue發送給reporter service。

?????????其中`dns_client`線程需要攜帶`thread_queue<lars::GetRouteRequest>`。`agent`負責將請求modid/cmdid的route消息`lars::GetRouteRequest`通過thread_queue發送給dns service。



3個udp server的線程開辟實現如下:

> lars_loadbalance_agent/src/agent_udp_server.cpp

```c
#include "lars_reactor.h"
#include "main_server.h"


void * agent_server_main(void * args)
{
????int *index = (int*)args;
????short port = *index + 8888;
????event_loop loop;

????udp_server server(&loop, "0.0.0.0", port);

????//TODO 給server注冊消息分發路由業務

????printf("agent UDP server :port %d is started...\n", port);
????loop.event_process();

????return NULL;
}

07 lars-lbAgentV0.4-數據問題修改-上報業務測試

void start_UDP_servers(void)
{
????for (int i = 0; i < 3; i ++) {
????????pthread_t tid;
????????
????????int ret = pthread_create(&tid, NULL, agent_server_main, &i);
????????if (ret == -1) {
????????????perror("pthread_create");
????????????exit(1);
????????}

????????pthread_detach(tid);

????}
}
```



reporter thread創建實現如下:

> lars_loadbalance_agent/src/reporter_client.cpp

```c
#include "lars_reactor.h"
#include "main_server.h"
#include <pthread.h>

void *report_client_thread(void* args)
{
????printf("report client thread start\n");
#if 0
????event_loop loop;

????//1 加載配置文件得到repoter ip + port
????std::string ip = config_file::instance()->GetString("reporter", "ip", "");
????short port = config_file::instance()->GetNumber("reporter", "port", 0);

????//2 創建客戶端
????tcp_client client(&loop, ip.c_str(), port, "reporter client");

????//3 將 thread_queue消息回調事件,綁定到loop中
????report_queue->set_loop(&loop);
????report_queue->set_callback()

????//4 啟動事件監聽
????loop.event_process();
#endif

????return NULL;
}

08 lars-lbAgentV0.4-模擬器測試工具

void start_report_client()
{
????//開辟一個線程
????pthread_t tid;

????//啟動線程業務函數
????int ret = pthread_create(&tid, NULL, report_client_thread, NULL);
????if (ret == -1) {
????????perror("pthread_create");
????????exit(1);
????}

????//設置分離模式
????pthread_detach(tid);
}
```



dns thread創建實現如下:

> lars_loadbalance_agent/src/dns_client.cpp

```c
#include "lars_reactor.h"
#include "main_server.h"
#include <pthread.h>

void *dns_client_thread(void* args)
{
????printf("dns client thread start\n");

????return NULL;
}

void start_dns_client()
{
????//開辟一個線程
????pthread_t tid;

????//啟動線程業務函數
????int ret = pthread_create(&tid, NULL, dns_client_thread, NULL);
????if (ret == -1) {
????????perror("pthread_create");
????????exit(1);
????}

????//設置分離模式
????pthread_detach(tid);
}
```

09 lars-lbAgentV0.5-idle連續成功-overload連續失敗的定期窗

口重置機制

### 2.3 測試lb_agentV0.1開發

編譯,然后我們簡單啟動一下`./bin/lars_lb_agent`

```bash
$ ./bin/lars_lb_agent?
dns client thread start
report client thread start
done!
msg_router init...
server on 0.0.0.0:8888 is running...
agent UDP server :port 8888 is started...
msg_router init...
server on 0.0.0.0:8888 is running...
agent UDP server :port 8888 is started...
msg_router init...
server on 0.0.0.0:8888 is running...
agent UDP server :port 8888 is started...
...
```
?

10 lars-lbAgentV0.6-loadbalance主動更新主機信息功能

## 3) Report Client設計與實現

?????????report client主要是實現thread_queue的回調業務,udp server會定期的上傳上報數據到reporter,那么請求對于report client就是透傳給reporter serivce即可。

> lars_loadbalance_agent/src/reporter_client.cpp

```c
#include "lars_reactor.h"
#include "main_server.h"
#include <string>
#include <pthread.h>

//typedef void io_callback(event_loop *loop, int fd, void *args);
//只要thread_queue有數據,loop就會觸發此回調函數來處理業務
void new_report_request(event_loop *loop, int fd, void *args)
{
????tcp_client *client = (tcp_client*)args;

????//1. 將請求數據從thread_queue中取出,
????std::queue<lars::ReportStatusRequest>??msgs;

????//2. 將數據放在queue隊列中
????report_queue->recv(msgs);
????
????//3. 遍歷隊列,通過client依次將每個msg發送給reporter service
????while (!msgs.empty()) {
????????lars::ReportStatusRequest req = msgs.front();
????????msgs.pop();

????????std::string requestString;
????????req.SerializeToString(&requestString);

????????//client 發送數據
????????client->send_message(requestString.c_str(), requestString.size(), lars::ID_ReportStatusRequest);
????}
}

11 昨日回顧

void *report_client_thread(void* args)
{
????printf("report client thread start\n");
????
????event_loop loop;

????//1 加載配置文件得到repoter ip + port
????std::string ip = config_file::instance()->GetString("reporter", "ip", "");
????short port = config_file::instance()->GetNumber("reporter", "port", 0);

????//2 創建客戶端
????tcp_client client(&loop, ip.c_str(), port, "reporter client");

????//3 將 thread_queue消息回調事件,綁定到loop中
????report_queue->set_loop(&loop);
????report_queue->set_callback(new_report_request, &client);

????//4 啟動事件監聽
????loop.event_process();

????return NULL;
}

12 Lars-LbAgentV0.7-GetRouteAPI實現

void start_report_client()
{
????//開辟一個線程
????pthread_t tid;

????//啟動線程業務函數
????int ret = pthread_create(&tid, NULL, report_client_thread, NULL);
????if (ret == -1) {
????????perror("pthread_create");
????????exit(1);
????}

????//設置分離模式
????pthread_detach(tid);
}
```



## 4) Dns Client設計與實現

?????????dns client 和report client的業務十分相似,只是針對的協議不同了。dns client的thread_queue 回調業務主要是透傳`lars::GetRouteRequest`數據包。

> lars_loadbalance_agent/src/dns_client.cpp

```c
#include "lars_reactor.h"
#include "main_server.h"
#include <pthread.h>


//typedef void io_callback(event_loop *loop, int fd, void *args);
//只要thread_queue有數據,loop就會觸發此回調函數來處理業務
void new_dns_request(event_loop *loop, int fd, void *args)
{
????tcp_client *client = (tcp_client*)args;

????//1. 將請求數據從thread_queue中取出,
????std::queue<lars::GetRouteRequest>??msgs;

????//2. 將數據放在queue隊列中
????dns_queue->recv(msgs);
????
????//3. 遍歷隊列,通過client依次將每個msg發送給reporter service
????while (!msgs.empty()) {
????????lars::GetRouteRequest req = msgs.front();
????????msgs.pop();

????????std::string requestString;
????????req.SerializeToString(&requestString);

????????//client 發送數據
????????client->send_message(requestString.c_str(), requestString.size(), lars::ID_GetRouteRequest);
????}

}

13 Lars-LbAgentV0.7-Udp-server-獲取路由服務業務注冊

void *dns_client_thread(void* args)
{
????printf("dns client thread start\n");
????event_loop loop;

????//1 加載配置文件得到dns service ip + port
????std::string ip = config_file::instance()->GetString("dnsserver", "ip", "");
????short port = config_file::instance()->GetNumber("dnsserver", "port", 0);

????//2 創建客戶端
????tcp_client client(&loop, ip.c_str(), port, "dns client");

????//3 將thread_queue消息回調事件,綁定到loop中
????dns_queue->set_loop(&loop);
????dns_queue->set_callback(new_dns_request, &client);

????//4 啟動事件監聽
????loop.event_process();?

????return NULL;
}


void start_dns_client()
{
????//開辟一個線程
????pthread_t tid;

????//啟動線程業務函數
????int ret = pthread_create(&tid, NULL, dns_client_thread, NULL);
????if (ret == -1) {
????????perror("pthread_create");
????????exit(1);
????}

????//設置分離模式
????pthread_detach(tid);
}
```

14 Lars-LbAgentV0.7-Udp-server-API和udpserver的測試

## 5) 負載均衡模塊基礎設計(V0.2)



### 5.1 基礎

?????????每個模塊`modid/cmdid`下有若干節點,節點的集合稱為此模塊的路由; 對于每個節點,有兩種狀態:

-?`idle`:此節點可用,可作為API**(相當于Agent的客戶端)**請求的節點使用;

-?`overload`:此節點過載,暫時不可作為API請求的節點使用

???????在請求節點時,有幾個關鍵屬性:

-?虛擬成功次數`vsucc`,API匯報節點調用結果是成功時,該值+1
-?虛擬失敗次數`verr`,API匯報節點調用結果是失敗時,該值+1
-?連續成功次數`contin_succ`,連續請求成功的次數
-?連續失敗次數`contin_err`,連續請求失敗的次數

這4個字段,在節點狀態改變時(idle<—>overload),會被重置。
?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/904225.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/904225.shtml
英文地址,請注明出處:http://en.pswp.cn/news/904225.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

領略算法真諦: 多源bfs

嘿&#xff0c;各位技術潮人&#xff01;好久不見甚是想念。生活就像一場奇妙冒險&#xff0c;而編程就是那把超酷的萬能鑰匙。此刻&#xff0c;陽光灑在鍵盤上&#xff0c;靈感在指尖跳躍&#xff0c;讓我們拋開一切束縛&#xff0c;給平淡日子加點料&#xff0c;注入滿滿的pa…

雷電模擬器-超好用的Windows安卓模擬器

一、雷電模擬器介紹 雷電模擬器是一款功能強大的軟件&#xff0c;它能夠在電腦上模擬出安卓手機系統&#xff0c;讓你可以在電腦上運行各類手機應用及游戲。其采用虛擬安卓手機操作界面&#xff0c;為玩家帶來了獨特的體驗。 &#xff08;一&#xff09;強大的兼容性 雷電模擬…

文章三《機器學習基礎概念與框架實踐》

文章3:機器學習基礎概念與框架實踐 ——從理論到代碼,用Scikit-learn構建你的第一個分類模型 一、機器學習基礎理論:三大核心類型 機器學習是人工智能的核心,通過數據讓計算機自動學習規律并做出預測或決策。根據學習方式,可分為三類: 1. 監督學習(Supervised Learni…

腦機接口技術:開啟人類與機器的全新交互時代

在科技飛速發展的今天&#xff0c;人類與機器的交互方式正經歷著前所未有的變革。從最初的鍵盤鼠標&#xff0c;到觸摸屏&#xff0c;再到語音控制&#xff0c;每一次交互方式的升級都極大地提升了用戶體驗和效率。如今&#xff0c;腦機接口&#xff08;Brain-Computer Interfa…

8.2 GitHub企業級PDF報告生成實戰:ReportLab高級技巧與性能優化全解析

GitHub企業級PDF報告生成實戰:ReportLab高級技巧與性能優化全解析 GitHub Sentinel 高級功能實現:PDF 報告生成技術詳解 關鍵詞:PDF 報告生成, ReportLab 實戰, 結構化數據轉換, 容器化字體配置, 企業級報告模板 1. 需求分析與技術選型 PDF 報告生成需要滿足以下技術要求…

架構思維:構建高并發讀服務_基于流量回放實現讀服務的自動化測試回歸方案

文章目錄 引言一、升級讀服務架構&#xff0c;為什么需要自動化測試&#xff1f;二、自動化回歸測試系統&#xff1a;整體架構概覽三、日志收集1. 攔截方式2. 存儲與優化策略3. 架構進化 四、數據回放技術實現關鍵能力 五、差異對比對比方式靈活配置 六、三種回放模式詳解1. 離…

基于Spring Boot 3.0、ShardingSphere、PostgreSQL或達夢數據庫的分庫分表

要實現基于Spring Boot 3.0、ShardingSphere、PostgreSQL或達夢數據庫的分庫分表&#xff0c;首先需要對ShardingSphere進行一些基本配置。你提到的溯源碼、批次號等數據需要考慮到跨年數據的存儲&#xff0c;因此要設計一個能夠動態擴展的分表策略 添加ShardingSphere依賴 在…

位運算的應用

1. 判斷偶數&#xff0c;判斷最低位是0還是1即可&#xff0c;?求模快 x % 2 ! 0 //x正負都可以判斷&#xff1b;不?x%2 1&#xff0c;因為如果x為負奇數&#xff0c;x%2-1 (x & 0x1) 0 例如&#xff1a; int x; int main() { cin>>x; if((x & 0x1)0) cout<…

FOC算法開環控制基礎

1. 為什么要有FOC算法 先看看從有刷電機到無刷電機的簡單介紹&#xff0c;如下圖1&#xff0c;通電螺線圈會產生磁場&#xff0c;這個磁場會產生N級和S級&#xff0c;然后這個電磁鐵就可以吸引永磁體&#xff0c;S級吸引N級&#xff0c;N級吸引S級&#xff0c;通俗的來說&…

【計算機網絡】HTTP中GET和POST的區別是什么?

從以下幾個方面去說明&#xff1a; 1.定義 2.參數傳遞方式 3.安全性 4.冪等性 1.定義&#xff1a; GET&#xff1a; 獲取資源&#xff0c;通常請求數據而不改變服務器的狀態。POST&#xff1a; 提交數據到服務器&#xff0c;通常會改變服務器的狀態或副作用(如創建或更新資源…

7400MB/s5050TBW完美結合,全新希捷酷玩530R SSD體驗評測

7400MB/s&5050TBW完美結合&#xff0c;全新希捷酷玩530R SSD體驗評測 哈嘍小伙伴們好&#xff0c;我是Stark-C~ 說到希捷酷玩530 SSD&#xff0c;很多硬核進階玩家應該都知道&#xff0c;或者說正在使用&#xff08;比如說我~&#xff09;。 作為希捷大廠旗下高性能SSD的…

(undone) MIT6.S081 2023 學習筆記 (Day11: LAB10 mmap)

url: https://pdos.csail.mit.edu/6.1810/2023/labs/mmap.html mmap和munmap系統調用允許UNIX程序對其地址空間進行精細控制。它們可用于進程間共享內存、將文件映射到進程地址空間&#xff0c;并作為用戶級頁面錯誤處理方案的一部分&#xff0c;例如課程中討論的垃圾回收算法。…

Q_OBJECT宏的作用

Qt 中&#xff0c;如果一個類中定義了信號&#xff08;signals&#xff09;或槽&#xff08;slots&#xff09;&#xff0c;那么這個類必須包含 Q_OBJECT 宏。 Q_OBJECT宏是 Qt 元對象系統的核心部分&#xff0c;它使得信號和槽機制能夠正常工作。 Q_OBJECT宏是 Qt 的元對象系統…

信息安全基石:加解密技術的原理、應用與未來

信息加解密技術是信息安全領域的核心技術之一&#xff0c;以下為你詳細介紹&#xff1a; 一、加密技術 1.定義&#xff1a;加密是通過特定的算法和密鑰&#xff0c;將原始的明文信息轉化為看似無意義的密文信息的過程。這一過程使得信息在傳輸、存儲等過程中&#xff0c;即使…

LeetCode:返回倒數第k個結點

1、題目描述 實現一種算法&#xff0c;找出單向鏈表中倒數第 k 個節點。返回該節點的值。 注意&#xff1a;本題相對原題稍作改動 示例&#xff1a; 輸入&#xff1a; 1->2->3->4->5 和 k 2 輸出&#xff1a; 4 說明&#xff1a; 給定的 k 保證是有效的。 2、…

R004 -計算機硬件基礎

目錄 1.數據表示&計算機網絡組成 2.計算機網絡分類 3.馮諾依曼體系結構 4.指令系統基礎 5.指令系統類型 6.流水線技術 流水線周期 &#xff1a;各流水段中&#xff0c;執行時間最長的那一段。就是T 流水線時間&#xff1a;t 1t2t 3 (n-1) * T 7.流水線指標 8.存儲系…

Mybatis學習(下)

目錄 1. 動態sql的應用 1.2 1.2 1.3 、 、 標簽 1.4 1. 動態sql的應用 使用Mybatis框架時, 對于sql數據的操作量比較大的時候, 看著會覺得很亂, 可能寫著寫著就亂了, 或者說回過頭來發現sql語句寫錯了, 很麻煩, 所以動態sql就可以讓我們用Java代碼, 替換部分sql語句 1.2 &l…

iview 老版本合并單元格

新版的iview中已經支持了合并單元格了&#xff0c;我的版本比較老&#xff0c;為&#xff1a;"iview": "^3.5.2"。暫不支持。記錄一下別的大佬的方法。感覺思路比較活&#xff0c;正在這種思路需要在解決問題的過程中學習。 核心思路&#xff1a;通過rende…

FGMRES(Flexible Generalized Minimal Residual)方法

FGMRES&#xff08;Flexible Generalized Minimal Residual&#xff09;方法是GMRES的變種&#xff0c;主要用于處理變預處理子&#xff08;即每次迭代的預處理子可能不同&#xff09;的情況。與標準GMRES相比&#xff0c;FGMRES通過存儲預處理后的向量而非預處理子本身&#x…

自主采集高質量三維重建數據集指南:面向3DGS與NeRF的圖像與視頻拍攝技巧【2025最新版!!】

一、? 引言 隨著三維重建技術的飛速發展&#xff0c;NeRF&#xff08;Neural Radiance Fields&#xff09;與 3D Gaussian Splatting&#xff08;3DGS&#xff09;等方法成為重建真實場景和物體幾何細節的前沿方案。這些方法在大規模場景建模、機器人感知、文物數字化、工業檢…