»
S
I
D
E
B
A
R
«
Estimating NETWORK throughput
Feb 7th, 2013 by Anand Shah

On the assumption that you have tuned/tweeked your farm of realservers and you know that they are capable of delivering data to clients at a total rate of bits/sec or packets/sec, you need to design a director capable of routing this number of requests and replies for the clients.

First some background information on networking hardware. At least for Linux (the OS I’ve measured, see performance data for single server), a network rated at 100Mbps is not 100Mbps all the time. It’s only 100Mbps when continuously carrying packets of mtu size (1500bytes). A packet with 1 bit of data takes as long to transmit as a full mtu sized packet. If your packets are s, or 1 character packets from your telnet editing session or requests for http pages and images, you’ll barely reach 1Mbps on the same network. On the performance page, you’ll notice that the hit rate increases as the size of the hit targets (in bytes) gets smaller. Hit rate is not necessarily a good indicator of network throughput.

A possible explanation for the Ethernet rate being a function only of the packet rate is in an article on Gigabit Ethernet Jumbo Frames (look for the section “Local performance issues”) (also see jumbo frames). Each packet requires an interrupt and the per-packet processing overhead sets the limit for TCP performance. This has resulted in a push for larger (jumbo) packets with Gigabit ethernet (e.g. 64kB, a whole NFS frame). The original problem was that the MTU size chosen for 100Mbps ethernet (1500bytes) is the same as for 10Mbps ethernet. This was so that packets traversing the different types of ethernet would not have to be fragmented and defragmented. However the side effect was that the packets are too small for 100Mbps ethernet and you can double your ethernet throughput by doubling your packet size.

Tcpip can’t use the full 100Mbps of 100Mbps network hardware, as most packets are paired (data, ack; request, ack). A link carrying full mtu data packets and their corresponding s, will presumably be only carrying 50Mbps. A better measure of network capacity is the packet throughput. An estimate of the packet throughput comes from the network capacity (100Mbps)/mtu size(1500bytes) = 8333 packets/sec.

Script to check the throughput of your Network:-

    #!/bin/sh
    #Usage show_traffic.sh eth0
    #packets are sent at about 7000 packets/sec on my
    #100Mbps
    #
    #——————————————
    # setup a few things
    to=10 #sleep time
    trap return INT #trap ^C from the keyboard (used to exit the program)
    iface=”$1″ #NIC to listen on

    #——————————————
    function get_packets() {
    cat /proc/net/dev | sed -n “s/.*${iface}:\(.*\)/\1/p” | \
    awk ‘{ packets += $2} ; END { print packets }’
    }

    function call_get_packets() {
    while true
    do
    sleep $to
    p1=”`get_packets “$iface”`”
    echo “$((($p1-$p0)/$to)) packets/sec”
    p0=”$p1″
    done
    }
    #——————————————-
    echo “Hit control-C to exit”

    #initialise packets at $iface
    p0=”`get_packets “$iface”`”

    call_get_packets

    #——————————————-

Hope this helps you !

Logs location for Plesk Linux Servers
Jan 22nd, 2013 by Anand Shah

Control Panel

Error log: /var/log/sw-cp-server/error_log
Access log: /usr/local/psa/admin/logs/httpsd_access_log
Panel log: /usr/local/psa/admin/logs/panel.log
service control:

Stop:

/etc/init.d/psa stop

Start:

/etc/init.d/psa start

Restart:

/etc/init.d/psa restart

config files:

php: /usr/local/psa/admin/conf/php.ini
www: /etc/sw-cp-server/applications.d/plesk.conf
features: /usr/local/psa/admin/conf/site_isolation_settings.ini

Sitebuilder

Log: /usr/local/psa/admin/logs/sitebuilder.log
Install / upgrade Logs: /usr/local/sb/tmp/
service control:

No service control (working via sw-cp-server service).
config files:

/usr/local/sb/config
/etc/sw-cp-server/applications.d/plesk.conf
/usr/local/psa/admin/conf/php.ini

Billing

Error Log: /var/log/sw-cp-server/error_log
Access log: /usr/local/psa/admin/logs/httpsd_access_log
service control:

No service control (working via sw-cp-server service).
config files:

/usr/local/psa/admin/conf/php.ini
/etc/sw-cp-server/applications.d/plesk.conf
/opt/plesk-billing/htdocs/lib-billing/include/config/config.php

SSO

Error Log: /var/log/sw-cp-server/error_log
SSO log: /var/log/sso/sso.log
service control:

No service control (working via sw-cp-server service).

Utility to configure SSO & Panel integration:

/usr/local/psa/bin/sso
config files:

/etc/sw-cp-server/applications.d/00-sso-cpserver.conf
/etc/sso/sso_config.ini

phpMyAdmin

Error log: /var/log/sw-cp-server/error_log
service control:

No service control (working via sw-cp-server service).
config files:

/usr/local/psa/admin/htdocs/domains/databases/phpMyAdmin/libraries/config.default.php

phpPGAdmin

Error log: /var/log/sw-cp-server/error_log
service control:

No service control (working via sw-cp-server service).
config files:

/usr/local/psa/admin/htdocs/domains/databases/phpPgAdmin/conf/config.inc.php/p>

Courier-IMAP

Access and error log: /usr/local/psa/var/log/maillog
service control:

Stop:

/etc/init.d/courier-imap stop

Start:

/etc/init.d/courier-imap start

Restart:

/etc/init.d/courier-imap restart
config files:

