Docker與JVM效能對比實驗設計
準備資源
1.安裝VMware的電腦
2.CentOS-7.0映象
3.Mongodb安裝包
4.Jdk安裝包
5.Tomcat安裝包
6.Supplierprofile 專案檔案實驗過程設計
分別對Docker和VM設計兩種場景,Docker與VM都設計為共2G的記憶體。 Docker場景,一臺2G記憶體虛擬機器安裝Docker,執行兩個CentOS映象服務。 VM場景,兩臺虛擬機器各執行一個服務。 兩種場景使用相同的資源,分別部署了兩個Supplierprofile服務。最後,測試兩個服務的寫入,讀取速度。測試報告
一臺Linux虛擬機器啟動兩個CentOS的Docker映象服務的資源使用情況
top - 15:37:48 up 1:20, 2 users, load average: 0.34, 0.12, 0.07
Tasks: 428 total, 4 running, 424 sleeping, 0 stopped, 0 zombie
%Cpu(s): 36.6 us, 4.1 sy, 0.0 ni, 59.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem: 1870764 total, 1025240 used, 845524 free,
KiB Swap: 2097148 total, 0 used, 2097148 free. 407896 cached Mem單臺VM上啟動一個服務的資源使用情況
top - 02:25:36 up 1:09, 4 users, load average: 0.57, 0.92, 0.50
Tasks: 418 total, 3 running, 415 sleeping, 0 stopped, 0 zombie
%Cpu(s): 13.6 us, 1.0 sy, 0.0 ni, 85.4 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem: 1003432 total, 940024 used, 63408 free,
KiB Swap: 2097148 total, 143780 used, 1953368 free. 102904 cached Mem服務寫入和讀取的速度對比
Docker 寫入一條資料平均使用 9326 毫秒, 讀取一條資料平均使用9326毫秒。
MV 寫入一條資料平均使用 9345毫秒, 讀取一條資料平均使用9330毫秒。
結論:Docker伺服器2G記憶體使用54.8%, VM伺服器2G記憶體使用93%, 同時Docker服務的訪問速度快於MV服務,因此使用Docker更加節省資源。
(注:centos關閉防火牆: systemctl stop firewalld.service。 最後附上,呼叫Supplierprofile的Groovy指令碼)
package docker;
import com.derby.nuke.common.module.groovy.GroovyLocalContext;
import com.derby.nuke.common.ws.client.JSONRPCClient;
import com.derby.nuke.common.ws.client.RetryExecutor;
def persisetnHotel(){
def hotel =[
hotelCode:"JP0097",
country:"JP"
];
def url = GroovyLocalContext.get().getInitProperties().get("profile.url");
JSONRPCClient client = new JSONRPCClient();
client.executor = new RetryExecutor(3, 1);
int total = 0;
int count =10;
for(int i=0;i<count;i++){
Date start = new Date();
client.service(url+"/management.ci", "put", "Hotel", hotel);
Date end = new Date();
total = total + (end.getTime()-start.getTime())
}
println total;
println total/count;
}
GroovyLocalContext.test([
// "profile.url": "http://169.168.137.128:84/supplierprofile",
"profile.url": "http://169.168.137.130:8080/supplierprofile",
]);
persisetnHotel();
package docker;
import com.derby.nuke.common.module.groovy.GroovyLocalContext;
import com.derby.nuke.common.ws.client.JSONRPCClient;
import com.derby.nuke.common.ws.client.RetryExecutor;
def persisetnHotel(){
def url = GroovyLocalContext.get().getInitProperties().get("profile.url");
JSONRPCClient client = new JSONRPCClient();
client.executor = new RetryExecutor(3, 1);
int total = 0;
int count =10;
for(int i=0;i<count;i++){
Date start = new Date();
client.service(url+"/profile.rpc", "getHotel", "JP0097");
Date end = new Date();
total = total + (end.getTime()-start.getTime())
}
println total;
println total/count;
}
GroovyLocalContext.test([
// "profile.url": "http://169.168.137.128:84/supplierprofile",
"profile.url": "http://169.168.137.130:8080/supplierprofile",
]);
persisetnHotel();