Thursday, September 28, 2017





15 Steps to Improve MacBook's Performance





Remember the feeling of a brand new Mac? A Mac without rainbow wheels. A Mac that didn’t cause headaches or frustration. Everything was just perfect! However, with all apps, documents, photos and a full iTunes library, your Mac starts to act as if it’s hiking 20 miles uphill in the snow. Don’t worry; it’s easy to improve Mac performance. We’ll show you 15 ways to speed up Mac.

Here’s How to Speed Up Mac

1. Find resource-hungry processes

Some apps are more power hungry than others and can slow your Mac to a crawl. To see which apps are eating up your system resources, use Activity Monitor. You can open it from the Utilities folder of your Applications folder, or use Spotlight to find it.
Activity Monitor details five different resources: CPU, Memory, Energy, Disc, and Network usage. If your Mac is running slowly, pay special attention to the CPU section. It shows how processes affect CPU (processor) activity. Click a column name, such as % CPU, to list all programs by the amount of CPU they’re using.
If you see that some app is using a lot of CPU power, you can close it from here by choosing the app with the mouse and clicking the X in the left-hand corner of the Activity Monitor.

2. Manage your startup items

It goes without saying that a clean startup helps speed up slow Mac. When your Mac launches faster, it takes less time to do anything. No waiting for Safari, Chrome or Firefox to launch — they open instantly. How do you get such speed? Well, when your Mac boots up, it runs a lot of unnecessary apps. But it’s quite easy to take control of it. Go to your System Preferences > Users & Groups and then click on your username. Now click on Login Items and select a program you don’t immediately need when your Mac starts up, and click the “-” button below.


3. Turn off visual effects

A great tip to help you when you wonder how to speed up your Mac is to turn off visual effects. Sure, they look pretty, but who cares if your Mac is running slowly? Turning off some of the features can greatly speed up iMac or MacBook.
Here’s how to speed up a Mac by turning off some visual effects:


  1. Click System Preferences > Dock
  2. Untick the following boxes: Animate opening applications, Automatically hide and show the Dock.
  3. Click on Minimize windows using and change Genie effect to Scale effect.

4. Repair disk permissions

When you install an app on your Mac, the piece of software arrives as a package of files, including permissions that tell OS which users can do what things with specific files. Over time, these permissions can get changed, resulting in your Mac lagging. A quick and easy fix is to repair disk permissions.
Follow these steps to repair disc permissions:
  1. Open Disk Utility (Applications > Utilities).
  2. Choose your startup disk.
  3. Click the First Aid tab.
  4. Click Repair Disk Permissions to repair any inconsistent permissions.
Note that beginning from OS X EI Capitan, there is no need to repair disk permissions because the process is handled automatically. But if your Mac runs OS X Yosemite or earlier, repairing disk permissions with Disk Utility can help speed up old Mac.

5. Reindex Spotlight

If you recently updated your OS, you would be aware of the slowness that occurs when Spotlight is indexing. This only takes a few hours and then your Mac will be fine. But sometimes the indexing gets stuck, and you need to speed up a Mac. To solve this problem, you need to reindex Spotlight by going to System Preferences > Spotlight and clicking on the “Privacy” tab.
Now drag your hard drive from Finder into the Privacy List. Once added, remove it by clicking the “-” sign. The indexing will start again, but hopefully, after a few hours, it will finish properly and boost your Mac speed.

6. Manage syncing photos to iCloud

You may be surprised by how much of your Mac’s storage is taken up by photos. And syncing them to iCloud may take plenty of time, and as a result, slow down your Mac. You may think that deleting photos from your Mac may resolve the problem. But, unfortunately, that’s not how iCloud Photo Library works. When you remove photos from your computer, they are also deleted from all your devices. So how to speed up your Mac and don’t lose your photos?
One of the possible solutions might be turning off iCloud Photo Library on your Mac. If you still want to back up your photos in the cloud, you may use another device, such as Dropbox or Google Drive. That’s up to you! But note that taking control over syncing your photos to the iCloud may speed up your Mac.