/etc/courier-imap/imapd
/etc/courier-imap/imapd-ssl
/etc/courier-imap/pop3d
/etc/courier-imap/pop3d-ssl

SMTP server (QMail)

Access and error log: /usr/local/psa/var/log/maillog
service control:

Stop:

/etc/init.d/qmail stop

Start:

/etc/init.d/qmail start

Restart:

/etc/init.d/qmail restart
config files:

/etc/xinetd.d/smtp_psa
/etc/xinetd.d/smtps_psa
/etc/xinetd.d/submission_psa
/etc/inetd.conf (Debians)
/var/qmail/control/

Named (BIND, DNS)

Access and error log: /var/log/messages
service control:

Stop:

/etc/init.d/named stop

Start:

/etc/init.d/named start

Restart:

/etc/init.d/named restart
config files:

/etc/named.conf

Tomcat

Access and error logs: /var/log/tomcat5/
service control:

Stop:

/etc/init.d/tomcat5 stop

Start:

/etc/init.d/tomcat5

Restart:

/etc/init.d/tomcat5
config files:

/usr/share/tomcat5/conf/

MySQL

Access and error log: /var/log/mysqld.log
service control:

Stop:

/etc/init.d/mysqld stop

Start:

/etc/init.d/mysqld start

Restart:

/etc/init.d/mysqld restart
config files:

/etc/my.cnf

Postgresql

Startup log: /var/lib/pgsql/pgstartup.log
service control:

Stop:

/etc/init.d/postgresql stop

Start:

/etc/init.d/postgresql start

Restart:

/etc/init.d/postgresql restart
config files:

/var/lib/pgsql/data/postgresql.conf

Plesk SpamAssassin

Access and error log: /usr/local/psa/var/log/maillog
service control:

Stop:

/etc/init.d/psa-spamassassin stop

Start:

/etc/init.d/psa-spamassassin start

Restart:

/etc/init.d/psa-spamassassin restart
config files:

/etc/mail/spamassassin/
/etc/mail/spamassassin/local.cf
/var/qmail/mailnames/%d/%l/.spamassassin

Drweb antivirus

Access and error log: /usr/local/psa/var/log/maillog
service control:

Stop:

/etc/init.d/drwebd stop

Start:

/etc/init.d/drwebd start

Restart:

/etc/init.d/drwebd restart
config files:

/etc/drweb/

FTP(proftpd)

Access and error log: /usr/local/psa/var/log/xferlog
service control:

No service control (working via xinetd service).
config files:

/etc/xinetd.d/ftp_psa
/etc/proftpd.conf
/etc/proftpd.include

Kaspersky antivirus

Log: /usr/local/psa/var/log/maillog
Before 10.2:

/var/log/kav/5.5/kav4mailservers/aveserver.log
/var/log/kav/5.5/kav4mailservers/smtpscanner.log
/var/log/kav/5.5/kav4mailservers/avstats.log
/var/log/kav/5.5/kav4mailservers/kavscanner.log
/var/log/kav/5.5/kav4mailservers/kavupdater.log
service control:
Since 10.2:

Stop:

/etc/init.d/kavehost stop

Start:

/etc/init.d/kavehost start

Restart:

/etc/init.d/kavehost restart
Before 10.2:

Stop:

/etc/init.d/aveserver stop

Start:

/etc/init.d/aveserver start

Restart:

/etc/init.d/aveserver restart
config files:
Before 10.2:

/etc/kav/5.5/kav4mailservers/
Since 10.2:

/opt/kav/sdk8l3/etc/kav-handler.cfg
/etc/kavehost.xml

SMTP server (Postfix)

Access and error log: /usr/local/psa/var/log/maillog
service control:

Stop:

/etc/init.d/postfix stop

Start:

/etc/init.d/postfix start

Restart:

/etc/init.d/postfix restart
config files:

/etc/postfix/
xinetd

Access and error log: /var/log/messages
service control:

Stop:

/etc/init.d/xinetd stop

Start:

/etc/init.d/xinetd start

Restart:

/etc/init.d/xinetd restart
config files:

/etc/xinetd.conf

Watchdog (monit)

Log files: /usr/local/psa/var/modules/watchdog/log/wdcollect.log
/usr/local/psa/var/modules/watchdog/log/monit.log
service control:

Stop:

/usr/local/psa/admin/bin/modules/watchdog/wd –stop

Start:

/usr/local/psa/admin/bin/modules/watchdog/wd –start

Restart:

/usr/local/psa/admin/bin/modules/watchdog/wd –restart
config files:

/usr/local/psa/etc/modules/watchdog/monitrc
/usr/local/psa/etc/modules/watchdog/wdcollect.inc.php

Watchdog (rkhunter)

Log: /var/log/rkhunter.log
service control:

Start:

/usr/local/psa/admin/bin/modules/watchdog/rkhunter
config files:

/usr/local/psa/etc/modules/watchdog/rkhunter.conf

Mailman (Maillist service)

Log files: /var/log/mailman/
service control:

Stop:

/etc/init.d/mailman stop

Start:

/etc/init.d/mailman start

Restart:

/etc/init.d/mailman restart
config files:

/etc/httpd/conf.d/mailman.conf
/usr/lib/mailman/Mailman/mm_cfg.py
/etc/mailman/sitelist.cfg

AWstats

service control:

Start:

/usr/local/psa/bin/sw-engine-pleskrun /usr/local/psa/admin/plib/DailyMaintainance/script.php
config files:

/usr/local/psa/etc/awstats/

Webalizer

