Faster Mutt

Mutt is surly Men’s best friend when it comes to managing huge amount of emails with Powers in hand.

Some updates which I made to my .muttrc to make my Mutt faster (on Max OSX):

set header_cache         = /Volumes/ramdisk/headers
set sleep_time = 0
set timeout = 15         # idle time before scanning
set mail_check = 60      # minimum time between scans

As seen above, I am keeping the header cache on a ramdisk, it makes reading the same at least 50% faster. Create a RAM Disk of 100MB by running:

diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://204800`

In the example above 204800 means 100*2048, will create a ramdisk of 100MB.

You can see my .muttrc here, customized to my taste (or download from my github):

# Paths ----------------------------------------------
set folder           = ~/.mail               # mailbox location
set alias_file       = ~/.mutt/alias         # where to store aliases
#set header_cache     = ~/.mutt/cache/headers # where to store headers
set header_cache      = /Volumes/ramdisk/headers # where to store headers
#set message_cachedir = ~/.mutt/cache/bodies  # where to store bodies
set certificate_file = ~/.mutt/certificates  # where to store certs
set mailcap_path     = ~/.mutt/mailcap       # entries for filetypes
set tmpdir           = ~/.mutt/temp          # where to keep temp files
set signature        = ~/.mutt/sig           # my signature file

unset maildir_header_cache_verify 	# don't verify cache
folder-hook . 'set read_inc=10000'	# don't update progress too fast
set sleep_time = 0
bind index,pager f next-new-then-unread
bind index,pager F forward-message
bind index,pager b previous-new-then-unread
bind index,pager B bounce-message
bind index S sort-mailbox
auto_view text/html
set sendmail_wait=-1
set mime_forward=yes
set mime_forward_rest=yes

# Basic Options --------------------------------------
set wait_key = no        # shut up, mutt
set mbox_type = Maildir  # mailbox type
set timeout = 15         # idle time before scanning
set mail_check = 60      # minimum time between scans
unset move               # gmail does that
set delete               # don't ask, just do
unset confirmappend      # don't ask, just do!
set quit                 # don't ask, just do!!
unset mark_old           # read/new is good enough for me
unset beep_new           # bell on new mails
set pipe_decode          # strip headers and eval mimes when piping
set thorough_search      # strip headers and eval mimes before searching

# Sidebar Patch --------------------------------------
set sidebar_delim   = '  '
set sidebar_visible = yes
set sidebar_width   = 26
color sidebar_new color221 color233

# Sidebar Navigation ---------------------------------
bind index,pager    sidebar-next
bind index,pager      sidebar-prev
bind index,pager   sidebar-open

# Status Bar -----------------------------------------
set status_chars  = " *%A"
set status_format = "───[ Folder: %f ]───[%r%m messages%?n? (%n new)?%?d? (%d to delete)?%?t? (%t tagged)? ]───%>─%?p?( %p postponed )?───"

# Header Options -------------------------------------
ignore *                                # ignore all headers
unignore from: to: cc: date: subject: user-agent:   # show only these
unhdr_order *                           # some distros order things by default
hdr_order from: to: cc: date: subject: user-agent:  # and in this order

# Index View Options ---------------------------------
set date_format = "%D %r"
#set index_format = "[%Z]  %D (%4c)  %-30.30F %s"
set index_format="%4C %Z %D  %-22.22F  (%4c) %s"
set sort = reverse-date
#set sort_aux = reverse-last-date-received  # like gmail
#set uncollapse_jump                        # don't collapse on an unread message
#set sort_re                                # thread based on regex
set reply_regexp = "^(([Rr][Ee]?(\[[0-9]+\])?: *)?(\[[^]]+\] *)?)*"

# Index Key Bindings ---------------------------------
bind index gg       first-entry
bind index G        last-entry

bind index R        group-reply
bind index     sync-mailbox
bind index   collapse-thread

# Pager View Options ---------------------------------
set pager_index_lines = 10 # number of index lines to show
set pager_context = 3      # number of context lines to show
set pager_stop             # don't go to next message automatically
set menu_scroll            # scroll in menus
set tilde                  # show tildes like in vim
unset markers              # no ugly plus signs

set quote_regexp = "^( {0,4}[>|:#%]| {0,4}[a-z0-9]+[>|]+)+"
alternative_order text/plain text/enriched text/html

# Pager Key Bindings ---------------------------------
bind pager k  previous-line
bind pager j  next-line
bind pager gg top
bind pager G  bottom
set editor="vim -c 'set spell spelllang=en'"

bind pager R  group-reply

# View attachments properly.
bind attach  view-mailcap

# Ctrl-R to mark all as read
macro index \Cr "T~UN." "mark all messages as read"

# URL View
macro pager \Cu "|urlview" "call urlview to open links"