7. Empty the caches

Cache files are temporary data used to speed up the processes. For example, a web browser will cache web pages to download a website faster when you revisit it. Sounds great, right? Actually, it is, but there is always “but.” Over time, these cache files take much storage on your Mac, and instead of speeding things up, they slow your computer down.
So how to speed up MacBook by emptying the caches? There are two ways: you can clean them up manually (step-by-step) or you can remove them in a second with a cleaning utility CleanMyMac 3.
If you want to clear cache automatically, do the following:
  1. Launch CleanMyMac 3.
  2. Choose System Junk.
  3. Click Scan and then Clean.
That’s it!


However, if you decide to clean cache files manually, check out his guide on “How to Clear Cache on a Mac.”

8. Uninstall applications

Another proven way to speed up MacBook Pro, MacBook Air or iMac is to uninstall the application you don’t need anymore. So how to remove unwanted apps on your Mac? You may be surprised to find out that simply dragging them to a Trash bin is not enough. It leaves gigabytes of junk behind. Dragging documents and movies to Trash works fine but apps should be uninstalled completely. Check out a step-by-step guide on “How to Install Apps on a Mac.” It describes the manual way and the easy way.

9. Clean up Mac’s hard drive

If you want the most bang for your buck, cleaning your hard drive is by far the best and easiest way to speed up MacBook or iMac. Go through your hard drive and clean out everything that is slowing it down. But what is slowing down my Mac? What to look for? Caches, logs, apps, widgets, hidden trash, large and old files.
Of course, you can clean up your Mac manually. But finding and removing all these things takes time. And you have to know where to look. The good news is that there is an easy solution to the problem. CleanMyMac 3 app has everything you need to finish the 3-hour task of hard drive cleanup in under 5 minutes. Even more, it will clean up the junk you didn’t even know about and speed up Mac.

10. Update your Mac (OS and hardware)

Typically, Macs take care of themselves. Having the latest software from Apple makes speeding up your Mac simple. To check your version of the operating system, click the Apple icon in the top left corner of your screen and then About This Mac. Make sure you have the latest macOS/OS X installed (or the latest you can install since not all Macs upgrade to EI Capitan.)


As for the hardware upgrade, as you’ve probably guessed, it is costly. But if your OS is the latest possible version and you’ve cleaned up the hard drive, and you still have troubles with speed, this could be your solution. Keep in mind that upgrading some hardware is not possible for certain Macs.
Upgrading to the latest OS and upgrading your hardware will typically solve a bunch of slowness issues.

11. Restart your Mac

If your Mac is acting sluggish or some programs are failing to run, try to restart your computer. When you restart your Mac, it closes all running programs and offers to save any files you’re working on. Once you choose to save the file, your Mac will boot up again. The result is a refreshed Mac that should perform better.
To restart your Mac, do the following:
  1. Click the Apple menu button in the top-left corner of your screen.
  2. Click Restart.
  3. Click the Restart button in the pop-up menu to confirm.
If you need to reboot your Mac but want to reopen apps automatically after rebooting, check the Reopen windows when logging back in box in the pop-up menu.

12. Reset SMC & PRAM

Sometimes your Mac will act strange for no apparent reason — it sleeps or shuts down unexpectedly, the battery doesn’t charge properly, the keyboard backlight behaves incorrectly, and your Mac performs slowly. If these issues are not solved by restarting your computer, you’ll need to reset SMC (system management controller) and PRAM (parameter RAM).

Resetting the SMC

How to speed up MacBook Air, MacBook Pro, and MacBook
First of all, you need to determine whether your Mac’s battery is removable. That’s because the process of resetting the SMC for computers that have a non-removable battery is quite different.
If the battery is non-removable:
  1. Shut down your Mac.
  2. Press Shift+Control+Option on your keyboard and press the power button at the same time. Hold the keys and a power button for 10 seconds.
  3. Release all keys.
  4. Press the power button to turn on your Mac.