service control:

Start:

/usr/local/psa/bin/sw-engine-pleskrun /usr/local/psa/admin/plib/DailyMaintainance/script.php
config files:

/var/www/vhosts/%d/conf/webalizer.conf

Plesk Backup Manager

Backup logs: /usr/local/psa/PMM/sessions//psadump.log
/usr/local/psa/PMM/sessions//migration.log
/usr/local/psa/PMM/logs/migration.log
/usr/local/psa/PMM/logs/pmmcli.log
Restore logs: /usr/local/psa/PMM/rsessions//conflicts.log
/usr/local/psa/PMM/rsessions//migration.log
/usr/local/psa/PMM/logs/migration.log
/usr/local/psa/PMM/logs/pmmcli.log
service control:

Functionality is controlled by the Plesk Control Panel service.
config files:

/etc/psa/psa.conf

Plesk Migration Manager

Migration logs: /usr/local/psa/PMM/msessions//migration.log
/usr/local/psa/PMM/rsessions//migration.log
/usr/local/psa/PMM/rsessions//conflicts.log
/usr/local/psa/PMM/logs/migration.log
/usr/local/psa/PMM/logs/pmmcli.log
/usr/local/psa/PMM/logs/migration_handler.log
service control:

Functionality is controlled by the Plesk Control Panel service.

Horde

Log: /var/log/psa-horde/psa-horde.log
service control:

Functionality is controlled by the Plesk Control Panel service.
config files:

apache configs: /etc/httpd/conf.d/zzz_horde_vhost.conf
/etc/psa-webmail/horde/conf.d/
horde configs: /etc/psa-webmail/horde/

Atmail

Logs: /var/log/atmail/
service control:

Functionality is controlled by the Plesk Control Panel service.
config files:

apache configs: /etc/httpd/conf.d/zzz_atmail_vhost.conf
/etc/psa-webmail/atmail/conf.d/
Atmail configs: /etc/psa-webmail/atmail/atmail.conf
/var/www/atmail/libs/Atmail/Config.php

psa-logrotate

No logs
service control:

Start:

/usr/local/psa/bin/sw-engine-pleskrun /usr/local/psa/admin/plib/DailyMaintainance/script.php
config files:

/usr/local/psa/etc/logrotate.conf
/usr/local/psa/etc/logrotate.d/

Samba

Logs: /var/log/samba/
service control:

Stop:

/etc/init.d/smb stop

Start:

/etc/init.d/smb start

Restart:

/etc/init.d/smb restart
config files:

/etc/samba/smb.conf
/etc/samba/smb.conf.include

psa-firewall

service control:

Stop:

/etc/init.d/psa-firewall stop

Start:

/etc/init.d/psa-firewall start

Restart:

/etc/init.d/psa-firewall restart
config files:

/usr/local/psa/var/modules/firewall/firewall-active.sh
/usr/local/psa/var/modules/firewall/firewall-emergency.sh
/usr/local/psa/var/modules/firewall/firewall-new.sh
psa-firewall (IP forwarding)
service control:

Stop:

/etc/init.d/psa-firewall-forward stop

Start:

/etc/init.d/psa-firewall-forward start

Restart:

/etc/init.d/psa-firewall-forward restart
config files:

/usr/local/psa/var/modules/firewall/ip_forward.active
/usr/local/psa/var/modules/firewall/ip_forward.saved

psa-vpn

service control:

Stop:

/etc/init.d/smb stop

Start:

/etc/init.d/smb start

Restart:

/etc/init.d/smb restart
config files:

/usr/local/psa/var/modules/vpn/openvpn.conf

Health Monitor

Logs: /usr/local/psa/admin/logs/health-alarm.log
service control:

Stop:

/etc/init.d/sw-collectd stop

Start:

/etc/init.d/sw-collectd start

Restart:

/etc/init.d/sw-collectd restart
config files:

/usr/local/psa/admin/conf/health-config.xml
/usr/local/psa/var/custom-health-config.xml
/etc/sw-collectd/collectd.conf

Parallels Panel Health Monitor Notification Daemon

Logs: /usr/local/psa/admin/logs/health-alarm.log
service control:

Stop:

/etc/init.d/psa-health-monitor-notificationd stop

Start:

/etc/init.d/psa-health-monitor-notificationd start

Restart:

/etc/init.d/psa-health-monitor-notificationd restart
config files:

/usr/local/psa/admin/conf/health-config.xml
/usr/local/psa/var/custom-health-config.xml

Web server (Apache)

Access and Error logs: /var/log/httpd/
Plesk domains logs: /var/www/vhosts/%d/statistics/logs/
service control:

Stop:

/etc/init.d/httpd stop

Start:

/etc/init.d/httpd start

Restart:

/etc/init.d/httpd restart
config files:

/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/
/usr/local/psa/admin/conf/ip_vhosts_bootstrap.conf
/usr/local/psa/admin/conf/vhosts_bootstrap.conf
/usr/local/psa/admin/conf/webmail_atmail_bootstrap.conf
/usr/local/psa/admin/conf/webmail_atmailcom_bootstrap.conf
/usr/local/psa/admin/conf/webmail_horde_bootstrap.conf
Generated config files:
/usr/local/psa/admin/conf/generated/_server.include
/var/www/vhosts//conf/_httpd.include
/usr/local/psa/admin/conf/generated/_horde.include
/usr/local/psa/admin/conf/generated/_atmail.include
/usr/local/psa/admin/conf/generated/_atmailcom.include
/usr/local/psa/admin/conf/generated/__webmail.include

