-2

I have a Linux server containing the os version below:

Linux 2.6.32-220.7.1.el6.x86_64

I want to restart it in every 2 days, please help me, I want to do it via crontab.

Another help,

I used a code below to drop my memory caches in every hour.

0 * * * * /root/clearcache.sh

#!/bin/sh
sync; echo 3 > /proc/sys/vm/drop_caches

But 1st 15 in every hour my server remain so slow after cleaning the caches. My sites do not load during every hour in 1st 15 minutes.

In another way if I restart my server then also caches are removed. So I decided to restart my server in every 2 days to drop my caches.

Will it be helpful to restart? Or is there any other way to drop my memory caches that will not down my server?

user9517
  • 114,104
  • 20
  • 206
  • 289
Barkat Ullah
  • 145
  • 1
  • 3
  • 9
  • 5
    Why are you doing this? The caches are not a problem. Restarting won't fix whatever issue you're having. – cjc Apr 15 '12 at 14:20
  • If you have a performance related problem, you need to know its cause first. Restart will not offer you anything! – Khaled Apr 15 '12 at 14:21
  • I have 16GB ram, but if i clear my caches now, after 10 hours my caches are taking 10GB and using 5GB, so total 15GB is using, in that if i clear cache, it will free a lots of ram. Thanks. – Barkat Ullah Apr 15 '12 at 14:26
  • 4
    Are you seeing this behavior? If so, it's not a problem: http://www.linuxatemyram.com/ – Bill Weiss Apr 15 '12 at 14:34
  • Why would you want to clean your cache, on a linux machine caching is a good thing not a bad one... – Lucas Kauffman Apr 15 '12 at 14:36
  • Now it is super off peak hour, therefore i am sharing my # free -m screenshot. http://dl.dropbox.com/u/26967109/free-m.jpg . See that 6GB memory is used but 4 GB is cached. – Barkat Ullah Apr 15 '12 at 14:46
  • Yes, 6GB in use and 4GB of that is being used for cache. Your system has 14GB additional memory for use by applications because it is only using 2GB of RAM for applications currently. This is actually a very good setup for a physical application server. – Magellan Apr 15 '12 at 15:20
  • Basically now it is a super off peak hour that i told you. When it will be peak hour then the uses will be such as, 9GB in cache and 6 GB in actual used, so that my system is using total 15GB. I wanted to reduce that 9GB cached when my sites are will be in peak hour. – Barkat Ullah Apr 15 '12 at 15:25
  • 3
    If you don't want your system to *use* RAM, take it out of the system and sit it on your desk. The more RAM your system uses, the faster it goes. That's why we add RAM to a system! Why would you want your system to be forced to use less RAM and thus run more slowly?! – David Schwartz Apr 15 '12 at 20:33

1 Answers1

8

To answer your headline question, in root's crontab

0 0 */2 * * reboot

would reboot your system at midnight every other day. There may be an extra reboot or an extra day between reboots for months with odd numbered days.

Having said that, dropping caches probably isn't the correct thing to do as they are generally used to speed things up. Have a look at some of the answers to this SF search which may be able to help you diagnose why your system is slow so you can fix the real problem.

user9517
  • 114,104
  • 20
  • 206
  • 289
  • Now it is super off peak hour, therefore i am sharing my # free -m screenshot. http://dl.dropbox.com/u/26967109/free-m.jpg . See that 6GB memory is used but 4 GB is cached – Barkat Ullah Apr 15 '12 at 15:13
  • 3
    I think you should go read this website that @billweiss posted, repeatedly, until you understand what it is saying: http://www.linuxatemyram.com/ – Magellan Apr 15 '12 at 15:22
  • OH, i just got my answer, If your applications want more memory, they just take back a chunk that the disk cache borrowed. Disk cache can always be given back to applications immediately! You are not low on ram! , that means cached memory will be free when my sites will be needed, is not it? – Barkat Ullah Apr 15 '12 at 15:28
  • Exactly. That's exactly how that works. – Magellan Apr 15 '12 at 15:29
  • Thanks a lot, i will not use any crontab to drop caches, it will help me so much from my hesitation and my sites will be faster from now. – Barkat Ullah Apr 15 '12 at 15:31