Skip to content

Commit d70546f

Browse files
committed
REFACTOR: refactor config file support for server configuration
1 parent 9e93d37 commit d70546f

File tree

4 files changed

+430
-30
lines changed

4 files changed

+430
-30
lines changed

arcus.conf

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
# ============================================================
2+
# Arcus-memcached Configuration File
3+
#
4+
# This file is used to configure the Arcus-memcached server at startup.
5+
#
6+
# Usage:
7+
# ./memcached -c arcus.conf
8+
# ./memcached -c arcus.conf -p 20000 (CLI options override config file settings)
9+
#
10+
# Format:
11+
# key=value
12+
# Lines starting with '#' are treated as comments.
13+
# ============================================================
14+
15+
16+
# [Required] Path to the storage engine library (.so).
17+
# This must be specified to start the server.
18+
# CLI Option: -E
19+
engine_path=.libs/default_engine.so
20+
#
21+
# TCP port number to listen on. (Default: 11211)
22+
# CLI Option: -p
23+
port=11211
24+
#
25+
# UDP port number to listen on. Set to 0 to disable. (Default: 11211)
26+
# CLI Option: -U
27+
udpport=11211
28+
#
29+
# The IP address of the network interface to listen on.
30+
# 0.0.0.0 means listen on all available interfaces (INADDR_ANY).
31+
# CLI Option: -l
32+
listen=0.0.0.0
33+
# Path to the UNIX socket file.
34+
# CLI Option: -s
35+
# socketpath=/tmp/memcached.sock
36+
#
37+
# Access mask for the UNIX socket in octal. (Default: 0700)
38+
# CLI Option: -a
39+
# access=0700
40+
#
41+
# Assume the identity of <username> (drops root privileges).
42+
# Effectively switches the user after starting.
43+
# CLI Option: -u
44+
# username=nobody
45+
#
46+
# Number of worker threads to process incoming requests. (Default: 4)
47+
# Typically set to the number of CPU cores.
48+
# CLI Option: -t
49+
threads=4
50+
#
51+
# Maximum number of simultaneous connections. (Default: 1024)
52+
# Connections exceeding this limit may be queued or rejected.
53+
# CLI Option: -c
54+
maxconns=1024
55+
#
56+
# Backlog queue limit for pending connections. (Default: 1024)
57+
# CLI Option: -b
58+
backlog=1024
59+
#
60+
# Maximum number of requests per event. (Default: 20)
61+
# Limits the number of requests processed for a given connection to prevent starvation.
62+
# CLI Option: -R
63+
reqs_per_event=20
64+
#
65+
# Maximum memory to use for item storage in MB. (Default: 64)
66+
# Suffixes like M (Megabytes) and G (Gigabytes) are supported (e.g., 2G).
67+
# CLI Option: -m
68+
memory_limit=64M
69+
#
70+
# Maximum size of a single item. (Default: 1m)
71+
# Supports K and M suffixes. Min: 1k, Max: 128m.
72+
# Adjusting this value also adjusts the slab page size.
73+
# CLI Option: -I
74+
item_size_max=1m
75+
#
76+
# Action to take when memory is exhausted. (Default: false)
77+
# false = Evict old items (LRU) to make space.
78+
# true = Return an error instead of evicting items.
79+
# CLI Option: -M (Equivalent to setting this to true)
80+
eviction=false
81+
#
82+
# Chunk size growth factor between slab classes. (Default: 1.25)
83+
# Controls the size increase of chunks in subsequent slab classes.
84+
# CLI Option: -f
85+
factor=1.25
86+
#
87+
# Minimum space allocated for key+value+flags. (Default: 48)
88+
# CLI Option: -n
89+
chunk_size=48
90+
#
91+
# Sticky (gummed) memory limit in MB. (Default: 0 - Unlimited)
92+
# Reserved memory for items that should not be evicted.
93+
# CLI Option: -g
94+
sticky_limit=0
95+
#
96+
# Use large memory pages if available. (Default: false)
97+
# Can improve performance by reducing TLB misses.
98+
# CLI Option: -L
99+
preallocate=false
100+
101+
# These options control the behavior of the Arcus storage engine,
102+
# including Collection features (List, Set, Map, B+Tree).
103+
#
104+
# Enable CAS (Check-And-Set) feature. (Default: true)
105+
# Ensures data consistency. Set to false to disable.
106+
# CLI Option: -C (Equivalent to setting this to false)
107+
use_cas=true
108+
#
109+
# Raw configuration string passed directly to the engine.
110+
# Format: param1=val1;param2=val2...
111+
# CLI Option: -e
112+
# engine_config=conf/default_engine.conf
113+
#
114+
# Maximum number of elements allowed in a collection.
115+
# Recommended to set below the default to avoid latency issues.
116+
# (Default: 50000, Min: 10000, Max: 1000000)
117+
max_list_size=50000
118+
max_set_size=50000
119+
max_map_size=50000
120+
max_btree_size=50000
121+
#
122+
# Maximum size of an element in bytes. (Default: 16KB, Min: 1KB, Max: 32KB)
123+
max_element_bytes=16KB
124+
#
125+
# Scrub count. (Default: 96, Min: 16, Max: 320)
126+
# Number of items to check per scrub iteration when cleaning up expired items.
127+
scrub_count=96
128+
#
129+
# Character to use as a delimiter for key prefixes in stats. (Default: :)
130+
# If specified, per-prefix stats collection is automatically enabled.
131+
# CLI Option: -D
132+
prefix_delimiter=:
133+
#
134+
# Enable detailed stats collection. (Default: false)
135+
# Automatically enabled if 'prefix_delimiter' is set.
136+
detail_enabled=false
137+
#
138+
# Allow the 'stats detail' command to be used. (Default: true)
139+
allow_detailed=true
140+
141+
# Run as a daemon (background process). (Default: false)
142+
# CLI Option: -d
143+
daemonize=false
144+
#
145+
# File to write the Process ID (PID) to when running as a daemon.
146+
# CLI Option: -P
147+
# pid_file=/var/run/memcached.pid
148+
#
149+
# Verbose logging level. (Default: 3)
150+
# 0 = Detail, 1 = Debug, 2 = Info, 3 = Warning
151+
# Higher values result in less logging.
152+
# CLI Option: -v, -vv, -vvv
153+
verbosity=3
154+
#
155+
# Limit the size of the core file. (Default: 0)
156+
# Used for debugging purposes to allow core dumps.
157+
# CLI Option: -r
158+
maxcore=0
159+
#
160+
# Lock down all paged memory. (Default: false)
161+
# Prevents memory from being swapped out, but may fail if system limit is exceeded.
162+
# CLI Option: -k
163+
lock_memory=false
164+
#
165+
# Path to the UNIX socket file (if used).
166+
# CLI Option: -s
167+
# socketpath=/tmp/memcached.sock
168+
#
169+
# Access mask for the UNIX socket in octal. (Default: 0700)
170+
# CLI Option: -a
171+
# access=0700
172+
#
173+
# Protocol to use (auto, binary, ascii). (Default: auto)
174+
# CLI Option: -B
175+
protocol=auto
176+
#
177+
# Enable data persistence. (Default: false)
178+
use_persistence=false
179+
#
180+
# Path for the snapshot file. (Default: ARCUS-DB)
181+
data_path=ARCUS-DB
182+
#
183+
# Path for the command log file. (Default: ARCUS-DB)
184+
logs_path=ARCUS-DB
185+
#
186+
# Load extension libraries (.so).
187+
# Used to load additional modules like loggers or management tools.
188+
# extension1=/usr/local/lib/logger.so
189+
# extension2=/usr/local/lib/management.so
190+
191+
# Settings required
192+
#
193+
# ZooKeeper ensemble server list.
194+
# Only available if compiled with ZooKeepr support.
195+
# Format: host1:port1,host2:port2,...
196+
# CLI Option: -z
197+
# zookeeper=zk1.local:2181,zk2.local:2181,zk3.local:2181
198+
#
199+
# ZooKeeper session timeout in milliseconds. (Default: 0 -> Uses internal default)
200+
# Only available if compiled with ZooKeepr support.
201+
# Recommended value: > 10 and < 20000 (check internal implementation limits).
202+
# CLI Option: -o
203+
# zk_timeout=3000
204+
#
205+
# Proxy configuration (if compiled with proxy support)
206+
# proxy_config=...
207+
#
208+
# Require SASL authentication for connections. (Default: false)
209+
# Only available if compiled with SASL support.
210+
# CLI Option: -S
211+
# require_sasl=false

config_parser.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
#include <memcached/config_parser.h>
2727
#include <memcached/util.h>
2828

29-
static int read_config_file(const char *fname, struct config_item items[],
30-
FILE *error);
31-
3229
/**
3330
* Copy a string and trim of leading and trailing white space characters.
3431
* Allow the user to escape out the stop character by putting a backslash before
@@ -224,8 +221,7 @@ int parse_config(const char *str, struct config_item *items, FILE *error) {
224221
return ret;
225222
}
226223

227-
static int read_config_file(const char *fname, struct config_item items[],
228-
FILE *error) {
224+
int read_config_file(const char *fname, struct config_item items[], FILE *error) {
229225
FILE *fp = fopen(fname, "r");
230226
if (fp == NULL) {
231227
(void)fprintf(error, "Failed to open file: %s\n", fname);

include/memcached/config_parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct config_item {
7777
*/
7878
MEMCACHED_PUBLIC_API int parse_config(const char *str, struct config_item items[], FILE *error);
7979

80+
int read_config_file(const char *fname, struct config_item items[], FILE *error);
8081
#ifdef __cplusplus
8182
}
8283
#endif

0 commit comments

Comments
 (0)