If the battery is removable:
  1. Shut down your Mac.
  2. Remove the battery.
  3. Press the power button and hold it for 5 seconds.
  4. Press the power button again to turn on your computer.
How to speed up iMac, Mac Mini, Mac Pro
  1. Shut down your computer.
  2. Unplug a power cord and wait 15 seconds.
  3. Plug the power cord in.
  4. Wait 5 seconds and press the power button.

Resetting the PRAM

  1. Shut down your Mac.
  2. Press the power button.
  3. Press the Command+Option+P+R keys at the same time.
  4. Hold the keys until your Mac restarts.
  5. Release the keys.
Resetting SNC and PRAM may seem to be difficult, but it can really help with Mac speedup.

13. Replace your HDD with SSD

You can breathe new life into your Mac by replacing its traditional hard drive with a solid-state drive. Adding an SSD will make your computer boot faster, copy files in the blink of an eye and make the system really fast when multitasking.
A word of caution: it’s recommended that you consult a professional before attempting any hardware upgrades yourself because the process is quite challenging. And don’t forget to make a complete backup of your data before replacing your HDD with SSD, so that you’ll be able to restore all important files if something goes wrong.

14. Add more RAM

How to speed up my Mac? How to get it run faster? In fact, upgrading RAM is usually a great solution for improving your Mac’s performance. The more RAM your Mac has at its disposal, the more windows or tabs you can have open without slowing the system down. With more RAM, the operating system isn’t making calls to virtual memory which uses the hard drive and slows down the system considerably. Here’s a comprehensive guide on  “How to Upgrade Your Mac’s RAM.”

15. Use CleanMyMac 3

If you don’t feel like spending the next several hours trying to get your Mac in shape manually, there is a great solution. Download CleanMyMac 3 and let it do the job for you. It’s a powerful utility for speeding up Mac. It knows which files are useless, where they are, and how to remove them completely. CleanMyMac is incredibly easy to use: all the tools we’ve talked about, and even more, are right there, ready to launch in a few clicks. No wasted time, just a faster Mac.


Now, speed up your Mac, take a deep breath, do a Mac speed test and come to thank us.

Wednesday, March 1, 2017

Cleanup a postfix mail queue




  1. Do you need to cleanup a postfix mail queue?

    To delete all email from one specific email address, or all email From: a specific domain name, please choose the appropriate command from the following list.

    To delete all email in the queue from a domain run this command as root:

    postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } /@example\.com/ { print $1 }' | tr -d '*!' | postsuper -d -

    To delete all email in the queue From: a specific email address run this command as root:

    postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } /username@example\.com/ { print $1 }' | tr -d '*!' | postsuper -d -


    To delete ALL email from the queue regardless of domain name or email address use:


    postsuper -d ALL 


Tuesday, February 14, 2017

Find out the highest cpu consumed threads of java, and print the stack of these threads.

#!/bin/bash
# @Function
# Find out the highest cpu consumed threads of java, and print the stack of these threads.
#
# @Usage
#   $ ./show-busy-java-threads.sh
#
# @author Jerry Lee

readonly PROG=`basename $0`
readonly -a COMMAND_LINE=("$0" "$@")

usage() {
    cat <<EOF
Usage: ${PROG} [OPTION]...
Find out the highest cpu consumed threads of java, and print the stack of these threads.
Example: ${PROG} -c 10

Options:
    -p, --pid       find out the highest cpu consumed threads from the specifed java process,
                    default from all java process.
    -c, --count     set the thread count to show, default is 5
    -h, --help      display this help and exit
EOF
    exit $1
}

readonly ARGS=`getopt -n "$PROG" -a -o c:p:h -l count:,pid:,help -- "$@"`
[ $? -ne 0 ] && usage 1
eval set -- "${ARGS}"

