<file descriptor¿¡ ´ëÇÑ °Í>
(1) ¾ðÁ¦ file descriptor¸¦ º¯°æÇØ¾ß µÇ´ÂÁö?
- ¼ÒÄÏÀ» »ç¿ëÇÏ´Â multi-threaded ÇÁ·Î±×·¥ ȯ°æ¿¡¼ ¼ºñ½º ¿äûÀÌ µ¿½Ã¿¡
¸¹ÀÌ ¹ß»ýÇϸé, ¼ºñ½º¸¦ ó¸®ÇÏ´Â accept() ÇÔ¼ö°¡ ¿¡·¯¸¦
»Ñ·Á ÁÖ°Ô µÇÁö¿ä. ¾Æ·¡Ã³·³ ¸»ÀÌÁÒ.
"errno=24, Too many open files"
ÀÌ·± °æ¿ì µ¿½Ã¿¡ open() ÇÒ ¼ö ÀÖ´Â ÆÄÀÏ °¹¼öÀÇ Á¦ÇÑ ¶§¹®¿¡ º¯°æÀ»
ÇØ ÁÙ ÇÊ¿ä°¡ ÀÖÁö¿ä.
- system resource¸¦ Á¦ÇÑÇÒ ¼ö ÀÖ´Â °æ¿ì´Â ¾Æ·¡¿Í °°½À´Ï´Ù.
(per-user ¶Ç´Â per-process ¸¦ ±âÁØÀ¸·Î )
1> ÇÑ ÇÁ·Î¼¼½º¿¡ ÀÇÇØ ¸¸µé¾îÁú ¼ö ÀÖ´Â core file size
2> ÇÑ ÇÁ·Î¼¼½ºÀÇ Heap (process data segment)
3> ÇÑ ÇÁ·Î¼¼½º¿¡ ÀÇÇØ ¸¸µé¾îÁú ¼ö ÀÖ´Â file size
4> ÇÑ ÇÁ·Î¼¼½º°¡ »ý¼ºÇÒ ¼ö ÀÖ´Â file descriptors
5> ÇÑ ÇÁ·Î¼¼½ºÀÇ process stack segments
6> ÇÑ ÇÁ·Î¼¼½º°¡ ÃÊ´ç »ç¿ëÇÒ ¼ö ÀÖ´Â cpu time
7> ÇÑ ÇÁ·Î¼¼½ºÀÇ Virtual memory (mapped address space)
** #man getrlimit ÇØ º¸¸é resource definition Á¤º¸¸¦ º¸½Ç ¼ö ÀÖ½À´Ï´Ù.
(2) file descriptor¿¡ ´ëÇÑ ÀǹÌ
- À§ÀÇ 7°¡Áö °æ¿ìÁß¿¡¼ 4>¹ø file descriptors¸¸ÀÌ kernel tunable º¯¼ö·Î¼
Á¶Á¤ÀÌ °¡´ÉÇÕ´Ï´Ù. Áï /etc/system ÆÄÀÏÀ» »ç¿ëÇÏ´Â °æ¿ìÀÔ´Ï´Ù.
- osº°·Î limit °ªÀ» º¸¸é, ¾Æ·¡¿Í °°½À´Ï´Ù.
---------------------------------------------------------------------------------
os ver default(soft limit) default(hard limit) max(stdio) max(select())
---------------------------------------------------------------------------------
5.4~5.6 64 1024 256 1024
5.7(32bit) 64 1024 256 65535
5.7(64bit) 64 1024 256 65535
5.8(32bit) 256 1024 256 65535
5.8(64bit) 256 1024 256 65535
5.9(32bit) 256 65535 256 65535
5.9(64bit) 256 65535 256 65535
---------------------------------------------------------------------------------
** À§¿¡¼ 32bit ÀÎ °æ¿ì max(select())ÀÇ °æ¿ì´Â source code¿¡
¾Æ·¡ÀÇ lineÀ» Ãß°¡ÇÑ µÚ¿¡ recompileÀÌ ÇÊ¿äÇÕ´Ï´Ù.
> #define FD_SETSIZE 65535
#include <sys/select.h>
(¼³¸í)
- FD_SETSIZE : library file descriptor limit ÀÔ´Ï´Ù.
- library limit°ªÀÌ Á¶Á¤ÀÌ µÈ ÈÄ¿¡´Â systemÀÇ file descriptors
ÀÇ Á¶Á¤ÀÌ ÇÊ¿äÇÕ´Ï´Ù. ÀÌ °ªÀ» /etc/system¿¡ ¾Æ·¡Ã³·³
Ãß°¡ÇÏ´Â °Ì´Ï´Ù. ´ç¿¬È÷ reboot ÇÊ¿äÇÕ´Ï´Ù.
set rlim_fd_cur=1024
set rlim_fd_max=65535
- Berkeley stdio.h¸¦ ÀÌ¿ëÇÏ´Â °æ¿ì(fopen/fclose/fread/fwrite) per-process
´ç openÇÒ ¼ö ÀÖ´Â maximum fd °¹¼ö´Â 256 ÀÔ´Ï´Ù.
DB¼¹ö ³ª À¥¼¹ö°¡ ¾Æ´Ñ ´ëºÎºÐÀÇ application¿¡¼´Â 256 º¸´Ù Å©°Ô º¯°æÇÒ
ÇÊ¿ä°¡ ÀüÇô ¾ø½À´Ï´Ù. ¶§¶§·Î ÀÌ °ªÀÌ 1024º¸´Ù Å©°Ô ¼³Á¤ÇßÀ» °æ¿ì, select.h
ÇÔ¼ö¿¡ ¼±¾ðµÇ¾î ÀÖ´Â fd_set °°Àº structure °æ¿ì´Â maximum fd¸¦ 1023À¸·Î
°£ÁÖÇϱ⠶§¹®¿¡ ÀÌ ¹üÀ§¸¦ ¹þ¾î³ª´Â °æ¿ì memory spaceÀÇ ¹®Á¦°¡ ¾ß±â µË´Ï´Ù.
À§ÀÇ fd_set structure´Â select() ÇÔ¼ö¿¡ ÀÇÇؼ »ç¿ëÀÌ µË´Ï´Ù.
solaris 7,8 µîÀÇ °æ¿ì ÇöÀç µ¹°í ÀÖ´Â ÇÁ·Î¼¼½º¿¡ ´ëÇÑ hard/soft limit °ªÀ»
º¯°æÇÒ ¼ö ÀÖ½À´Ï´Ù. ¾Æ·¡Ã³·³ ¸»ÀÔ´Ï´Ù.
#plimit <pid> (ÇöÀç ¼³Á¤µÈ °ªÀ» È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù)
#plimit -n <soft>,<hard> <pid> (´Ü, soft limitÀº hard limit°ªÀ» ÃÊ°úÇÏ¸é ¾ÈµÊ)
(3) file descriptor º¯°æÇÏ´Â 3°¡Áö ¹æ¹ý
1) ulimit À» ÀÌ¿ëÇÏ´Â ¹æ¹ý
- ÀÌ ¹æ¹ýÀº ÇöÀç ½©¿¡¼ soft limit °ª¸¸À» º¯°æÇØ ÁÝ´Ï´Ù.
> default °ª : 64 (SunOS 5.8 ¹Ì¸¸ ¹öÁ¯)
> º¯°æ ¹üÀ§: hard limit °ª < º¯°æÇÒ °ª < default °ª(soft limit°ª)
- #ulimit -n <º¯°æÇÒ °ª>
2) setrlimit ÇÔ¼ö¸¦ »ç¿ëÇÏ´Â ¹æ¹ý
- ÀÌ ¹æ¹ýÀº hard and soft limit ¸ðµÎ º¯°æÀ» ÇÕ´Ï´Ù.
´Ü, hard limit º¯°æÀ» À§Çؼ root ±ÇÇÑÀÌ ÇÊ¿äÇÕ´Ï´Ù.
3) /etc/system ÆÄÀÏ¿¡ ³Ö¾î ÁÖ´Â ¹æ¹ý
- ÀÌ ¹æ¹ýÀº hard and soft limit ¸ðµÎ º¯°æÀ» ÇÕ´Ï´Ù.
- set rlim_fd_cur=4096
set rlim_fd_max=4096
ÀÌ·±½ÄÀ¸·Î ¼³Á¤ÇÏ´Â ¹æ¹ýÀÔ´Ï´Ù.
(ÀǹÌ)
> rlim_fd_max : ÇÑ ÇÁ·Î¼¼½º°¡ openÇÒ ¼ö ÀÖ´Â ÆÄÀÏÀÇ °¹¼ö
Hard Limit ÀÓ.
> rlim_fd_cur : ¸ðµç ½©¿¡¼ »ç¿ëÇÏ´Â ±âº»°ª
Soft limit ÀÓ.
#/etc/system
** 2°³ÀÇ ÆÄÀÏ ¸¶Áö¸· ¶óÀο¡ Ãß°¡ (º¯°æ°ª)
set rlim_fd_max=8192
set rlim_fd_cur=8192
-- È®ÀÎ
root@aqua# ulimit -a
time(seconds) unlimited
file(blocks) unlimited
data(kbytes) unlimited
stack(kbytes) 8192
coredump(blocks) unlimited
nofiles(descriptors) 8192
memory(kbytes) unlimited
root@MS6_TEMP # ulimit -Hn
8192
root@aqua#