SPF Record For Email Deliverability
Jun 21st, 2012 by Anand Shah

If you’ve taken a look at your spam box recently you’ll notice that a great many of those spam messages are attempting to use forged email addresses to trick you into opening them. Forged Email addresses claiming everyone from Facebook, UPS, DHL, and the CIA have attempted to trick me into opening their emails. A new standard known as Sender Policy Framework (SPF) became necessary to prevent such email forgeries. This standard has been implemented by many ISPS and mail hosts, including major providers such as Gmail, AOL, MSN/Hotmail, and Bell South. As a result domains require an SPF record for their mail systems if they want their emails to be accepted by those providers.
Simply put, Sender Policy Framework is a method for preventing sender address forgery. What do we mean by sender address? Think of a traditional paper letter that you send out to someone. Your letter may have a one address in the letterhead, the address of your specific department, and an altogether different address on the envelope, the address of the institution that your department belongs to. The address that’s on the envelope is known as the envelope sender address when you send an email. It’s the return-path that is used when you transport a message from mail server to mail server. This address is not usually shown to users by mail programs. The header sender address of an email message is what you seen in the “From” or “Sender” Address in your email client. Mail servers do not typically care what the header sender address is when delivering a message.
An SPF record protects the envelope sender address which is used for the actual delivery of the email message. This allows the owner of a domain to take ownership of their mail policy, e.g., which mail servers they will use to send emails from their domain. First, the domain owner publishes information in an SPF record in their domain’s DNS Zone. When another mail server receives a message that claims to come from that domain the receiving server is able to check whether the message complies with the domain’s stated policy. Thus it will know whether the message is a forgery.
Once the authenticity of the sender address is established a reputation can be attached to it. Establishing a reputation based on the domain will become more prevalent in the future even when it comes to individual email addresses. For this reason it’s important to set up an SPF record on your From sender’s domain if you have not already done so.

How to setup the SPF record

The biggest obstacle you will face is in how to write and create a proper SPF record which is correct for your domain, as any SMTP server used to send email for that domain must be defined. The DNS syntax for an SPF record may look like this:

    Example: IN TXT “v=spf1 a mx –all”

Some set up wizards for setting up valid SPF DNS entries can be found here:
• Record Setup Wizard
• Sender ID Framework SPF Record Wizard

We strongly suggest using the above wizards and following their instructions for completing your SPF setup.
You’ll begin by entering in the domain you wish to set up the SPF record for in order to find out if any existing SPF records can be found. If an existing record is found then the wizard will allow you to modify it. If no record is found then you can proceed with the wizard to set one up.
A mail exchanger record (MX record) is a type of resource record in the Domain Name System (DNS) that specifies a mail server responsible for accepting email messages on behalf of recipient’s domain and a preference value used to prioritize mail delivery if multiple mail servers are available. The set of MX records of a domain specify how email should be routed with Simple Mail Transfer Protocol (SMTP).

The wizard should give you the option to select whether your domain’s inbound servers may send mail. The wizard will detect any IP addresses listed in A records for your domain in DNS . The ip address listed is for sending out mail from your outbound mail server. You can also use the SPF wizard to enter in any additional IP addresses that you want to add to your SPF record. If you have questions specific to what options you need to select it is suggested that you contact your server admin or hosting provider.

When your SPF record is generated you’ll notice that all SPF records start out with something like v=spf1. V defines the version of SPF used and ifs mandatory to identify it’s an SPF record.

Now, copy and paste the text to the DNS entry as a TXT record. Your record may be in quotes depending. You may or may not have to exclude quotation marks depending on your DNS system.

How to verify that your SPF record is setup properly

