====== Linux Performance ====== * [[linux:perf|perf]] * [[https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Performance_Tuning_Guide/index.html|Performance Tuning Guide - Red Hat Customer Portal]] [[http://happy20hours.blogspot.kr/2012/09/linux-performance-and-tuning-guidelines.html|한국어 요약]] * [[https://access.redhat.com/site/documentation/ko-KR/Red_Hat_Enterprise_Linux/6/pdf/Performance_Tuning_Guide/Red_Hat_Enterprise_Linux-6-Performance_Tuning_Guide-ko-KR.pdf|Redhat 6 Performance Tuning Guide]] * [[http://www.slideshare.net/brendangregg/linux-performance-analysis-and-tools|Linux Performance analysis and tools]] * [[http://www.cyberciti.biz/programming/linux-memory-forensics-analysis-tools/|Top 8 Tools For Linux / Unix Memory Forensics Analysis]] * [[http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html|Top Linux System monitoring tools]] ===== CPU Frequency 조정 ===== [[linux:cpufreq|Linux CPU Frequency]]를 참조한다. ===== swap 명령 ===== * [[http://www.cyberciti.biz/faq/linux-check-swap-usage-command/|HowTo: Check Swap Usage in Linux]] ===== swappiness ===== 메모리를 스왑 영역으로 옮기는 비율을 정한다. 0~100 까지 정할 수 있으며, 0이면 거의 스왑을 사용하지 않다가 어쩔 수 없을 때 스왑을 사용한다. /etc/sysctl.conf 파일에 다음 값으로 지정한다. 기본값은 거의 60이다. vm.swappiness=5 명령행에서 일시적 지정은 sudo sysctl vm.swappiness=5 cat /proc/sys/vm/swappiness # 확인 http://ubuntu.or.kr/wiki/doku.php?id=%EB%AA%A9%EC%B0%A8:vm.swap_%EC%A1%B0%EC%A0%95%ED%95%98%EA%B8%B0 혹은 ''/etc/fstab''에서 swap 파티션을 주석처리하고 재부팅하여 아예 꺼버릴 수도 있다. [[https://askubuntu.com/questions/214805/how-do-i-disable-swap|How do I disable swap]] AWS 인스턴스의 경우 명시적으로 지정하지 않으면 아예 swap 공간을 만들지 않으므로 swappiness가 의미가 없는 듯. ===== vm.max_map_count ===== * 리눅스에서 [[linux:wine|Linux Wine]] 혹은 [[linux:steam|Steam]] 게임 혹은 [[search:elasticsearch|Elastic Search]] 서버 설정을 위해 필요할 수 있음. * 게임용도로는 ''vm.max_map_count=2147483642'' (''MAX_INT - 5'') * [[search:elasticsearch|Elastic Search]]는 최소 ''vm.max_map_count=262144'' 가 필요함. [[https://www.elastic.co/guide/en/elasticsearch/reference/current/file-descriptors.html|Virtual memory | Elasticsearch Guide | Elastic]] sudo sysctl -w vm.max_map_count=2147483642 * ''/etc/sysctl.d/99-vm-max-map-count.conf'' 파일을 만들어서 내용을 추가하면 부팅시 자동적용 vm.max_map_count=2147483642 * [[https://www.youtube.com/watch?v=PsHRbfZhgXM&ab_channel=BrodieRobertson|Fedora 39 Changes 1 Line Saving Hours Of Pain - YouTube]] : Fedora 39 에서 기본값으로 ''2147483642'' 적용될 수 있음. ===== nproc(Max User Processes) ===== * ''ulimit -u'' 명령으로 값을 볼 수 있다. * ''ulimit -u 정수''로 임시 값 설정 * Centos의 경우 ''/etc/security/limits.conf'' 파일에서 값 지정 * - nproc 10240 ===== open files ===== * ''ulimit -n'' 명령으로 값을 볼 수 있다. * ''ulimit -n 정수''로 임시 값 설정 * Centos의 경우 ''/etc/security/limits.conf'' 파일에서 값 지정 * - nofile 10240 ===== limits.conf ===== * [[https://www.cubrid.com/tutorial/3794180|CUBRID | 튜토리얼 - 리소스를 제한(limits.conf) 하여 DB서버를 관리하자]] * ''/etc/security/limits.conf'' 혹은 ''/etc/security/limits.d/*.conf'' 로 파일 생성 * ''soft''에 다다르면 경고, ''hard''는 절대로 해당값 이상으로는 설정할 수 없다. * 계정명은 ''*'' 이면 전체 계정 계정명 soft nofile 50000 계정명 hard nofile 50000 계정명 soft nproc 10000 계정명 hard nproc 10000 계정명에 ''*'' 으로 지정하면 나머지 다를 의미함. [[:aws|AWS]] EC2 인스턴스의 경우 자동으로 인스턴스 타입에 따라 ''nproc''을 적정수로 지정하는 것으로 보임. 확인해보고 ''nproc''은 굳이 안해도 될 듯. # 현재 프로세스 limits 확인 cat /proc/[PID]/limits # hardlimit 확인 ulimit -aH * [[http://woowabros.github.io/experience/2018/04/17/linux-maxuserprocess-openfiles.html|Java, max user processes, open files - 우아한형제들 기술 블로그]] ===== systemd 사용시의 limits 설정 ===== * [[linux:systemd|systemd]]를 사용하고 GUI 로그인을 하거나(non GUI 로그인은 무관), systemd 서비스들의 경우에는 ''limits.conf''가 적용이 안 된다. * [[https://superuser.com/questions/1200539/cannot-increase-open-file-limit-past-4096-ubuntu/|linux - Cannot Increase open file limit past 4096 (Ubuntu) - Super User]] * [[https://man.archlinux.org/man/systemd-system.conf.5|systemd-system.conf(5) — Arch manual pages]] * ''/etc/systemd/system.conf'', ''/etc/systemd/user.conf'', ''/etc/systemd/system/unit.d/override.conf'' , ''/etc/systemd/user.conf.d/원하는파일.conf'' 등을 사용해서 설정해야 한다. * ''/etc/systemd/user.conf.d/99-user-system-limits.conf'' 를 통한 각 사용자의 limit 설정 [Manager] DefaultLimitNOFILE=50000 DefaultLimitNPROC=10000 $ ulimit -n -u open files (-n) 50000 max user processes (-u) 10000 ===== Outbound Socket Connection ===== * [[http://stackoverflow.com/questions/410616/increasing-the-maximum-number-of-tcp-ip-connections-in-linux|limit - Increasing the maximum number of tcp/ip connections in linux - Stack Overflow]] net.ipv4.tcp_fin_timeout = 10 net.ipv4.ip_local_port_range = 15000 61000 net.ipv4.tcp_tw_recycle = 0 net.ipv4.tcp_tw_reuse = 1 * ''net.ipv4.tcp_tw_recycle'' 이 값은 1로 줄 경우 문제 발생의 소지가 있을 수 있다. ===== Hyper Threading ===== * [[http://snoopybox.co.kr/1738|리눅스 하이퍼쓰레딩(Hyper Threading) 활성화 확인 방법 - snoopybox]] * ''egrep 'siblings|cpu cores' /proc/cpuinfo | head -2'' 명령의 결과 ''siblings''의 값이 ''cpu cores''의 2배이면 하이퍼쓰레딩이 켜져 있는 것이다. 두 값이 동일하면 꺼져있는 것이다. * 가끔 하이퍼쓰레딩을 지원하지 않는 CPU인데 이 값이 2배로 보이는 일이 발생하기도 한다고 한다. ===== 참조 ===== * [[http://meetup.toast.com/posts/53|리눅스 서버의 TCP 네트워크 성능을 결정짓는 커널 파라미터 이야기 - 1편 : TOAST Meetup]] * [[http://meetup.toast.com/posts/54|리눅스 서버의 TCP 네트워크 성능을 결정짓는 커널 파라미터 이야기 - 2편 : TOAST Meetup]] * [[http://meetup.toast.com/posts/55|리눅스 서버의 TCP 네트워크 성능을 결정짓는 커널 파라미터 이야기 - 3편 : TOAST Meetup]] * [[https://www.slideshare.net/brendangregg/performance-tuning-ec2-instances|Performance Tuning EC2 Instances]] * [[https://haydenjames.io/linux-server-performance-disk-io-slowing-application/|Linux server performance: Is disk I/O slowing your application?]]