Skip to content

Commit 6718ac1

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

File tree

4 files changed

+420
-30
lines changed

4 files changed

+420
-30
lines changed

arcus.conf

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
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. (Default: 0)
26+
# CLI Option: -U
27+
# udpport=0
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. (Default: 64)
66+
# CLI Option: -m
67+
memory_limit=64M
68+
#
69+
# Maximum size of a single item. (Default: 1m)
70+
# Supports K and M suffixes. Min: 1k, Max: 128m.
71+
# Adjusting this value also adjusts the slab page size.
72+
# CLI Option: -I
73+
item_size_max=1m
74+
#
75+
# Action to take when memory is exhausted. (Default: false)
76+
# false = Evict old items (LRU) to make space.
77+
# true = Return an error instead of evicting items.
78+
# CLI Option: -M (Equivalent to setting this to true)
79+
eviction=false
80+
#
81+
# Chunk size growth factor between slab classes. (Default: 1.25)
82+
# Controls the size increase of chunks in subsequent slab classes.
83+
# CLI Option: -f
84+
factor=1.25
85+
#
86+
# Minimum space allocated for key+value+flags. (Default: 48)
87+
# CLI Option: -n
88+
chunk_size=48
89+
#
90+
# Sticky (gummed) memory limit in MB. (Default: 0 - Unlimited)
91+
# Reserved memory for items that should not be evicted.
92+
# CLI Option: -g
93+
sticky_limit=0
94+
#
95+
# Use large memory pages if available. (Default: false)
96+
# Can improve performance by reducing TLB misses.
97+
# CLI Option: -L
98+
preallocate=false
99+
100+
# These options control the behavior of the Arcus storage engine,
101+
# including Collection features (List, Set, Map, B+Tree).
102+
#
103+
# Enable CAS (Check-And-Set) feature. (Default: true)
104+
# Ensures data consistency. Set to false to disable.
105+
# CLI Option: -C (Equivalent to setting this to false)
106+
use_cas=true
107+
#
108+
# Raw configuration string passed directly to the engine.
109+
# Format: param1=val1;param2=val2...
110+
# CLI Option: -e
111+
# engine_config=conf/default_engine.conf
112+
#
113+
# Maximum number of elements allowed in a collection.
114+
# Recommended to set below the default to avoid latency issues.
115+
# (Default: 50000, Min: 10000, Max: 1000000)
116+
max_list_size=50000
117+
max_set_size=50000
118+
max_map_size=50000
119+
max_btree_size=50000
120+
#
121+
# Maximum size of an element in bytes. (Default: 16KB, Min: 1KB, Max: 32KB)
122+
max_element_bytes=16KB
123+
#
124+
# Scrub count. (Default: 96, Min: 16, Max: 320)
125+
# Number of items to check per scrub iteration when cleaning up expired items.
126+
scrub_count=96
127+
#
128+
# Character to use as a delimiter for key prefixes in stats. (Default: :)
129+
# If specified, per-prefix stats collection is automatically enabled.
130+
# CLI Option: -D
131+
prefix_delimiter=:
132+
#
133+
# Enable detailed stats collection. (Default: false)
134+
# Automatically enabled if 'prefix_delimiter' is set.
135+
detail_enabled=false
136+
#
137+
# Allow the 'stats detail' command to be used. (Default: true)
138+
allow_detailed=true
139+
140+
# Run as a daemon (background process). (Default: false)
141+
# CLI Option: -d
142+
daemonize=false
143+
#
144+
# File to write the Process ID (PID) to when running as a daemon.
145+
# CLI Option: -P
146+
# pid_file=/var/run/memcached.pid
147+
#
148+
# Verbose logging level. (Default: 3)
149+
# 0 = Detail, 1 = Debug, 2 = Info, 3 = Warning
150+
# Higher values result in less logging.
151+
# CLI Option: -v, -vv, -vvv
152+
verbosity=3
153+
#
154+
# Limit the size of the core file. (Default: 0)
155+
# Used for debugging purposes to allow core dumps.
156+
# CLI Option: -r
157+
maxcore=0
158+
#
159+
# Lock down all paged memory. (Default: false)
160+
# Prevents memory from being swapped out, but may fail if system limit is exceeded.
161+
# CLI Option: -k
162+
lock_memory=false
163+
#
164+
# Path to the UNIX socket file (if used).
165+
# CLI Option: -s
166+
# socketpath=/tmp/memcached.sock
167+
#
168+
# Access mask for the UNIX socket in octal. (Default: 0700)
169+
# CLI Option: -a
170+
# access=0700
171+
#
172+
# Protocol to use (auto, binary, ascii). (Default: auto)
173+
# CLI Option: -B
174+
protocol=auto
175+
#
176+
# Load extension libraries (.so).
177+
# Used to load additional modules like loggers or management tools.
178+
# extension1=/usr/local/lib/logger.so
179+
# extension2=/usr/local/lib/management.so
180+
181+
# Settings required
182+
#
183+
# ZooKeeper ensemble server list.
184+
# Only available if compiled with ZooKeepr support.
185+
# Format: host1:port1,host2:port2,...
186+
# CLI Option: -z
187+
# zookeeper=zk1.local:2181,zk2.local:2181,zk3.local:2181
188+
#
189+
# ZooKeeper session timeout in milliseconds. (Default: 0 -> Uses internal default)
190+
# Only available if compiled with ZooKeepr support.
191+
# Recommended value: > 10 and < 20000 (check internal implementation limits).
192+
# CLI Option: -o
193+
# zk_timeout=3000
194+
#
195+
# Proxy configuration (if compiled with proxy support)
196+
# proxy_config=...
197+
#
198+
# Require SASL authentication for connections. (Default: false)
199+
# Only available if compiled with SASL support.
200+
# CLI Option: -S
201+
# 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)