Each domain name registrar will have a slightly different procedure for adding the SPF record to your domain name’s TXT entry. This option is generally under the “manage domains” options. If you do not see this option, your registrar’s support center will be able to assist you, or can insert the SPF record for you. Once you add the SPF record it may take between 30 minutes and 48 hours for the changes to your DNS record to take effect.
Once you have set up an SPF record you can use the following form to validate whether or not your SPF record is set up properly:

  • http://www.kitterman.com/spf/validate.html
  • You can use the following tool to simply look up an existing record:

  • http://www.mxtoolbox.com/spf.aspx
  • http://dkimcore.org/c/keycheck
  • Understanding work-load averages as opposed to CPU usage
    May 23rd, 2011 by Anand Shah

    Is uptime the best measure of system efficiency?

    In effort to find out the answer i came across a good document by Mr Ray walker from linux journal docs and putting it as it is.

    Understanding work-load averages as opposed to CPU usage.

    Many Linux administrators and support technicians regularly use the top utility for real-time monitoring of their system state. In some shops, it is very typical to check top first when there is any sign of trouble. In that case, top becomes the de facto critical measurement of the machine’s health. If top looks good, there must not be any system problems. top is rich with information—memory usage, kernel states, process priorities, process owner and so forth all can be obtained from top. But, what is the purpose of those three curious load averages, and what exactly are they trying to tell me? To answer those questions, an intuitive as well as a detailed understanding of how the values are formed are necessary. Let’s start with intuition.

    The Intuitive Interpretation

    The three load-average values in the first line of top output are the 1-minute, 5-minute and 15-minute average. (These values also are displayed by other commands, such as uptime, not only top.) That means, reading from left to right, one can examine the aging trend and/or duration of the particular system state. The state in question is CPU load—not to be confused with CPU percentage. In fact, it is precisely the CPU load that is measured, because load averages do not include any processes or threads waiting on I/O, networking, databases or anything else not demanding the CPU. It narrowly focuses on what is actively demanding CPU time. This differs greatly from the CPU percentage. The CPU percentage is the amount of a time interval (that is, the sampling interval) that the system’s processes were found to be active on the CPU. If top reports that your program is taking 45% CPU, 45% of the samples taken by top found your process active on the CPU. The rest of the time your application was in a wait. (It is important to remember that a CPU is a discrete state machine. It really can be at only 100%, executing an instruction, or at 0%, waiting for something to do. There is no such thing as using 45% of a CPU. The CPU percentage is a function of time.) However, it is likely that your application’s rest periods include waiting to be dispatched on a CPU and not on external devices. That part of the wait percentage is then very relevant to understanding your overall CPU usage pattern.

    The load averages differ from CPU percentage in two significant ways: 1) load averages measure the trend in CPU utilization not only an instantaneous snapshot, as does percentage, and 2) load averages include all demand for the CPU not only how much was active at the time of measurement.

    Authors tend to overuse analogies and sometimes run the risk of either insulting the reader’s intelligence or oversimplifying the topic to the point of losing important details. However, freeway traffic patterns are a perfect analogy for this topic, because this model encapsulates the essence of resource contention and is also the chosen metaphor by many authors of queuing theory books. Not surprisingly, CPU contention is a queuing theory problem, and the concepts of arrival rates, Poisson theory and service rates all apply. A four-processor machine can be visualized as a four-lane freeway. Each lane provides the path on which instructions can execute. A vehicle can represent those instructions. Additionally, there are vehicles on the entrance lanes ready to travel down the freeway, and the four lanes either are ready to accommodate that demand or they’re not. If all freeway lanes are jammed, the cars entering have to wait for an opening. If we now apply the CPU percentage and CPU load-average measurements to this situation, percentage examines the relative amount of time each vehicle was found occupying a freeway lane, which inherently ignores the pent-up demand for the freeway—that is, the cars lined up on the entrances. So, for example, vehicle license XYZ 123 was found on the freeway 30% of the sampling time. Vehicle license ABC 987 was found on the freeway 14% of the time. That gives a picture of how each vehicle is utilizing the freeway, but it does not indicate demand for the freeway.

    Moreover, the percentage of time these vehicles are found on the freeway tells us nothing about the overall traffic pattern except, perhaps, that they are taking longer to get to their destination than they would like. Thus, we probably would suspect some sort of a jam, but the CPU percentage would not tell us for sure. The load averages, on the other hand, would.

    This brings us to the point. It is the overall traffic pattern of the freeway itself that gives us the best picture of the traffic situation, not merely how often cars are found occupying lanes. The load average gives us that view because it includes the cars that are queuing up to get on the freeway. It could be the case that it is a nonrush-hour time of day, and there is little demand for the freeway, but there just happens to be a lot of cars on the road. The CPU percentage shows us how much the cars are using the freeway, but the load averages show us the whole picture, including pent-up demand. Even more interesting, the more recent that pent-up demand is, the more the load-average value reflects it.

    Taking the discussion back to the machinery at hand, the load averages tell us by increasing duration whether our physical CPUs are over- or under-utilized. The point of perfect utilization, meaning that the CPUs are always busy and, yet, no process ever waits for one, is the average matching the number of CPUs. If there are four CPUs on a machine and the reported one-minute load average is 4.00, the machine has been utilizing its processors perfectly for the last 60 seconds. This understanding can be extrapolated to the 5- and 15-minute averages.

    In general, the intuitive idea of load averages is the higher they rise above the number of processors, the more demand there is for the CPUs, and the lower they fall below the number of processors, the more untapped CPU capacity there is. But all is not as it appears.

    The Wizard behind the Curtain
    The load-average calculation is best thought of as a moving average of processes in Linux’s run queue marked running or uninterruptible. The words “thought of” were chosen for a reason: that is how the measurements are meant to be interpreted, but not exactly what happens behind the curtain. It is at this juncture in our journey when the reality of it all, like quantum mechanics, seems not to fit the intuitive way as it presents itself.

    The load averages that the top and uptime commands display are obtained directly from /proc. If you are running Linux kernel 2.4 or later, you can read those values yourself with the command cat /proc/loadavg. However, it is the Linux kernel that produces those values in /proc. Specifically, timer.c and sched.h work together to do the computation. To understand what timer.c does for a living, the concept of time slicing and the jiffy counter help round out the picture.

    In the Linux kernel, each dispatchable process is given a fixed amount of time on the CPU per dispatch. By default, this amount is 10 milliseconds, or 1/100th of a second. For that short time span, the process is assigned a physical CPU on which to run its instructions and allowed to take over that processor. More often than not, the process will give up control before the 10ms are up through socket calls, I/O calls or calls back to the kernel. (On an Intel 2.6GHz processor, 10ms is enough time for approximately 50-million instructions to occur. That’s more than enough processing time for most application cycles.) If the process uses its fully allotted CPU time of 10ms, an interrupt is raised by the hardware, and the kernel regains control from the process. The kernel then promptly penalizes the process for being such a hog. As you can see, that time slicing is an important design concept for making your system seem to run smoothly on the outside. It also is the vehicle that produces the load-average values.

    The 10ms time slice is an important enough concept to warrant a name for itself: quantum value. There is not necessarily anything inherently special about 10ms, but there is about the quantum value in general, because whatever value it is set to (it is configurable, but 10ms is the default), it controls how often at a minimum the kernel takes control of the system back from the applications. One of the many chores the kernel performs when it takes back control is to increment its jiffies counter. The jiffies counter measures the number of quantum ticks that have occurred since the system was booted. When the quantum timer pops, timer.c is entered at a function in the kernel called timer.c:do_timer(). Here, all interrupts are disabled so the code is not working with moving targets. The jiffies counter is incremented by 1, and the load-average calculation is checked to see if it should be computed. In actuality, the load-average computation is not truly calculated on each quantum tick, but driven by a variable value that is based on the HZ frequency setting and tested on each quantum tick. (HZ is not to be confused with the processor’s MHz rating. This variable sets the pulse rate of particular Linux kernel activity and 1HZ equals one quantum or 10ms by default.) Although the HZ value can be configured in some versions of the kernel, it is normally set to 100. The calculation code uses the HZ value to determine the calculation frequency. Specifically, the timer.c:calc_load() function will run the averaging algorithm every 5 * HZ, or roughly every five seconds. Following is that function in its entirety:

    unsigned long avenrun[3];

    static inline void calc_load(unsigned long ticks)
    {
    unsigned long active_tasks; /* fixed-point */
    static int count = LOAD_FREQ;

    count -= ticks;
    if (count < 0) {
    count += LOAD_FREQ;
    active_tasks = count_active_tasks();
    CALC_LOAD(avenrun[0], EXP_1, active_tasks);
    CALC_LOAD(avenrun[1], EXP_5, active_tasks);
    CALC_LOAD(avenrun[2], EXP_15, active_tasks);
    }
    }

    The avenrun array contains the three averages we have been discussing. The calc_load() function is called by update_times(), also found in timer.c, and is the code responsible for supplying the calc_load() function with the ticks parameter. Unfortunately, this function does not reveal its most interesting aspect: the computation itself. However, that can be located easily in sched.h, a header used by much of the kernel code. In there, the CALC_LOAD macro and its associated values are available:

    extern unsigned long avenrun[]; /* Load averages */

    #define FSHIFT 11 /* nr of bits of precision */
    #define FIXED_1 (1< #define LOAD_FREQ (5*HZ) /* 5 sec intervals */
    #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */
    #define EXP_5 2014 /* 1/exp(5sec/5min) */
    #define EXP_15 2037 /* 1/exp(5sec/15min) */

    #define CALC_LOAD(load,exp,n) \
    load *= exp; \
    load += n*(FIXED_1-exp); \
    load >>= FSHIFT;

    Here is where the tires meet the pavement. It should now be evident that reality does not appear to match the illusion. At least, this is certainly not the type of averaging most of us are taught in grade school. But it is an average nonetheless. Technically, it is an exponential decay function and is the moving average of choice for most UNIX systems as well as Linux. Let’s examine its details.

    The macro takes in three parameters: the load-average bucket (one of the three elements in avenrun[]), a constant exponent and the number of running/uninterruptible processes currently on the run queue. The possible exponent constants are listed above: EXP_1 for the 1-minute average, EXP_5 for the 5-minute average and EXP_15 for the 15-minute average. The important point to notice is that the value decreases with age. The constants are magic numbers that are calculated by the mathematical function shown below:

    When x=1, then y=1884; when x=5, then y=2014; and when x=15, then y=2037. The purpose of the magical numbers is that it allows the CALC_LOAD macro to use precision fixed-point representation of fractions. The magic numbers are then nothing more than multipliers used against the running load average to make it a moving average. (The mathematics of fixed-point representation are beyond the scope of this article, so I will not attempt an explanation.) The purpose of the exponential decay function is that it not only smooths the dips and spikes by maintaining a useful trend line, but it accurately decreases the quality of what it measures as activity ages. As time moves forward, successive CPU events increase their significance on the load average. This is what we want, because more recent CPU activity probably has more of an impact on the current state than ancient events. In the end, the load averages give a smooth trend from 15 minutes through the current minute and give us a window into not only the CPU usage but also the average demand for the CPUs. As the load average goes above the number of physical CPUs, the more the CPU is being used and the more demand there is for it. And, as it recedes, the less of a demand there is. With this understanding, the load average can be used with the CPU percentage to obtain a more accurate view of CPU activity.

    It is my hope that this serves not only as a practical interpretation of Linux’s load averages but also illuminates some of the dark mathematical shadows behind them. For more information, a study of the exponential decay function and its applications would shed more light on the subject. But for the more practical-minded, plotting the load average vs. a controlled number of processes (that is, modeling the effects of the CALC_LOAD algorithm in a controlled loop) would give you a feel for the actual relationship and how the decaying filter applies.

    Ray Walker is a consultant specializing in UNIX kernel-level code. He has been a software developer for more than 25 years, working with Linux since 1995. He can be contacted at ray.rwalk2730@gmail.com.

    delete directory function in PHP
    Dec 11th, 2010 by Anand Shah

    Was looking for delete directory function in PHP which could delete directories and its data..finally landed with some options avilable on Internet shared by friends and some innovation.

    Here is the output :

    function delete_directory($homepath) {
    if (is_dir($homepath))
    $dir_handle = opendir($homepath);
    if (!$dir_handle)
    return false;
    while($file = readdir($dir_handle)) {
    if ($file != “.” && $file != “..”) {
    if (!is_dir($homepath.”/”.$file))
    unlink($homepath.”/”.$file);
    else
    delete_directory($homepath.’/’.$file);
    }
    }
    closedir($dir_handle);
    rmdir($homepath);
    return true;
    }

    Hotmail deleted all my mails
    Aug 5th, 2010 by Anand Shah

    Hotmail……. it just annoys me when i hear that name…….I was a frequent hotmail user and suddenly one day i found my Inbox which holds not less than 5000 mails is now a count zero. I raised a concern to the hotmail support team and request them to atleast migrate my mails ot a newly created live.in id. But it just proved to be a failed attempt………….

    This will sound harsh, but you need to learn from this lesson.

    Stop using HotMail.

    I’m serious. Stop using HotMail, or for that matter any web-based email service for anything that you would consider to be “important”.

    If your email and your contacts are truly important, if losing them would be a serious problem for you, as it apparently has, then invest in a ‘real’ POP3 email account from an email service provider or from your ISP. Then use a ‘real’ email program like Outlook, or Eudora, or Thunderbird or any of a number of other good email programs that run on your machine to manage your email.

    I am sharing the response i received from the support team which is more annoying,

      Hi anandshah1983,

      I tried to retrieve your e-mails but I wasn’t able to recover any. I’m sorry to tell you that we can no longer recover your mails.

      Check out this Solution Article on the causes of lost e-mails and how you can prevent them:

      Emails are missing from your Windows Live Hotmail account

      https://windowslivehelp.com/solution.aspx?solutionid=66b7e7be-6723-4d38-8c62-a58f03e4130e

    When i digged in i found that i was a coolhotmail user which allows you to create customised email accounts and my email id was anand.shah@coolaquarius.com ; the domain coolaqaurius was expired and none of the hotmail managers even cared about of saving a promoted product for the sake of company’s name. I am able to login but would never get my emails back ever.

    STOP USING HOTMAIL !!!!!

    Fix FTP Passive Mode Problems on Amazon EC2 Instances
    Jun 8th, 2010 by Anand Shah

    Today i faced ftp issues while using Amazon EC2. Nothing seemed to be difficult when i started but strated creating problems when i was prompted with errors saying

    ” ftp 421 Service not available, remote server has closed connection “

    After some efforts i figured out the issue was because passive mode was not able to recognize the port and passive server address from the server.

    I decided enough was enough and set about problem-solving: my favourite. It turns out, as usual, the problem relates to the ports the EC2 firewall opens for its instances, namely, none at all. Since passive mode connects to any random port > 1023, this is a problem. So, what you will need to do is define a fixed port range for VSFTP to use for PASV connections and then allow these in your “Security Groups” firewall rules.

    1. Specify a port range in which VSFTP will run PASV connections

    Add the following lines to your vsftpd.conf file:

      pasv_enable=YES
      pasv_max_port=12100
      pasv_min_port=12000
      port_enable=YES

    MOST IMPORTANTLY
    You also need to add an extra line to specify which IP address VSFTP will advertise in response to a passive connection, so underneath the lines you’ve already pasted in vsftpd.conf, put:

      pasv_address={your public IP address}

    OR if you don’t have a fixed elastic IP address:

      pasv_addr_resolve={your public domain or DNS}


    2. Authorise required ports in a security group that applies to your instance

    This can be done via the AWS management console (Amazon’s EC2 web control panel), or in your own console:

      ec2-authorize default -p 20-21
      ec2-authorize default -p 12000-12100

    Now restart vsftpd by typing

      /etc/init.d/vsftpd restart

    in your server’s terminal.

    DNS Error on Plesk
    May 24th, 2010 by Anand Shah

    I was really pissed up with this error on Plesk while suspending a site. I wasted 2 hours to get rid of this error. Luckily i got one solution….

    Error:
    Table::select() failed: no such row in the table

    MS-ACESSS as PLESK DB:

    1. we need a MS Access Database editor to open the plesk Database.

    2. Open query analyzer and find domains which have missed ID in Plesk database with following command :

      SELECT d.name FROM domains d LEFT JOIN dns_zone z ON d.dns_zone_id=z.id WHERE z.id IS NULL;

    3. Create appropriate id records with following commands, do not forget to replace DOMAN-NAME with a real domain name and ADMIN-EMAIL with a correct email:

      INSERT INTO dns_zone (name, displayName, email) VALUES (’DOMAIN-NAME’, ‘DOMAIN-NAME’, ‘ADMIN-EMAIL’);

    4. Know new zone ID:

      SELECT id, name FROM dns_zone where name=’DOMAIN-NAME’;

    5. Enter substitute correct ID into psa.domains table, don’t forget to replace DOMAN-NAME and DNS-ZONE-ID with correct values:

      UPDATE domains SET dns_zone_id=’DNS-ZONE-ID’ WHERE name=’DOMAIN-NAME’;

    Then log into Plesk panel, for each corrected domain go to domain.com > DNS and use Default button to re-generate DNS records. After this the error disappear.

    Finally helped out….myself

    SQL Server 2005 Express: Express Manager, Management Studio, downloads, & limitations
    Apr 20th, 2010 by Anand Shah

    SQL Server 2005 Express Edition is a scaled down version of Microsoft SQL Server 2005. Although the database server is limited in enterprise features, most of the limitations do not affect the database performance for what it is meant to do.

    Performance limitations in SQL Server Express

    The SQL engine of SQL Server Express supports 1 CPU, 1 GB RAM and a 4 GB database size. This distinction gives SQL Server Express well defined cut-off points to differentiate it from other SQL Server 2005 editions. Unlike MSDE, SQL Server Express eliminates the confusion created by the workload governor.

    1 CPU: SQL Server Express can install and run on multiprocessor machines, but only a single CPU is used at any time. This limitation prevents the use of parallel query execution in SQL Server Express.

    1 GB RAM: The 1 GB RAM limit is the memory limit available for the buffer pool. The buffer pool is used to store data pages and other information. However, memory needed to keep track of connections, locks, etc. is not counted toward the buffer pool limit. It is therefore possible that the server will use more than 1 GB in total, but it will never use more than 1GB for the buffer pool. This limitation prevents the use of Address Windowing Extensions (AWE) with SQL Server Express.

    4 GB Database Size: The 4 GB database size limit applies only to data files and not to log files. However, there are no limits to the number of databases that can be attached to the server. There are some minor changes to the startup of SQL Server Express. User databases are not automatically started, and DTC is not automatically initialized. For the user experience, though, there should be no difference other than a faster startup. Applications planning to use SQL Server Express are recommended to keep these changes in mind when designing their applications.

    SQL Server Management Studio Express (SSMSE)

    SQL Server Express does not ship with any management tools. However, you can download basic management tools from Microsoft. For streamlined management with fast and efficient user interface, download a copy of Teratrax Database Manager. Teratrax Database Manager provides a number of enhanced productivity features.

    Limitation in enterprise features

    The following SQL Server 2005 enterprise level features are not available in SQL Server 2005 Express Edition:

    Analysis Services (both OLAP and Data Mining)
    Integration Services (DTS successor)
    Notification Services
    Report Builder (although Reporting Services is included)
    SQL Agent (See Teratrax Job Scheduler)
    Database Tuning Advisor
    Full-text search
    Log shipping
    Enterprise availability limitations

    Unlike other editions of SQL Server 2005, the Express edition does not support Fail-over Clustering or Database Mirroring.

    Database Mirroring: Database Mirroring extends log shipping capabilities and enhances availability of SQL Server systems by providing automatic fail-over to a standby server.

    Fail-over Clustering: Fail-over clustering is the ultimate fail-over mechanism SQL Server can provide. A SQL Server node in a cluster of nodes sharing one disk array can fail-over to another node without affecting the availability of the server cluster. The disk array where databases reside is central to the SQL Server cluster.

    Networking support in SQL Server 2005 Express

    Only the shared memory on the local machine is accessible by default for SQL Server Express, although the user can explicitly turn on other supported protocols such as TCP/IP and Named Pipes. VIA and HTTP protocols are not supported in SQL Server Express. With only shared memory available by default, connections from a remote machine to SQL Server Express will fail unless the networking is turned on. To turn networking on, Use SQL Server Configuration Manager to enable relevant protocols and start SQL Browser.

    SQL Browser is a new service in SQL Server 2005 that is used to identify the ports that named instances listen on. Since shared memory does not use it, this service is turned off in SQL Server Express by default. This means that the user will have to start this service so that network access can work.

    Note One interesting fact is that SQL Browser listens on UDP port 1434. However, pre-SP3 versions of SQL Server 2000 holding port UDP 1434 may result in failure of SQL Browser name resolution, since they may refuse to give up the port. The workaround is to upgrade all SQL Server 2000/MSDE instances on the machine to SP3 or higher.

    SQL Server Express instances

    Multiple SQL Server 2005 Express installations can coexist on the same machine along with other installations of SQL Server 2000, SQL Server 2005, or Microsoft Desktop Engine (MSDE). In general, it is best that SQL Server 2000 instances be upgraded to SP3a or higher. The maximum limit to the number of SQL instances is 50 on the same machine. These instances must be uniquely named for the purpose of identifying them.

    SQL Server Express by default installs as a named instance called SQLEXPRESS. This particular instance is to be shared among multiple applications and application vendors. We recommend that you use this instance unless your application has special configuration needs. Some configuration needs, such as the requirement of the Secure Socket Layer (SSL) authentication, affect the installation as a whole and hence need a separate named instance. In all other cases, the shared instance should suffice. Another advantage of using the shared instance is that the application vendors need not worry about installing SQL Server Express along with the application, which simplifies application installation.

    Software requirements

    Microsoft Internet Explorer 6.0 SP1 or higher

    Microsoft .NET Framework 2.0

    Operating systems

    Microsoft Windows 2000 SP4 Professional

    Microsoft Windows 2000 SP4 Server

    Microsoft Windows 2000 SP4 Advanced

    Microsoft Windows 2000 SP4 Data Center

    Microsoft Windows XP SP1 Professional or higher

    Microsoft Windows 2003 Server or higher

    Microsoft Windows 2003 Enterprise or higher

    Microsoft Windows 2003 Data Center or higher

    Microsoft Windows Small Business Server 2003 Standard or higher

    Microsoft Windows Small Business Server 2003 Premium or higher

    Reset SA password (ms-sql)
    Feb 5th, 2010 by anand

    I recently forgot my SA password for my ms-sql database server. Since i have logged in after many days it was annoying for me to figure out the correct combination which i always use and do not share.

    Just a simple step given below solved my problem !

    USE [master]
    GO
    ALTER LOGIN [sa] WITH DEFAULT_DATABASE=[master],
    DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=ON, CHECK_POLICY=ON
    GO
    USE [master]
    GO
    ALTER LOGIN [sa] WITH PASSWORD=’password’ MUST_CHANGE
    GO

    Enjoy !!

    »  Substance: WordPress   »  Style: Ahren Ahimsa