Cached too high causes memory overflow Java head space

Source: Internet
Author: User

Recently the company on the line encountered a memory overflow check after the cached command: free-m command: Sync//Cache write to the hard disk Cat/etc/redhat-release this is the command to view the system version of CentOS or other. Command: Echo 1 >/proc/sys/vm/drop_caches Clean cache permissions may be root because it is a system of search queries, so the IO write index is so cached too high and related to the Linux mechanism # Description, best sync before release, Prevent data loss
#!/bin/bash#total area allocated by the systemMem_total= ' Free-m | Awk'nr==2'| Awk'{print $}'` #the current remaining sizeMem_free= ' Free-m | Awk'nr==3'| Awk'{print $4}'`  #used size currently in useMem_used= ' Free-m | grep Mem | Awk'{print $}'`   if(($mem _used! =0)); Then#if it is already in use, calculate the percentage of the total that is currently remaining free, expressed in decimal notation, to complement an integer digit before the decimal point 0Mem_per=0 ' Echo"scale=2, $mem _free/$mem _total"|BC ' DATA="$ (date-d"Today" +"%y-%m-%d-%h-%m") Free percent is: $mem _per"Echo $DATA>>/var/log/Mem_detect.log#set the alarm value to 20% (i.e. alarm when using more than 80%). mem_warn=0.20#The current remaining percentage is compared to the alarm value (1 is returned when it is greater than the alarm value (i.e. more than 20% remaining), and 0 is returned when it is less than (that is, less than 20%)mem_now= ' Expr $mem _per \>$mem _warn '#If you are currently using more than 80% (that is, the remaining is less than 20%, the above return value equals 0), free memoryif($mem _now = =0)); Then Syncecho3 >/proc/sys/vm/Drop_cachesfi fi

Or

#!/bin/bashused= ' Free-m | Awk'nr==2'| Awk'{print $}'' free= ' Free-m | Awk'nr==2'| Awk'{print $4}'' echo"===========================">>/var/log/mem.logdate>>/var/log/Mem.logecho"Memory Usage | [USE:${USED}MB] [FREE:${FREE}MB]">>/var/log/Mem.logif[$free-le 100 ] ; Then sync&& echo 1 >/proc/sys/vm/drop_caches Sync&& Echo 2 >/proc/sys/vm/drop_caches Sync&& echo 3 >/proc/sys/vm/drop_caches Echo"OK">>/var/log/Mem.logElseEcho"Not required">>/var/log/mem.log

Finally, we need

# echo "0 * */1 * *? root/home/tomcat/clearcached.sh ">>/etc/crondtab

Cached too high causes memory overflow Java head space

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.