linux下性能测试

1.硬盘IO读写速度

dd if=/dev/zero of=test bs=64k count=4k oflag=dsync
dd if=/dev/zero of=test bs=8k count=256k conv=fdatasync
#conv=fdatasync与oflag=dsync的区别在于:sync函数只是将所有修改过的块缓冲区排入写队列,然后就返回,它并不等待实际写磁盘操作结束。
#而fsync函数只对由文件描述符filedes指定的单一文件起作用,并且等待写磁盘操作结束,然后返回。这是我电脑的硬盘IO测试结果。

2.网络吞吐

wget https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
python speedtest.py --share #自动找到最近的节点,测试网速,并共享

如果需要测试其他地方的网速,可以列出可用节点,再测试
python speedtest.py –list |grep China
python speedtest.py –server 5017 #服务器节点编号


http://blog.csdn.net/panjican/article/details/51189587

centos查看系统信息(linux)

1.cpu核http://blog.csdn.net/sycflash/article/details/6643492

grep "model name" /proc/cpuinfo

2.内存http://blog.csdn.net/sycflash/article/details/6643492

grep "MemTotal" /proc/meminfo

3.系统内核及位数

cat /proc/version

4.磁盘信息

df   #默认按kb
fdisl -l

5.系统版本

cat /etc/centos-release

6.查看IP地址

ifconfig #或者ip addr
cat /etc/sysconfig/network-scripts/ifcfg-eth0  #查看网卡设置的详细信息,也可以设置网关,DNS信息

7.查看网关

cat /etc/sysconfig/network\

8.查看DNS

cat /etc/resolv.cof

硬件及系统核心的数据,一般在/proc目录下能找到
配置信息一般在/etc目录下

循环测试ping延迟

1.sh脚本

#!/bin/bash
#需求是PING一个地址,延迟高于100ms就发送个邮件, 然后正常后在发个邮件通知 之后正常不发。
Timeout_limit=100;
IP="104.224.138.22"
n=0

if ping -c 3 $IP |awk -F/ 'END{if($5>100)print "errer"}' |grep -q "errer" ;then
        echo "IP地址:$IP异常,延迟大于100ms" |mail -s "Ping Delay,IP:$IP"  ntp_monitor@163.com
        n=1
elif [ "$n" -eq 1 ];then
        echo "IP地址:$IP恢复" |mail -s "Ping recovery"  ntp_monitor@163.com
        n=0
fi

2.添加自动任务

*/1 * * * *  sh /root/tangzhq/chk_ping_time.sh & #一分钟

循环ping测试服务器

1.sh代码

#!/bin/bash
COUNT=100 #每台服务器测试ping的次数
MAX=10 #其中最多无法ping通的次数
HOST=(#服务器列表,IP地址或者域名
115.28.155.12
119.42.149.89
)
#循环检测
for ipadd in "${HOST[@]}"
do
  timing=`date +%Y/%m/%d/%H:%M:%S`
  ping $ipadd -c $COUNT > 1ping.log
  losspag=`grep "packet loss" 1ping.log |awk '{print $6}' |sed 's/%//g'`
  if [ $losspag -ge $MAX ] ;
  then
    echo  $timing > tmp.log
    echo -n $ipadd >> tmp.log
    echo -n "packet loss is more than $MAX of $COUNT">> tmp.log
    cat /root/tmp.log | mail -s "$ipadd ping packet loss is more then $MAX of $COUNT" monitor@163.com
  else
    rm -f tmp.log
  fi
done

2.cron设置
*/6 * * * * root sh /root/checkping.sh &

使用Redis队列+hp-socket

 private void buttonStart_Click(object sender, EventArgs e)
        {
            try
            {
                string ip = textBoxIPAdress.Text.Trim();
                ushort port = ushort.Parse(textBoxPort.Text.Trim());

                appState = AppState.Starting;

                server.IpAddress = ip;
                server.Port = port;

                if (server.Start())
                {
                    appState = AppState.Started;
                    SetControlState();

                    thread = new Thread(new ThreadStart(this.Subscribe));
                    thread.Start();
                }
                else
                {
                    appState = AppState.Stoped;
                    SetControlState();
                    throw new Exception(string.Format("服务端启动失败:{0},{1}", server.ErrorMessage, server.ErrorCode));
                }
            }
            catch (Exception exc)
            {
                ShowMSG(exc.Message);
            }
        }

 private void Subscribe()
        {
            string channel = "messages";
            var sub = RedisHelper.GetSub(channel);

            sub.Subscribe(channel, (chan, message) =>  //订阅后,只有有队列信息进来,就会执行下面的代码
            {
                string msg = (string)message;
                byte[] sendBytes = Encoding.Default.GetBytes(msg);

                for (int i = 0; i < checkedListBoxClientList.Items.Count; i++)
                {
                    IntPtr connId = (IntPtr)Convert.ToInt32(checkedListBoxClientList.Items[i]);
                    if (checkedListBoxClientList.GetItemChecked(i))
                    {
                        server.Send(connId, sendBytes, sendBytes.Length);
                    }
                }
            });
        }

2.服务端接收到消息时,发布消息到相关的redis队列中

  HandleResult server_OnReceive(IntPtr connId, byte[] bytes)
        {
            string recievedStr = Encoding.Default.GetString(bytes);

            ShowMSG(string.Format("收到连接ID:{0} 的信息,内容:{1},长度:{2}", connId, recievedStr, bytes.Length));

            //加入消息队列
            long tt = RedisHelper.Publish("messages", recievedStr);

            return HandleResult.Ok;
        }


3.另一个小例子的代码下载:RedisTest
4.redis订阅测试:
一个客户端:

redis-cli
publish msg1 “1111”

另一个客户端:

redis-cli
subscribe msg1
….实时显示结果

复制虚拟机,网卡不能用

因为复制后,网卡mac地址冲突导致
一般错误是:

service network restart
Shutting down loopback insterface:                                                       [   OK  ]
Bringing up loopback insterface:                                                            [   OK  ]
Bringing up interface eth0:  Device eth0 does not seem to be present,delaying initialization.                    [FAILED]

解决办法:
1.直接删除“`shell
rm -rf /etc/udev/rules.d/70-persistent-net.rules

reboot
“`

2.调换eth0与eth1的信息

总结
只要保证/etc/sysconfig/network-scripts/ifcfg-eth0 与/etc/udev/rules.d/70-persistent-net.rules的信息一致即可