# Saner copy/move dialogs
macro index C "?" "copy a message to a mailbox"
macro index M "?" "move a message to a mailbox"

# Compose View Options -------------------------------
set realname = "Abhinav Gupta"	     # who am i?
set envelope_from                    # which from?
set sig_dashes                       # dashes before sig
set edit_headers                     # show headers when composing
set fast_reply                       # skip to compose when replying
set askcc                            # ask for CC:
set fcc_attach                       # save attachments with the body
#set mime_forward                    # forward attachments as part of body
set forward_format = "Fwd: %s"       # format of subject when forwarding
set forward_decode                   # decode when forwarding
set attribution = "On %d, %n wrote:" # format of quoting header
set reply_to                         # reply to Reply to: field
set reverse_name                     # reply as whomever it was to
set include                          # include message in replies
set forward_quote                    # include message in forwards
bind compose p postpone-message

# Contacts
set query_command = "contacts -Sf '%eTOKEN%n' '%s' | sed -e 's/TOKEN/\t/g'"
bind editor  complete-query
bind editor ^T    complete

Biggest Reference: Steve Losh’s guide to Homely Mutt.

Post on Twitter
Share on Facebook
Share on LinkedIn
Stumble Now!
Posted in General | Tagged , , , , , , , , , , , | Leave a comment

Automate offlineimap sync using Launchd on Mac OSX

I am now on a mutt + offlineimap setup for both my work and personal emails (love thy mutt), I will put a post later on why and how am I doing it, posting how to automatically run the offlineimap on a MacOSX (10.8) using Launchd.

Create a file in user’s LaunchAgents directory, the label naming convention that Apple uses a typically weird but okay as long as it works:

~/Library/LaunchAgents/org.abhinav.mail.abhinav.plist

My offlineimap plist file looks like this:

< ?xml version="1.0" encoding="UTF-8"?>
< !DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
                <string>org.abhinav.mail.abhinav</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/local/bin/offlineimap</string>
                <string>-a AbhinavAbhinavOrg</string>
        </array>
        <key>RunAtLoad</key>
                <true></true>
        <key>StartInterval</key>
                <integer>60</integer>
        <key>TimeOut</key>
                <integer>180</integer>
        <key>StandardErrorPath</key>
                <string>/Users/abhinav/log/offlineimap_abhinav_error.log</string>
        <key>StandardOutPath</key>
                <string>/Users/abhinav/log/offlineimap_abhinav.log</string>
</dict>
</plist>

Then run following to submit it to Launchd.

launchctl load ~/Library/LaunchAgents/org.abhinav.mail.abhinav.plist

In short, above plist file tells Launchd to start the offlineimap application with -a mailboxname argument every 60 minutes and start at load also, time it out if it’s running or stuck for more than 180 seconds and puts stdin and stderr in defined logs. Works beautifully for me.

I took help from here, here and Steve Losh’s guide to a homely mutt.

Post on Twitter
Share on Facebook
Share on LinkedIn
Stumble Now!
Posted in mail, open | Tagged , , , , , , , , , , , , | Leave a comment

Why nginx is faster than Apache

After doing considerable research over the Internet I found following as the major Advantages of using nginx vs using Apache.

Apache
1) Apache uses a blocking model of using threads for processing requests.
2) One thread is dedicated for serving one request.
3) The threads have to do sync with there Process so it’s a synchonous event.
4) Apache has to allocate ~1 MB per process just to start with, apache has to create process by cloning itself, consider apache with php, that itself is around 20 MB, now if apache starts 5 processes, memory footprint becomes 100 MB.
5) It’s basically useless to use threaded model on old CPUs (uni-threded).

nginx
1) nginx is a event based web server.
2) It uses (it’s own implementation of ) libevent and Reactor Pattern to process requests.
3) Event model is non-blocking and asynchronous.
4) nginx recives requests, transfers it to the system for processing without blocking the resources and listens to events using “kqueue, epoll/select” etc, when the data/document is processed and ready to be served, the request handler serves it back to the client.

After above research, it’ll be injustice if I do not give some credit to the Process vs Thread show.

Threads vs Processes

1) Processes need to be “forked” or “cloned” from Parent process, they are exact copy of parent to start with while threads are subset of a Process, it’s often termed as a “lightweight process”.
2) Processes have their own execution environment, memory space, kernel space and user space which threads share while execution.
3) Processes need to use Inter Process Communication for talking to other Processes which threads can talk to other threads within the same process directly and hence faster.
4) Threads run in same context as of their Parent Process, while a Process can alter the resources and contexts in the run-time of a program.

I stole many thoughts from here, here and here.

Post on Twitter
Share on Facebook
Share on LinkedIn
Stumble Now!
Posted in General, open, Web Servers | Tagged , , , , , , , , , | 3 Comments