while true; do
    case "$1" in
    -c|--count)
        count="$2"
        shift 2
        ;;
    -p|--pid)
        pid="$2"
        shift 2
        ;;
    -h|--help)
        usage
        ;;
    --)
        shift
        break
        ;;
    esac
done
count=${count:-5}

redEcho() {
    [ -c /dev/stdout ] && {
        # if stdout is console, turn on color output.
        echo -ne "\033[1;31m"
        echo -n "$@"
        echo -e "\033[0m"
    } || echo "$@"
}

yellowEcho() {
    [ -c /dev/stdout ] && {
        # if stdout is console, turn on color output.
        echo -ne "\033[1;33m"
        echo -n "$@"
        echo -e "\033[0m"
    } || echo "$@"
}

blueEcho() {
    [ -c /dev/stdout ] && {
        # if stdout is console, turn on color output.
        echo -ne "\033[1;36m"
        echo -n "$@"
        echo -e "\033[0m"
    } || echo "$@"
}

# Check the existence of jstack command!
if ! which jstack &> /dev/null; then
    [ -z "$JAVA_HOME" ] && {
        redEcho "Error: jstack not found on PATH!"
        exit 1
    }
    ! [ -f "$JAVA_HOME/bin/jstack" ] && {
        redEcho "Error: jstack not found on PATH and $JAVA_HOME/bin/jstack file does NOT exists!"
        exit 1
    }
    ! [ -x "$JAVA_HOME/bin/jstack" ] && {
        redEcho "Error: jstack not found on PATH and $JAVA_HOME/bin/jstack is NOT executalbe!"
        exit 1
    }
    export PATH="$JAVA_HOME/bin:$PATH"
fi

readonly uuid=`date +%s`_${RANDOM}_$$

cleanupWhenExit() {
    rm /tmp/${uuid}_* &> /dev/null
}
trap "cleanupWhenExit" EXIT

printStackOfThreads() {
    local line
    local count=1
    while IFS=" " read -a line ; do
        local pid=${line[0]}
        local threadId=${line[1]}
        local threadId0x="0x`printf %x ${threadId}`"
        local user=${line[2]}
        local pcpu=${line[4]}

        local jstackFile=/tmp/${uuid}_${pid}

        [ ! -f "${jstackFile}" ] && {
            {
                if [ "${user}" == "${USER}" ]; then
                    jstack ${pid} > ${jstackFile}
                else
                    if [ $UID == 0 ]; then
                        sudo -u ${user} jstack ${pid} > ${jstackFile}
                    else
                        redEcho "[$((count++))] Fail to jstack Busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user})."
                        redEcho "User of java process($user) is not current user($USER), need sudo to run again:"
                        yellowEcho "    sudo ${COMMAND_LINE[@]}"
                        echo
                        continue
                    fi
                fi
            } || {
                redEcho "[$((count++))] Fail to jstack Busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user})."
                echo
                rm ${jstackFile}
                continue
            }
        }
        blueEcho "[$((count++))] Busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user}):"
        sed "/nid=${threadId0x} /,/^$/p" -n ${jstackFile}
    done
}


ps -Leo pid,lwp,user,comm,pcpu --no-headers | {
    [ -z "${pid}" ] &&
    awk '$4=="java"{print $0}' ||
    awk -v "pid=${pid}" '$1==pid,$4=="java"{print $0}'
} | sort -k5 -r -n | head --lines "${count}" | printStackOfThreads

Identify Java code consuming high CPU in Linux (linking JVM thread and Linux PID)

