发表于: 2020-07-01 21:30:21
1 1686
今天完成的事情:实现了任务五的功能
一、http://119.45.117.56:8080/task5/
二、任务六的Jmeter测试
200.0.1 200线程 1次循环
200.0.10 在最后的50个时不动了,后来多测了几组数据,都是在样本数达到1600后就不动了
感觉线程数越多对性能要求越高
三、 Spring整合Memcached
1、pom
<!--memcached-->
<dependency>
<groupId>com.googlecode.xmemcached</groupId>
<artifactId>xmemcached</artifactId>
<version>2.0.0</version>
</dependency>
2、memcached.properties
#连接池大小即客户端个数
memcached.connectionPoolSize=1
memcached.failureMode=true
#server1
memcached.server1.host=127.0.0.1
memcached.server1.port=11211
memcached.server1.weight=1
3、memcached.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">
<!-- properties config -->
<!--加载配置文件-->
<context:property-placeholder location="classpath:properties/memcached.properties"/>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="order" value="1"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:properties/memcached.properties</value>
</list>
</property>
</bean>
<!-- Memcached配置 -->
<!-- p:connectionPoolSize="${memcached.connectionPoolSize}" p:failureMode="${memcached.failureMode}" -->
<bean id="memcachedClientBuilder" class="net.rubyeye.xmemcached.XMemcachedClientBuilder">
<constructor-arg>
<list>
<bean class="java.net.InetSocketAddress">
<constructor-arg>
<value>${memcached.server1.host}</value>
</constructor-arg>
<constructor-arg>
<value>${memcached.server1.port}</value>
</constructor-arg>
</bean>
</list>
</constructor-arg>
<constructor-arg>
<list>
<value>${memcached.server1.weight}</value>
</list>
</constructor-arg>
<property name="commandFactory" >
<bean class="net.rubyeye.xmemcached.command.TextCommandFactory" />
</property>
<property name="sessionLocator" >
<bean class="net.rubyeye.xmemcached.impl.KetamaMemcachedSessionLocator" />
</property>
<property name="transcoder" >
<bean class="net.rubyeye.xmemcached.transcoders.SerializingTranscoder" />
</property>
<property name="connectionPoolSize" value="${memcached.connectionPoolSize}" />
<property name="failureMode" value="${memcached.failureMode}" />
</bean>
<!-- Use factory bean to build memcached client -->
<bean id="memcachedClient" factory-bean="memcachedClientBuilder" factory-method="build" destroy-method="shutdown" />
</beans>
测试类
BaseTest类
import java.io.FileNotFoundException;
import org.apache.log4j.Logger;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.Log4jConfigurer;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:memcached.xml")
public class BaseTest {
/**
* 添加字段注释.
*/
protected Logger logger = Logger.getLogger(BaseTest.class);
static {
try {
Log4jConfigurer.initLogging("classpath:log4j.properties");
} catch (FileNotFoundException ex) {
System.err.println("Cannot Initialize log4j");
}
}
}
MemcacheSpring类
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import net.rubyeye.xmemcached.MemcachedClient;
public class MemcachedSpring extends BaseTest{
private ApplicationContext app;
private MemcachedClient memcachedClient;
@Before
public void init() {
app = new ClassPathXmlApplicationContext("classpath:memcached.xml");
memcachedClient = (MemcachedClient) app.getBean("memcachedClient");
}
@Test
public void test() {
try {
// 设置/获取
memcachedClient.set("zlex", 36000, "set/get");
System.out.println(memcachedClient.get("zlex"));
// 替换
memcachedClient.replace("zlex", 36000, "replace");
System.out.println(memcachedClient.get("zlex"));
// 移除
memcachedClient.delete("zlex");
System.out.println(memcachedClient.get("zlex"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
测试结果报错了
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
net.rubyeye.xmemcached.exception.MemcachedException: Session(127.0.0.1:11211) has been closed
SLF4J解决方案
pom加上依赖
<!--sl4j-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.2</version>
</dependency>
Session has been clossed
我找了好久,然后终于发现是因为安装好的memcached没有运行。。。。淦
运行结果
明天计划的事情:推进任务
日报bug了,日报顶端有问题
评论