CPU 사용량을 제한 할 수 있을까요? 95%이하로

io2oi의 이미지

학교실험실에있는 리눅스 클러스터를 관리하고 있는데요

그동안 별 문제 없이 사용하고 있던 노드들이 최근에 심한 연산을 하는 python으로 짠 프로그램을 돌리니 네트워크가 죽어버리면서 RPC에러를 내며 nfs를 잡지 못하고 있습니다.

메모리 양을 체크해봐도 170MB이상 가지를 않고 파워도 350W에서 480W짜리로 변경도 해 보았지만 변화가 없습니다.

지금 드는 생각은 CPU사용량이 99%된 채로 몇시간을 프로세스를 돌리는 것이 문제가 아닐까 하는데요 혹시 CPU사용양을 제한 할 수 있는 방법이 있을까요?
아니면 다른 문제가 있어서 그럴까요?

현재 서브노드 시스템은 CPU한개짜리이구요 CPU는 P4 3.2G를 쓰고 있습니다. 메모리는 2GB입니다.
서브노드에서 돌린 프로세스의 개수는 1개입니다.

도움을 주시면 정말 감사하겠습니다.

정태영의 이미지

nice 를 이용해보세요

오랫동안 꿈을 그리는 사람은 그 꿈을 닮아간다...

http://mytears.org ~(~_~)~
나 한줄기 바람처럼..

io2oi의 이미지

답변 감사합니다.

그런데 nice는 scheduling 우선순위를 조절한다고 man 페이지에 나와있는데요

우선순위 조절을 하면 CPU 사용량이 조절이 되나요?

우리의 클러스터의 경우 서브노드에서는 user process 는 동시에 한개의 프로세스만 돌고있습니다. 동시에 존재하는 프로세스는 모두 root프로세스라서 아마도 priority가 0보다 높을 것 같은데요.

혹시 nice로 해결이 가능하다면 어떻게 해야할까요?

정태영의 이미지

io2oi wrote:
답변 감사합니다.

그런데 nice는 scheduling 우선순위를 조절한다고 man 페이지에 나와있는데요

우선순위 조절을 하면 CPU 사용량이 조절이 되나요?

우리의 클러스터의 경우 서브노드에서는 user process 는 동시에 한개의 프로세스만 돌고있습니다. 동시에 존재하는 프로세스는 모두 root프로세스라서 아마도 priority가 0보다 높을 것 같은데요.

혹시 nice로 해결이 가능하다면 어떻게 해야할까요?

nice 값이 time slice 를 계산하는데 참조되는 값 중 하나니까... nice 값을 높임으로 cpu 점유시간을 조금이나마 낮출 수 있겠죠 ;)

그리고 nice 값은 높을 수록 우선순위가 낮습니다...

NICE(1)                          User Commands                         NICE(1)



NAME
       nice - run a program with modified scheduling priority

SYNOPSIS
       nice [OPTION] [COMMAND [ARG]...]

DESCRIPTION
       Run  COMMAND  with  an  adjusted scheduling priority.  With no COMMAND,
       print the current scheduling priority.  ADJUST is 10 by default.  Range
       goes from -20 (highest priority) to 19 (lowest).

오랫동안 꿈을 그리는 사람은 그 꿈을 닮아간다...

http://mytears.org ~(~_~)~
나 한줄기 바람처럼..

io2oi의 이미지

친절한 답변에 다시한번 감사드립니다.

버벅거리는 서브노드에 들어가서 간신히 확인을 해보니 priority가 더 낮은 것(숫자가 더 큰 것)들도 보이네요. 따라서 정태영님말처럼 하면 낮출 수 있을 것도 같습니다.

그런데 답변을 보기전에 인터넷에서 다음과 같은 프로그램을 찾았습니다. 이 프로그램의 뜻이 무엇일까요? 돌려보니까 확실히 CPU 사용률을 주어진 숫자 아래로 제한 하는 것을 확인 할 수 있었습니다.

//cpulimit.c
/**
* Simple program to limit the cpu usage of a process
*
* the code is very small, uses only SIGSTOP and SIGCONT signals, and can be improved, then i post it here.
* to compile: gcc -o cpulimit cpulimit.c
* to run: cpulimit {seti pid} {cpu limit}
* Author: Angelo Marletta (marlonx80@hotmail.com)
*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/resource.h>

//pid of the controlled process
int pid;

//SIGINT signal handler
void quit(int sig) {
//let the process continue if it's stopped
kill(pid,SIGCONT);
exit(0);
}

int main(int argc, char **argv) {

if (argc!=3) {
fprintf(stderr,"Usage: %s {pid} {max cpu percentage}\n",argv[0]);
exit(1);
}
pid=atoi(argv[1]);
int limit=atoi(argv[2]);
if (limit>100) {
fprintf(stderr,"limit must be in the range 0-100\n");
exit(1);
}
//if possible renice this process, so it has more responsiveness
if (setpriority(PRIO_PROCESS,getpid(),-20)!=0) {
printf("Warning: cannot renice.\nTo work better you should run this program as root.\n");
}
signal(SIGINT,quit);

//time quantum in microseconds
int period=100000;
struct timespec twork,tsleep; //time to work, and time to sleep
twork.tv_sec=0;
twork.tv_nsec=period*limit*10;
tsleep.tv_sec=0;
tsleep.tv_nsec=period*(100-limit)*10;

while(1) {
if (kill(pid,SIGSTOP)!=0) break;
nanosleep(&tsleep,NULL);
if (kill(pid,SIGCONT)!=0) break;
nanosleep(&twork,NULL);
}

perror("kill()");
exit(1);
}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.