We can easily identify a problematic java code which leads to high CPU utilization in Linux. Let me explain the steps with the following example,
  1.  package test;
  2.  public class ThreadDumpTest {
  3.          public void test(){
  4.                  for (int i = 0; i < 10 ; i++) {
  5.                          Thread th=new Thread(new TR(i));
  6.                          th.setName(“MyThread-“+(1000+i));
  7.                          th.start();
  8.                  }
  9.          }
  10.          public static void main(String[] args) {
  11.                  ThreadDumpTest t=new ThreadDumpTest();
  12.                  t.test();
  13.          }
  14.          private class TR implements Runnable{
  15.                  int ins=0;
  16.                  TR(int i){
  17.                          ins=i;
  18.                  }
  19.                  public void run(){
  20.                          while (true) {
  21.                                  if(ins!=5) {
  22.                                          try {
  23.                                                  Thread.sleep(10000);
  24.                                          } catch (Exception e) {
  25.                                                  e.printStackTrace();
  26.                                          }
  27.                                  }
  28.                          }
  29.                  }
  30.          }
  31.  }
In the above example, all the threads are in while loop. Except ‘MyThread-1005‘ thread, all other threads will sleep 10 secs inside the loop. The ‘MyThread-1005‘ thread will not enter sleep part, so it will run in while loop without sleep. Due to while loop, the ‘MyThread-1005‘ thread will leads to high CPU utilization.
How to identify ?
Step 1 :
Execute ‘top‘ command on the console. You can see the ‘java’ command with PID 7074 utilized 97% of CPU.
Step 2 :
The top command displays the process list like the above image. Press ‘Shift + h‘ and wait few secs. You can see ‘Show threads on‘ message in the top console. Now, you can see thread level details like CPU/Memory utilization. You can see a ‘java’ command thread with PID 7087 utilized 94% of CPU.
Step 3:
The identified problematic thread PID ( 7087 ) is in decimal format. Convert it into hexadecimal format. The respective hexadecimal for 7087 is 1BAF. And convert it into lowercase (1baf ).
Step 4:
Take thread dump and search the converted hexadecimal PID ( 1baf ) in the thread dump. You can find the hex PID as ‘nid‘ (with ‘0x’) of the thread trace. From the trace, you can find ‘MyThread-1005‘ is the problematic thread in the test program. And using the thread trace you can identify the problematic code and fix the problem.
  1. [rameshj@rameshj thread]$ java test/ThreadDumpTest
  2. ^\Full thread dump Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode):
  3. “DestroyJavaVM” prio=1 tid=0x083d2d78 nid=0x1ba2 waiting on condition [0x00000000..0xbff4bf60]
  4. “MyThread-1009” prio=1 tid=0x08510a88 nid=0x1bb3 waiting on condition [0xa9cca000..0xa9ccb020]
  5.         at java.lang.Thread.sleep(Native Method)                                             
  6.         at test.ThreadDumpTest$TR.run(ThreadDumpTest.java:45)          &nbs
    p;                     
  7.         at java.lang.Thread.run(Thread.java:595)                                             
  8. “MyThread-1008” prio=1 tid=0x08510318 nid=0x1bb2 waiting on condition [0xa9d4b000..0xa9d4bea0]
  9.         at java.lang.Thread.sleep(Native Method)                                             
  10.         at test.ThreadDumpTest$TR.run(ThreadDumpTest.java:45)                                
  11.         at java.lang.Thread.run(Thread.java:595)                                             
  12. “MyThread-1007” prio=1 tid=0x0850f298 nid=0x1bb1 waiting on condition [0xa9dcc000..0xa9dccf20]
  13.         at java.lang.Thread.sleep(Native Method)                                             
  14.         at test.ThreadDumpTest$TR.run(ThreadDumpTest.java:45)                                
  15.         at java.lang.Thread.run(Thread.java:595)                                             
  16. “MyThread-1006” prio=1 tid=0x0850d818 nid=0x1bb0 waiting on condition [0xa9e4d000..0xa9e4dda0]
  17.         at java.lang.Thread.sleep(Native Method)                                             
  18.         at test.ThreadDumpTest$TR.run(ThreadDumpTest.java:45)                                
  19.         at java.lang.Thread.run(Thread.java:595)                                             
  20. MyThread-1005” prio=1 tid=0x0850c9f8 nid=0x1baf runnable [0xa9ece000..0xa9ecee20]
  21.         at test.ThreadDumpTest$TR.run(ThreadDumpTest.java:43)                    
  22.         at java.lang.Thread.run(Thread.java:595)                                 
  23. “MyThread-1004” prio=1 tid=0x0850b8e8 nid=0x1bae waiting on condition [0xa9f4f000..0xa9f500a0]
  24.         at java.lang.Thread.sleep(Native Method)                                             
  25.         at test.ThreadDumpTest$TR.run(ThreadDumpTest.java:45)                                
  26.         at java.lang.Thread.run(Thread.java:595)                                             
  27. “MyThread-1003” prio=1 tid=0x0850aac8 nid=0x1bad waiting on condition [0xa9fd0000..0xa9fd1120]
  28.         at java.lang.Thread.sleep(Native Method)                                             
  29.         at test.ThreadDumpTest$TR.run(ThreadDumpTest.java:45)                                
  30.         at java.lang.Thread.run(Thread.java:595)                                             
  31. “MyThread-1002” prio=1 tid=0x085099b8 nid=0x1bac waiting on condition [0xaa051000..0xaa051fa0]
  32.         at java.lang.Thread.sleep(Native Method)                                             
  33.         at test.ThreadDumpTest$TR.run(ThreadDumpTest.java:45)                                
  34.         at java.lang.Thread.run(Thread.java:595)                                             
  35. “MyThread-1001” prio=1 tid=0x08508a28 nid=0x1bab waiting
    on condition [0xaa0d2000..0xaa0d3020]
  36.         at java.lang.Thread.sleep(Native Method)                                             
  37.         at test.ThreadDumpTest$TR.run(ThreadDumpTest.java:45)
  38.         at java.lang.Thread.run(Thread.java:595)
  39. “MyThread-1000” prio=1 tid=0x08508520 nid=0x1baa waiting on condition [0xaa153000..0xaa153ea0]
  40.         at java.lang.Thread.sleep(Native Method)
  41.         at test.ThreadDumpTest$TR.run(ThreadDumpTest.java:45)
  42.         at java.lang.Thread.run(Thread.java:595)
  43. “Low Memory Detector” daemon prio=1 tid=0x0843cf58 nid=0x1ba8 runnable [0x00000000..0x00000000]
  44. “CompilerThread0” daemon prio=1 tid=0x0843b930 nid=0x1ba7 waiting on condition [0x00000000..0xaa3eb808]
  45. “Signal Dispatcher” daemon prio=1 tid=0x0843a9d0 nid=0x1ba6 waiting on condition [0x00000000..0x00000000]
  46. “Finalizer” daemon prio=1 tid=0x08430740 nid=0x1ba5 in Object.wait() [0xaa52c000..0xaa52d120]
  47.         at java.lang.Object.wait(Native Method)
  48.         – waiting on <0xaa6b0848> (a java.lang.ref.ReferenceQueue$Lock)
  49.         at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:116)
  50.         – locked <0xaa6b0848> (a java.lang.ref.ReferenceQueue$Lock)
  51.         at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:132)
  52.         at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)
  53. “Reference Handler” daemon prio=1 tid=0x0842e898 nid=0x1ba4 in Object.wait() [0xaa5ad000..0xaa5adfa0]
  54.         at java.lang.Object.wait(Native Method)
  55.         – waiting on <0xaa6b0758> (a java.lang.ref.Reference$Lock)
  56.         at java.lang.Object.wait(Object.java:474)
  57.         at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)
  58.         – locked <0xaa6b0758> (a java.lang.ref.Reference$Lock)
  59. “VM Thread” prio=1 tid=0x0842bb68 nid=0x1ba3 runnable
  60. “VM Periodic Task Thread” prio=1 tid=0x0843e538 nid=0x1ba9 waiting on condition
Update : FYI : You can automatically take a thread dump of a Java application when a high CPU threshold is violated by using Applications Manager.  Learn more orwatch a related video or download Applications Manager now.