Narya性能測試(一)

Narya是基於NIO的網遊服務器底層通訊引擎,並在其上做了對象的序列化,可以直接做方法的遠程調用。今天有時間測試了下其性能。

 

測試環境如下

 

服務器

CPU:Intel Xeon   X3220  2.40GHz 四核

內存:8G

操作系統:Red Hat Enterprise Linux Server release 5.4, 內核版本爲2.6.18-164.el5PAE

 

客戶機

CPU:Intel Xeon   E5410  2.33GHZ 八核

內存:4G

操作系統:WIndow Server 2008 R2 Enterprise

 

關鍵測試代碼

 

 

public class TestApp {
    public static void main (String[] args)
    {
    	for (int i = 0; i < 3000; i++) {
            TestClient tclient = new TestClient();
            UsernamePasswordCreds creds =
                new UsernamePasswordCreds(new Name("test" + i), "test");
            BasicRunQueue rqueue = new BasicRunQueue();
            Client client = new Client(creds, rqueue);
            tclient.setClient(client);
            client.addClientObserver(tclient);
            client.setServer("202.75.220.231", new int[]{45312});
            client.logon();
            // start up our event processing loop
            rqueue.start();
            try {
                Thread.sleep(RandomUtil.getInRange(0, 100));
            } catch (Exception e) {
            }
    	}

    }
}

 這裏一共開啓3000個線程,模擬3000用戶,每個線程之間間隔0~0.1秒

 

 

        for (int i = 0; i < 500; i++) {
            service.test(client, "one", 2, three, new TestService.TestFuncListener() {
                public void testSucceeded (String one, int two) {
                    //log.info("Got test response [one=" + one + ", two=" + two + "].");
                    jobCount++;
                    if (jobCount == 500) {
                    	client.logoff(false);
                    }
                }
                public void requestFailed (String reason) {
                    //log.info("Urk! Request failed [reason=" + reason + "].");
                }
            });
            try {
                Thread.sleep(RandomUtil.getInRange(50, 100));
            } catch (Exception e) {
            }
        }

 每個線程發送500次請求,每次請求間隔0.05 ~ 0.1秒,共3000x500 = 150萬次請求,外加3000次登錄與登出。

 

 

測試結果:

 

整個測試共持續了5分鐘左右,使用了linux的sar命令,以每5秒爲採樣頻率記錄了測試時的系統狀態

 

CPU消耗情況:

 

[root@localhost ~]# sar -u -f monitor

02:55:20 PM       CPU     %user     %nice   %system   %iowait    %steal     %idle

02:55:25 PM       all      0.00      0.00      0.05      0.00      0.00     99.95

02:56:33 PM       all      0.37      0.00      0.15      0.01      0.00     99.47

02:56:38 PM       all      3.75      0.00      0.40      0.00      0.00     95.85

02:56:43 PM       all     16.10      0.00      1.10      0.00      0.00     82.80

02:56:48 PM       all     15.21      0.00      1.90      0.00      0.00     82.89

02:56:53 PM       all     10.65      0.00      1.75      0.00      0.00     87.60

02:56:58 PM       all     16.30      0.00      3.95      0.00      0.00     79.75

02:57:03 PM       all     14.16      0.00      2.60      0.00      0.00     83.24

02:57:08 PM       all     19.46      0.00      4.25      0.00      0.00     76.29

02:57:13 PM       all     18.04      0.00      3.61      0.00      0.00     78.36

02:57:18 PM       all     19.26      0.00      3.66      0.00      0.00     77.08

02:57:23 PM       all     19.96      0.00      3.76      0.00      0.00     76.28

02:57:28 PM       all     24.23      0.00      4.37      0.00      0.00     71.40

02:57:33 PM       all     24.52      0.00      4.61      0.05      0.00     70.81

02:57:38 PM       all     25.57      0.00      4.42      0.00      0.00     70.02

02:57:43 PM       all     17.77      0.00      2.65      0.00      0.00     79.58

02:57:48 PM       all     19.90      0.00      3.06      0.00      0.00     77.04

02:57:53 PM       all     21.74      0.00      3.56      0.00      0.00     74.70

02:57:58 PM       all     22.72      0.00      3.86      0.00      0.00     73.42

02:58:03 PM       all     22.97      0.00      4.01      0.00      0.00     73.02


02:58:03 PM       CPU     %user     %nice   %system   %iowait    %steal     %idle

