主从同步性能优化,主从同步性能测试。

This commit is contained in:
1iaan
2026-02-01 16:49:50 +00:00
parent 003566b69a
commit 6d1a50cf88
31 changed files with 2119 additions and 400 deletions

View File

@@ -58,6 +58,7 @@ static void set_default_config(AppConfig *cfg)
cfg->persistence = PERSIST_NONE;
cfg->allocator = ALLOC_JEMALLOC;
cfg->leak_mode = MEMLEAK_DETECT_OFF;
cfg->replica_mode = REPLICA_DISABLE;
}
/* ---- 字符串转枚举 ---- */
@@ -103,6 +104,14 @@ static void parse_leakage(const char *s, MemLeakDetectMode *out)
else *out = MEMLEAK_DETECT_OFF;
}
static void parse_replica(const char *s, ReplicaMode *out)
{
if (!s || !out) return;
if (!strcasecmp(s, "enable")) *out = REPLICA_ENABLE;
else if (!strcasecmp(s, "disable")) *out = REPLICA_DISABLE;
else *out = REPLICA_DISABLE;
}
static int read_file_mmap(const char *filename, void **out_addr, size_t *out_len, int *out_fd) {
if (!filename || !out_addr || !out_len || !out_fd) return -1;
@@ -199,6 +208,16 @@ const char *leakage_to_string(MemLeakDetectMode a)
}
}
const char *replica_to_string(ReplicaMode a)
{
switch (a) {
case MEMLEAK_DETECT_ON: return "enable";
case MEMLEAK_DETECT_OFF: return "disable";
default: return "unknown";
}
}
/* ---- 主函数:从 XML 加载配置 ---- */
/* server 部分 */
@@ -236,6 +255,15 @@ void server_load(xmlNodePtr *root, AppConfig *out_cfg){
}
}
xmlNodePtr replica_node = find_child(server, "replica");
if (replica_node) {
xmlChar *txt = xmlNodeGetContent(replica_node);
if (txt) {
parse_replica((char *)txt, &out_cfg->replica_mode);
xmlFree(txt);
}
}
/* master (always read if present) */
xmlNodePtr master = find_child(server, "master");
if (master) {

View File

@@ -20,6 +20,11 @@ typedef enum {
PERSIST_NONE
} PersistenceType;
typedef enum {
REPLICA_DISABLE,
REPLICA_ENABLE
}ReplicaMode;
// typedef enum {
// ALLOC_JEMALLOC,
// ALLOC_MALLOC,
@@ -51,6 +56,7 @@ typedef struct {
AllocatorType allocator;
MemLeakDetectMode leak_mode;
ReplicaMode replica_mode;
} AppConfig;
/**
@@ -64,5 +70,7 @@ const char *server_mode_to_string(ServerMode mode);
const char *persistence_to_string(PersistenceType p);
const char *allocator_to_string(AllocatorType a);
const char *leakage_to_string(MemLeakDetectMode a);
const char *replica_to_string(ReplicaMode a);
#endif /* CONFIG_H */