Find the answer to your Linux question:
Results 1 to 7 of 7
Hello everyone I'm using Ubuntu 8.04 server and I'm running into a problem. I have a rake task that grabs alot of data out of a csv file and imports ...
  1. #1
    Just Joined!
    Join Date
    Dec 2006
    Posts
    4

    Cron jobs and swapping memory

    Hello everyone

    I'm using Ubuntu 8.04 server and I'm running into a problem.

    I have a rake task that grabs alot of data out of a csv file and imports it into our mysql database. When I run the rake task from in the console the amount of memory needed to complete the task exceeds that available memory and swapping occurs to complete the task.

    When I run this job from within cron, at the moment when swapping needs to occur to complete the task the task fails and the swapping does not occur.

    It's as if I need to tell cron to allow memory swapping.

    Has anyone seen anything like this before or have any ideas on how I tell cron to allow memory swapping to complete it's tasks?

    All help is greatly appreciated.

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Exclamation

    Quote Originally Posted by vanderkerkoff View Post
    Has anyone seen anything like this before or have any ideas on how I tell cron to allow memory swapping to complete it's tasks?
    That's quite unusual for me. I may be wrong,but here is my view:
    I think memory activities are obviously handled by kernel.Kernel decides to use swap space,only when i ran out of primary memory (RAM)

    In your case , It might be simple case of RAM has enough memory to execute the process ,so swapping is not used.

    I would suggest you to check the process timing using
    time command
    man time
    You can redirected the output from crontab to file and check the timing.

    note:
    Remember Swap and CPU time all depends on other processes too.

    If you have 10 process already running and when you execute your program,clearly it will take more time and it may use swap.

    If there is very few running process (say 2) then you mayn't need swap,processing time will quick.
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,975
    Swapping is built into the OS. If your process is failing under cron, then I think you likely do not have enough swap space allocated. Have you looked into the cronlog and system (dmesg) log file(s) to see what happened? FWIW, cron has no relationship to swap space. If you ran out of swap, then the process will fail, simply enough.

    ROT (Rule Of Thumb): calculate 1.5x the memory required by the OS, normally running processes, plus that required by any regularly scheduled process. If that exceeds the available RAM, then allocate sufficient swap space for up to 1.5x the available RAM or 1.5x the calculated space required - whichever is greater.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. #4
    Linux Engineer b2bwild's Avatar
    Join Date
    Jul 2008
    Location
    Behind You!
    Posts
    1,108
    Quote Originally Posted by Rubberman View Post
    ROT (Rule Of Thumb): calculate 1.5x the memory required by the OS, normally running processes, plus that required by any regularly scheduled process. If that exceeds the available RAM, then allocate sufficient swap space for up to 1.5x the available RAM or 1.5x the calculated space required - whichever is greater.
    Important thing about swap,
    For Desktop, or Small server.
    Swap should be minimum 32 MB and maximum 2GB.
    You swap should be 2.0x of RAM, if your RAM is less than 512.
    Your swap should be 1.5x of RAM, if your RAM is less than or equal to 1GB
    Your swap should be 1x of RAM, if ram is <= 2GB
    If RAM is more than 2GB, Swap file should go decreasing.

    Swap will be used when you are out of RAM,
    While you have enough space on your RAM, swapping is an idiocy.
    You don't need cron to swap memory.
    Swapping everything on swap will affect system stability.

    Swapping is controlled by swappiness.
    cat /proc/sys/vm/swappiness
    If you want to swap memory more increase swappiness.
    echo 100 > /proc/sys/vm/swappiness
    If you don't want memory to be swapped.
    echo 0 > /proc/sys/vm/swappiness
    Increasing swappiness will put more load on CPU.
    Never make any misteaks.

    Read my Blog at --> Penguin Inside Subscribe Feed

  5. #5
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Exclamation

    I tried to re-write it. are these general rules ? Let me know whether is this correct?

    You swap should be 2.0x of RAM, if your RAM is less than 512.
    if(RAM_SIZE <=512MB)
    swap = 2 x RAM_SIZE

    Your swap should be 1.5x of RAM, if your RAM is less than or equal to 1GB
    if (RAM_SIZE > 512MB && RAM_SIZE <=1GB
    swap = 1.5 x RAM_SIZE

    Your swap should be 1x of RAM, if ram is <= 2GB
    if (RAM_SIZE > 1GB && RAM_SIZE <=2GB )
    swap = RAM_SIZE

    If RAM is more than 2GB, Swap file should go decreasing.

    if (RAM_SIZE > 2GB)
    swap = RAM_SIZE - x
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  6. #6
    Linux Engineer b2bwild's Avatar
    Join Date
    Jul 2008
    Location
    Behind You!
    Posts
    1,108
    Quote Originally Posted by Lakshmipathi View Post
    if (RAM_SIZE > 512MB && RAM_SIZE <=1GB)
    swap = 1.5 x RAM_SIZE
    Correct algorithm, You only forgot a ) in if condition, X_X lol

    These are standard rules defined by Red Hat, applies to most of the Linux Distros.
    Never make any misteaks.

    Read my Blog at --> Penguin Inside Subscribe Feed

  7. #7
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568
    [QUOTE=b2bwild;700159]Correct algorithm, You only forgot a ) in if condition [QUOTE]
    yes,its a syntax error
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...