-
Notifications
You must be signed in to change notification settings - Fork 58
FEATURE: Refactor config file support for server configuration #945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a20ccb4 to
bd65692
Compare
jhpark816
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฆฌ๋ทฐ ์๋ฃ
memcached.c
Outdated
| settings.username = strdup(optarg); | ||
| break; | ||
| case 'P': | ||
| FREE_CFGFILE_VAL(settings.pid_file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FREE_CFGFILE_VAL() ๋งคํฌ๋ก๊ฐ ํ์ํ ์ด์ ๊ฐ ์ดํด๋์ง ์๋ ๋ฐ, ์ค๋ช
๋ฐ๋๋๋ค.
์ฐธ๊ณ ๋ก, ์์ settings.username ์ฒ๋ผ free ํ๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ฐธ๊ณ ๋ก, ์์ settings.username ์ฒ๋ผ free ํ๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค.
๊ธฐ์กด์ optarg ๊ทธ๋๋ก ์ฌ์ฉํ๋ ๋์ strdup()์ผ๋ก ๋ฉ๋ชจ๋ฆฌ ํ ๋น๋ฐ๋๋ก ๋ณ๊ฒฝํ๋๋ฐ,
์ข
๋ฃํ ๋ settings.username free ํ๋ ๋ก์ง ๋น ์ง ๊ฒ์ผ๋ก ๋ณด์
๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FREE_CFGFILE_VAL() ๋งคํฌ๋ก๊ฐ ํ์ํ ์ด์ ๊ฐ ์ดํด๋์ง ์๋ ๋ฐ, ์ค๋ช ๋ฐ๋๋๋ค.
์ฐธ๊ณ ๋ก, ์์ settings.username ์ฒ๋ผ free ํ๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค.
๊ฐ์ ๊ตฌ๋ ์ต์
์ด ์ฌ๋ฌ ๋ฒ ์ ๋ฌ๋๋ ๊ฒฝ์ฐ๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ํ ์ฝ๋์
๋๋ค.
config ํ์ผ ๊ธฐ๋ฅ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ settings.pid_file์๋ ๋ฉ๋ชจ๋ฆฌ ํ ๋น๋ ๊ฐ์ด ์ ์ฅ๋์ง๋ง, ๊ธฐ์กด ๊ตฌ๋ ์ต์
์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ์๋ optarg์ ์ฃผ์๋ฅผ ๊ทธ๋๋ก ๊ฐ๋ฆฌํค๊ฒ ๋ฉ๋๋ค.
์ด ์ํ์์ ๋์ผํ ๊ตฌ๋ ์ต์
์ ์ฌ๋ฌ ๋ฒ ์ฌ์ฉํ๋ฉด(memcached -P ./pidfile1 -P ./pidfile2 ...), ํด๋น ๊ฐ์ freeํ๋ฉด ์ ๋๋ ์ํฉ์ด ๋ฐ์ํ๋ฏ๋ก ์ด๋ฅผ ๋ฐฉ์งํ๊ธฐ ์ํด ์์ ๋งคํฌ๋ก๊ฐ ํ์ํฉ๋๋ค.
๊ธฐ์กด์ optarg ๊ทธ๋๋ก ์ฌ์ฉํ๋ ๋์ strdup()์ผ๋ก ๋ฉ๋ชจ๋ฆฌ ํ ๋น๋ฐ๋๋ก ๋ณ๊ฒฝํ๋๋ฐ,
์ข ๋ฃํ ๋ settings.username free ํ๋ ๋ก์ง ๋น ์ง ๊ฒ์ผ๋ก ๋ณด์ ๋๋ค.
settings.username๋ง ์๋ arcus_proxy_cfg ์ชฝ๋ ๋น ์ ธ์์ต๋๋ค. ํ์ฌ PR์์๋ ์ด๋ฅผ ๋ณ๋๋ก ์ฒ๋ฆฌํ์ง ์์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋ ๋ ๊ฐ์ง ํจํด์ ์ฌ์ฉํ๊ณ ์๋๋ฐ, ๊ตฌ๋ถ ๊ธฐ์ค์ ๋ฌด์์ธ๊ฐ์?
FREE_CFGFILE_VAL์ฌ์ฉํ๋ ๊ฒฝ์ฐstrdup+free์ฌ์ฉํ๋ ๊ฒฝ์ฐ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋ ๋ ๊ฐ์ง ํจํด์ ์ฌ์ฉํ๊ณ ์๋๋ฐ, ๊ตฌ๋ถ ๊ธฐ์ค์ ๋ฌด์์ธ๊ฐ์?
์ ํํ ์ฌํญ์ ๋ชจ๋ฆ
๋๋ค.
์ธ๋ถ API๋ก ํด๋น ์ฃผ์ ๊ณต๊ฐ์ ๋๊ธฐ๋ ๊ฒฝ์ฐ, strdup์ ์ด ๊ฒ์ผ๋ก ์ถ์ ํ๊ณ ์์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด์ ์ฝ๋ฉํธ์์ ์ง๋ฌธ์ ๋ชจํธํ๊ฒ ํ๋๋ฐ, ๊ธฐ์กด ๊ตฌํ๊ณผ ๋ณ๊ฐ๋ก
์ด๋ฒ PR์์ optarg๋ฅผ ๊ทธ๋๋ก ์ฌ์ฉํ๋ ์ต์
์ ๋ชจ๋ FREE_CFGFILE_VAL์ผ๋ก ๋ณ๊ฒฝํ์๋๋ฐ
username๋ง ์์ธ๋ก strdup() ์ฌ์ฉํ ์ด์ ๋ฅผ ๋ฌผ์ผ๋ ค๋ ๊ฒ์ด์์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
username ์ชฝ์ strdup ์ฒ๋ฆฌ๊ฐ ๋ค์ด๊ฐ ์๋ ์ง ๋ชฐ๋์ต๋๋ค.
ํ์ฌ๋ ์์ ์๋ฃ๋์์ต๋๋ค.
7faba24 to
b2570e2
Compare
38b8dbe to
7c5e437
Compare
7c5e437 to
b0f4957
Compare
|
@ing-eoking |
|
PR๋ณ๊ฒฝ์ด ์์ด์ ์ ์ draft๋ก ๋์์ต๋๋ค draft ํด์ ํ์ต๋๋ค. |
jhpark816
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฆฌ๋ทฐ ์๋ฃ
memcached.c
Outdated
| } | ||
| } | ||
|
|
||
| #define EXTENSION_PATH_MAX_SIZE 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด ๊ฐ์ 5์ด์ด๋ ์ถฉ๋ถํ ๊ฒ ๊ฐ์ต๋๋ค.
memcached.c
Outdated
|
|
||
| static int load_config_file(const char *path) | ||
| { | ||
| int ret = EXIT_SUCCESS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EXIT_XXXX ์ฝ๋์ EX_XXXX ์ฝ๋๊ฐ ํผ์ฉ๋์ด ์ฌ์ฉ๋๋ ๋ฐ์.
์ฑ๊ณตํ๋ฉด 0, ์คํจํ๋ฉด -1์ ๋ฆฌํดํ๋ ๊ฒ์ด ๊ฐ๋จํ ๊ฒ ๊ฐ์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
binding protocol ์๋ฌ์ ๊ฒฝ์ฐ EX_USAGE, ๊ทธ ์ธ์ ๊ฒฝ์ฐ๋ EXIT_FAILURE๋ก ์ข ๋ฃํ๊ณ ์์ต๋๋ค.
binding protocol์๋ฌ๋ -2, ๊ทธ ์ธ์ ๊ฒฝ์ฐ๋ -1์ ๋ฐํํ๋๋ก ๋ณ๊ฒฝํ๊ฒ ์ต๋๋ค.
memcached.c
Outdated
| uint32_t cache_memory_limit = settings.maxbytes / (1024 * 1024); | ||
| #ifdef ENABLE_STICKY_ITEM | ||
| uint32_t sticky_memory_limit = settings.sticky_limit / (1024 * 1024); | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cache_memory_limit๊ณผ sticky_memory_limit์ 0์ ์ด๊ธฐ ๊ฐ์ผ๋ก ๊ฐ์ ธ๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cache_memory_limit์ sticky_memory_limit ๊ฐ์ 0์ผ๋ก ์ค์ ํ๋ฉด,
config ํ์ผ์์ ํด๋น ๊ฐ๋ค์ด ๋ณ๋๋ก ํ ๋น๋์ง ์๋๋ผ๋ ๊ธฐ๋ณธ๊ฐ์ด ์๋ 0์ผ๋ก ๋ฐ๋๊ฒ ๋ฉ๋๋ค.
๊ธฐ๋ณธ๊ฐ์ ์๋์ฒ๋ผ ๋ช ์์ ์ผ๋ก ์ค์ ํ ์๋ ์์ง๋ง, ํน์ ํฅํ ๊ธฐ๋ณธ๊ฐ์ด ๋ณ๊ฒฝ๋ ๊ฐ๋ฅ์ฑ์ ๊ณ ๋ คํ์ฌ ํ์ฌ์ ๊ฐ์ด ๊ตฌํํ์ต๋๋ค.
uint32_t cache_memory_limit = 64;
#ifdef ENABLE_STICKY_ITEM
uint32_t sticky_memory_limit = 0;
#endif๋ค๋ฅธ ํํ๋ฅผ ์ํ์ ๋ค๋ฉด ์๋ ํํ๋ ๊ฐ๋ฅํฉ๋๋ค.
#define DEFAULT_MEMORY_LIMIT 64
#define DEFAULT_STICKY_LIMIT 0
...
static void settings_init(void)
{
...
settings.maxbytes = DEFAULT_MEMORY_LIMIT * 1024 * 1024;
settings.sticky_limit = DEFAULT_STICKY_LIMIT * 1024 * 1024;
}
static int load_config_file(const char *path)
{
uint32_t cache_memory_limit = DEFAULT_MEMORY_LIMIT;
#ifdef ENABLE_STICKY_ITEM
uint32_t sticky_memory_limit = DEFAULT_STICKY_LIMIT;
#endif
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cache_memory_limit์ sticky_memory_limit๋ ๋ก์ปฌ ๋ณ์์ธ ๋ฐ,
์ด์ ๋ํด ํน๋ณํ ์ด๊ธฐ ๊ฐ์ ์ค์ ํ๋ ๊ฒ ๋ณด๋ค ์๋ ํํ์ ์ฝ๋๊ฐ ์ข๊ฒ ์ต๋๋ค.
static int load_config_file(const char *path)
{
uint32_t cache_memory_limit = 0;
#ifdef ENABLE_STICKY_ITEM
uint32_t sticky_memory_limit = 0;
#endif
. . .
if (cache_memory_limit > 0) {
settings.maxbytes = (size_t)cache_memory_limit * 1024 * 1024;
}
#ifdef ENABLE_STICKY_ITEM
if (sticky_memory_limit > 0) {
settings.sticky_limit = (size_t)sticky_memory_limit * 1024 * 1024;
}
#endif
}b0f4957 to
d4efac0
Compare
4e4d057 to
a7f7913
Compare
jhpark816
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ผ๋ถ ๋ฆฌ๋ทฐ
a7f7913 to
c245ed4
Compare
| # ----------------------------------------------------------------------------- | ||
| # Maximum memory to use for item storage. (Default: 64M) | ||
| # Use suffixes: K, M, G, T (case-insensitive) | ||
| memory_limit=64M |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ฌ๊ธฐ๋ ๋จ์๊ฐ ํฌํจ๋ฉ๋๋ค.
๋ฐ๋ฉด, ๊ตฌ๋ ์ต์
์ผ๋ก ์ฝ์ ๋๋ ๋จ์๋ฅผ MB๋ก ์ธ์ํ๊ณ ์๋ ๋ฐ, ์ด ๋ถ๋ถ์ด ์ด์ํ ๊ฒ์ด๊ตฐ์.
์ฌ๊ธฐ ๋จ์๋ฅผ ํฌํจํ์ฌ ์ฝ๋๋ค๋ฉด, settings.maxbytes๋ก ๋ฐ๋ก ์ฝ์ด ๋ค์ฌ๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค.
sticky_limit ์ง์ ์์๋ ๋จ์๋ฅผ ์ง์ ํ๋ ๊ฒ์ผ๋ก ํ๊ตฌ์.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ing-eoking @namsic
์ฌ๊ธฐ ์ค์ ๊ณผ ์๋ load_config_file() ์ฝ๋๋ฅผ ๋ณด๋ฉด,
์ด๋ ๊ฒ ์ค์ ํ ๊ฒ์ผ๋ก ํ
์คํธ๋ฅผ ํ๋ฒ๋ ์ ํด ๋ณธ ๊ฒ ๊ฐ์๋ฐ์. ์ด๋ค๊ฐ์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memory_limit์ ๋ํ ์ค๋ช ์ด ํด๋น ๋ด์ฉ์ผ๋ก ์ฐ์ฌ์๋ ์ง ๋ชฐ๋์ต๋๋ค.
ํ์ฌ ํ
์คํธ๋ ๋ด๋ถ ๊ฐ๊น์ง ๋ชจ๋ ๊ฒ์ฆํ๊ณ ์์ง๋ ์๊ณ ,
์ค์ ํ์ผ๋ก ๋์์ํจ ๋ค ๊ด๋ จ ๋ช
๋ น์ด๊ฐ ์ ์์ ์ผ๋ก ๋์ํ๋์ง ์ ๋๋ง ํ์ธํ๊ณ ์์ต๋๋ค.
์ดํ ํ
์คํธ๋ stats settings๋ฅผ ํตํด ์ถ๋ ฅ๋ ๊ฐ๋ค์ด ์ค์ ์ค์ ๊ฐ๊ณผ ์ผ์นํ๋์ง๊น์ง ํ์ธํ๋๋ก ํ
์คํธ๋ฅผ ๋ณด์ํ๊ฒ ์ต๋๋ค.
๊ธฐ์กด ๊ตฌ๋ ์ต์
๋ฐ config ๋ช
๋ น์ด๋ฅผ ํตํด ์ค์ ํ ์ ์๋ memory_limit๊ณผ sticky_limit ๊ฐ์ด ๋ชจ๋ MB ๋จ์์ด๊ธฐ ๋๋ฌธ์,
ํ์ฌ ๊ตฌํ ๋ฐฉ์๋๋ก ๋์ํ๋ ๊ฒ์ด ๋ง๋ค๊ณ ์๊ฐ๋๋ฉฐ, ์ค๋ช
์ sticky_limit๊ณผ ๋์ผํ๊ฒ ๋ณ๊ฒฝํ๋ ํธ์ด ์ข์ ๊ฒ์ผ๋ก ์๊ฐ๋ฉ๋๋ค.
# Sticky (gummed) memory limit in MB. (Default: 0 - Unused)
# Reserved memory for items that should not be evicted.
# sticky_limit=0
ํํธ config_parser์์๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋จ์(k, m, g, t)๋ฅผ ์ง์ํ๊ณ ์์ด, ์ซ์ ํํ์ ๊ฐ์ ์ฝ์ด๋ค์ผ ๋ ๋จ์๋ฅผ ํจ๊ป ์ฝ๋ ๊ฒ์ด ๊ฐ์ ๋ฉ๋๋ค. ์ด ๊ฒฝ์ฐ ์๋ฅผ ๋ค์ด 64M๋ฅผ ์ค์ ํ๋ฉด ์ค์ ๋ด๋ถ ๊ฐ์ 64T๋ก ํด์๋์ด ์ฌ์ฉ๋ฉ๋๋ค.
cache_size=70368744177664
memory_limit ๊ฐ์ MB ๋จ์(1024 * 1024)๋ก ๋ณํํ์ง ์๊ณ ์ซ์ ๊ทธ๋๋ก ์ฒ๋ฆฌํ๋๋ก ๊ตฌํํ ๊ฒฝ์ฐ, ์ค์ ํ์ผ์ 1024 * 1024๋ณด๋ค ์์ ๊ฐ์ ์ง์ ํ๋ฉด ๋ด๋ถ์ ์ผ๋ก๋ ํด๋น ๊ฐ์ด ๊ทธ๋๋ก ์ค์ ๋ฉ๋๋ค.
ํ์ง๋ง config ๋ช
๋ น์ด์์๋ ๊ฐ์ 1024 * 1024๋ก ๋๋์ด ์ถ๋ ฅํ๊ธฐ ๋๋ฌธ์, ๊ฒฐ๊ณผ์ ์ผ๋ก 0์ผ๋ก ํ์๋๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๊ฒ ๋ฉ๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxbytes ์ค์ ์ ์ต์ข ๋ฐฉ์์ ๊ฒฐ์ ํ์ฌ ์๋ ค์ฃผ์ธ์.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config ํ์ผ์์ MB ๋จ์๋ก ๊ฐ์ ์ง์ ํ์ง ์์ ๊ฒฝ์ฐ, Warning ์ฑ๊ฒฉ์ ๋ก๊ทธ ๋ฉ์์ง๋ง ๋จ๊ธฐ๋๋ก ๋ณ๊ฒฝํ์ต๋๋ค.
c35f177 to
622d768
Compare
60c3cb6 to
7dcf3be
Compare
jhpark816
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฆฌ๋ทฐ ์๋ฃ
a7fda32 to
2719eb8
Compare
2719eb8 to
0ec139c
Compare
|
@namsic ์ต์ข ๋ฆฌ๋ทฐ๋ง ํ๋ฒ ํด ์ฃผ์ธ์. |
|
@ing-eoking |
๐ Related Issue
โจ๏ธ What I did
๊ธฐ์กด์ engine ์ค์ ๋ง ๊ฐ๋ฅํ๋ config file ์ค์ ๊ธฐ๋ฅ์ ํ์ฅํ์ฌ, engine์ธ์ ๋ค๋ฅธ ์ค์ ๋ ํ์ผ ํํ๋ก ๊ฐ๋ฅํ๊ฒ ํ๋๋ก ํฉ๋๋ค.
(
-e config_file=/config_file1.conf)(๋๋ถ๋ถ์ ํ๋ก๊ทธ๋จ์์ ์ฐจ์ฉํ๋ ๋ฐฉ์)
main()์คํ์, ๊ตฌ๋์ต์ ์ ํ์ธํ๊ธฐ ์ ์ ์ฒซ๋ฒ์งธ ์ธ์๋ฅผ config file๊ฒฝ๋ก๋ฅผ ์ธ์ํ๋๋ก ๊ธฐ๋ฅ์ ํ์ฅํฉ๋๋ค.try_load_config_file()์ ๊ตฌํํ์ฌ,.confํ์ผ์ ๋ผ์ธ ๋จ์๋ก ์ฝ์ด์ ๋ชจ๋ ๊ฐ์ ์ค์ ํฉ๋๋ค.getopt์optind๋ฅผ ๋์ ์ผ๋ก ์กฐ์ ํ์ฌ config file๊ณผ ๊ตฌ๋์ต์ ์ ํผ์ฉํ ๋, ๊ตฌ๋ ์ต์ ๊ฐ์ด ๋ฎ์ด์์ด์ง๋๋ก ํฉ๋๋ค.https://github.com/jam2in/arcus-works/issues/808 ๋ฅผ ํตํ
old_opts์ค๋ณต ํด๊ฒฐgetopt(๊ตฌ๋์ต์ ๊ฐ ์ค์ )๋ฃจํ ๋ด์์settings์ ์ญ ๊ตฌ์กฐ์ฒด์old_opts๋ฌธ์์ด ์์ฑ์ ๋์์ ์ํํ๊ธฐ์, config file๊ณผ ๊ตฌ๋์ต์ ์ ๋์์ ์ํํ๋ฉดold_opts์ ์ค๋ณต๋ ๊ฐ์ด ๋ค์ด๊ฐ์ต๋๋ค.settings์ ์ญ ๊ตฌ์กฐ์ฒด๋ง ์ ๋ฐ์ดํธ๋ฅผ ์ํํ๊ณ , ํ์ฑ์ดํ์old_opts๋ฌธ์์ด์ ์์ฑํ๋๋ก ํ์ต๋๋ค.