准备资源
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, 3364 buffers
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, 0 buffers
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();