02:58:08 PM       all     23.18      0.00      3.86      0.00      0.00     72.96

02:58:13 PM       all     24.00      0.00      4.47      0.00      0.00     71.54

02:58:18 PM       all     24.62      0.00      4.47      0.00      0.00     70.90

02:58:23 PM       all     25.06      0.00      4.78      0.00      0.00     70.16

02:58:28 PM       all     24.37      0.00      4.28      0.00      0.00     71.35

02:58:33 PM       all     23.36      0.00      4.37      0.00      0.00     72.28

02:58:38 PM       all     15.98      0.00      2.66      0.00      0.00     81.36

02:58:43 PM       all     17.98      0.00      2.30      0.00      0.00     79.72

02:58:48 PM       all     19.12      0.00      2.95      0.00      0.00     77.93

02:58:53 PM       all     21.06      0.00      3.70      0.05      0.00     75.19

02:58:58 PM       all     21.70      0.00      3.71      0.00      0.00     74.59

02:59:03 PM       all     23.31      0.00      4.11      0.00      0.00     72.58

02:59:08 PM       all     23.23      0.00      4.06      0.00      0.00     72.70

02:59:13 PM       all     21.27      0.00      4.15      0.00      0.00     74.57

02:59:18 PM       all     24.01      0.00      4.32      0.00      0.00     71.67

02:59:23 PM       all     24.01      0.00      4.67      0.00      0.00     71.32

02:59:28 PM       all     23.37      0.00      4.52      0.00      0.00     72.11

02:59:33 PM       all     22.19      0.00      3.77      0.00      0.00     74.05

02:59:38 PM       all     18.35      0.00      3.41      0.00      0.00     78.25

02:59:43 PM       all     15.52      0.00      2.80      0.00      0.00     81.68


02:59:43 PM       CPU     %user     %nice   %system   %iowait    %steal     %idle

02:59:48 PM       all     12.96      0.00      2.25      0.00      0.00     84.78

02:59:53 PM       all     11.32      0.00      2.20      0.00      0.00     86.48

02:59:58 PM       all      8.54      0.00      1.30      0.05      0.00     90.11

03:00:03 PM       all      5.30      0.00      1.70      0.00      0.00     93.00

03:00:08 PM       all      3.65      0.00      0.70      0.00      0.00     95.65

03:00:13 PM       all      1.20      0.00      0.15      0.00      0.00     98.65

Average:          all     13.92      0.00      2.48      0.01      0.00     83.60

 

網絡流量情況:

 

[root@localhost ~]# sar -n DEV -f monitor |grep -v eth1 |grep -v lo |grep -v sit0

02:55:20 PM     IFACE   rxpck/s   txpck/s   rxbyt/s   txbyt/s   rxcmp/s   txcmp/s  rxmcst/s

02:55:25 PM      eth0      2.40      1.60    295.60    150.00      0.00      0.00      0.00

02:56:33 PM      eth0      3.85      2.11    373.97    279.43      0.00      0.00      0.00

02:56:38 PM      eth0    121.80    118.60  17383.00  15822.40      0.00      0.00      0.00

02:56:43 PM      eth0   1050.00    973.20 132690.40 104611.20      0.00      0.00      0.00

02:56:48 PM      eth0   2123.40   1948.40 258994.00 194737.80      0.00      0.00      0.00

02:56:53 PM      eth0   3107.80   2843.00 375485.80 278015.60      0.00      0.00      0.00

02:56:58 PM      eth0   4245.20   3889.40 513692.40 378331.20      0.00      0.00      0.00

02:57:03 PM      eth0   5214.80   4773.40 630628.80 461246.40      0.00      0.00      0.00

02:57:08 PM      eth0   6229.46   5695.59 760204.61 553530.26      0.00      0.00      0.00

02:57:13 PM      eth0   5909.02   5832.26 783886.97 582450.30      0.00      0.00      0.00

02:57:18 PM      eth0   6274.55   6763.33 855541.48 682523.05      0.00      0.00      0.00

02:57:23 PM      eth0   6515.03   7160.52 947785.77 744700.00      0.00      0.00      0.00

02:57:28 PM      eth0   7303.81   8091.98 1045808.82 827522.24      0.00      0.00      0.00

02:57:33 PM      eth0   7600.40   8350.20 1077683.40 849423.80      0.00      0.00      0.00

