最近在看memcached的源代碼,源碼包是memcached-1.4.22,一開始看memcached.c的main函數的時候發現了和1.2.8的不同之處。
可能在1.4.22版本之前就已經添加了這些功能,只是我是直接從1.2.8跳到1.4.22的,所以才會以為是新添加的。
這個不同之處就是可以在啟動的時候手動修改chunk大小的上限。具體見下面代碼:
case 'I': buf = strdup(optarg); unit = buf[strlen(buf)-1]; if (unit == 'k' || unit == 'm' || unit == 'K' || unit == 'M') { buf[strlen(buf)-1] = '\0'; size_max = atoi(buf); if (unit == 'k' || unit == 'K') size_max *= 1024; if (unit == 'm' || unit == 'M') size_max *= 1024 * 1024; settings.item_size_max = size_max; } else { settings.item_size_max = atoi(buf); } if (settings.item_size_max < 1024) { fprintf(stderr, "Item max size cannot be less than 1024 bytes.\n"); return 1; } if (settings.item_size_max > 1024 * 1024 * 128) { fprintf(stderr, "Cannot set item size limit higher than 128 mb.\n"); return 1; } if (settings.item_size_max > 1024 * 1024) { fprintf(stderr, "WARNING: Setting item max size above 1MB is not" " recommended!\n" " Raising this limit increases the minimum memory requirements\n" " and will decrease your memory efficiency.\n" ); }
從代碼可以看出,這里需要使用參數 -I 來帶入這個參數。
這個參數后面指定的數據格式是有限制的:純數字、單位為m(或M)、單位為k(或K)。
只能是這些格式的,其他的不能用,例如:
我想帶入的參數是2M,那么可以寫成
-I 2m 或 -I 2M ,
-I 2048k 或 -I 2048K ,
或者直接寫 2097152或2097152b或2097152B
不能使用其他單位的數據,比如g(或G)
任何非b、k、m的單位都會被理解為b
當你指定的數值大小超過1M的話會收到一條警告,告訴你這個大小是不被推薦的,但是設置依然會生效。
查看設置是否生效,可以使用命令:stats settings,顯示的最后一條“STAT item_size_max 2097152”就是生效的值。