02:57:38 PM      eth0   7845.78   8383.53 1087125.90 842739.16      0.00      0.00      0.00

02:57:43 PM      eth0   5473.15   5686.97 937617.03 630977.15      0.00      0.00      0.00

02:57:48 PM      eth0   5408.00   5884.20 926051.80 699848.60      0.00      0.00      0.00

02:57:53 PM      eth0   5956.11   6419.04 954598.20 729923.25      0.00      0.00      0.00

02:57:58 PM      eth0   6383.60   6960.40 973623.80 758112.40      0.00      0.00      0.00

02:58:03 PM      eth0   6859.12   7529.46 1001398.20 786665.33      0.00      0.00      0.00

02:58:08 PM      eth0   7224.70   8093.37 1022953.82 827044.58      0.00      0.00      0.00

02:58:13 PM      eth0   7665.20   8624.40 1056824.60 863497.40      0.00      0.00      0.00

02:58:18 PM      eth0   8153.51   9156.11 1092524.05 898544.69      0.00      0.00      0.00

02:58:23 PM      eth0   8508.02   9275.55 1111162.73 899145.89      0.00      0.00      0.00

02:58:28 PM      eth0   8359.24   8661.04 1086370.88 841164.46      0.00      0.00      0.00

02:58:33 PM      eth0   8114.83   9234.47 1087768.74 884663.13      0.00      0.00      0.00

02:58:38 PM      eth0   5116.60   5312.20 863352.00 580472.60      0.00      0.00      0.00

02:58:43 PM      eth0   4352.20   4656.00 849515.20 613660.20      0.00      0.00      0.00

02:58:48 PM      eth0   4961.72   5358.32 888406.01 659205.61      0.00      0.00      0.00

02:58:53 PM      eth0   5585.00   6047.80 922080.80 697588.60      0.00      0.00      0.00

02:58:58 PM      eth0   6057.00   6620.60 946097.40 731614.60      0.00      0.00      0.00

02:59:03 PM      eth0   6797.39   7510.42 1001382.16 792359.52      0.00      0.00      0.00

02:59:08 PM      eth0   7287.00   7926.20 1024262.60 810788.20      0.00      0.00      0.00

02:59:13 PM      eth0   7582.16   8175.75 1038606.81 814097.60      0.00      0.00      0.00

02:59:18 PM      eth0   7967.54   8920.44 1061654.91 870389.78      0.00      0.00      0.00

02:59:23 PM      eth0   8311.04   8845.98 1074007.83 855888.15      0.00      0.00      0.00

02:59:28 PM      eth0   7916.03   7880.16 1001989.38 753715.83      0.00      0.00      0.00

02:59:33 PM      eth0   7151.20   7276.10 935381.33 702520.68      0.00      0.00      0.00

02:59:38 PM      eth0   6192.97   5885.54 816221.29 584488.55      0.00      0.00      0.00

02:59:43 PM      eth0   5380.52   5072.29 706938.76 503789.96      0.00      0.00      0.00

02:59:48 PM      eth0   4549.70   4234.87 593623.25 421019.44      0.00      0.00      0.00

02:59:53 PM      eth0   3716.60   3427.20 477704.20 338031.40      0.00      0.00      0.00

02:59:58 PM      eth0   2900.20   2648.80 364806.20 258180.20      0.00      0.00      0.00

03:00:03 PM      eth0   2112.02   1870.74 258350.90 180654.31      0.00      0.00      0.00

03:00:08 PM      eth0   1188.82   1029.94 142595.61  98956.29      0.00      0.00      0.00

03:00:13 PM      eth0    299.00    244.49  33657.52  22990.38      0.00      0.00      0.00

Average:         eth0   4217.52   4425.66 592974.45 454484.16      0.00      0.00      0.00

 

總結:

 

測試服務器進程CPU消耗平均爲14%,峯值在25%左右。

系統進程CPU消耗平均爲2.5%,峯值在5%左右。

 

網絡IO讀取平均爲592k/s,發送平均爲454k/s左右。

網絡IO讀取高峯在1.1m/s,發送高峯在900k/s左右。

 

使用top命令觀察內存(Resident Memory)消耗維持在110M~160M之間

 

5分鐘內接受請求在150萬次+,平均每秒爲5000+次。

 

在整個測試過程中沒有發現IO異常的情況,從測試結果來看,應該還沒有到極限,承載量還有繼續提升的空間。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章