发表于: 2016-12-21 09:21:30
5 2014
一.今天完成的事情
1.Nginx不错的博客:
1-1:http://www.360doc.com/content/14/1102/23/11962419_422047149.shtml
1-2:http://www.jb51.net/article/25643.htm
1-3:http://blog.csdn.net/lsfor365/article/details/19435147
1-4:Nginx Upstream的5种权重分配方式:http://www.jb51.net/article/31273.htm
1.轮询:每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。
2.weight:指定轮询的几率,weight和访问比率成正比,用于后端服务器性能不均的情况。
3.ip_hash:每个请求按访问的IP的hash结果分配,这样每个访客固定访问一个后端服务器,可解决Session的问题。
4.fair:按后端服务器响应时间来分配请求,响应时间短的优先分配。
5.url_hash:按访问url的hash结果分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存时比较有 效。
2.测试:在本地部署两台Web。一个为Tomcat端口是8082, 一个是Jetty端口为8085;
upstream cluster {
server localhost:8082 weight=3;
server localhost:8085 weight=5;
}
server {
listen 8080;
server_name localhost;
location / {
proxy_pass http://cluster;
}
录制好的线程组:
说明:localhost/task6/homePage 首页
localhost/task6/login 登录
localhost/task6/siginIn 登录成功跳转首页
localhost/task6/u/professionPage 职业页面
localhost/task6/clearSession 退出登录
开始测试:
1-1 关闭Memcache,线程数为30情况:(有错误啦。。。)
1-2 关闭Memcache,线程数为40情况:(有错误啦...)


1-3 打开Memcache,线程数为30情况:
1-4打开Memcache,线程数为40情况:
在本地部署一台Web,在远程部署一台WEB。本地为Tomcat端口是8082, 远程是Jetty端口为8085;
upstream cluster {
server localhost:8082 weight=3;
server 120.77.39.83:8085 weight=5;
}
server {
listen 8080;
server_name localhost;
location / {
proxy_pass http://cluster;
}
线程数为30情况:
报错:java.lang.IllegalStateException: Cannot create a session after the response has been committed
有时候在操作Session时,系统会抛出如下异常
java.lang.IllegalStateException: Cannot create a session after the response has been committed
之所以会出现此类问题是因为我们在Response输出响应后才创建Session的。
(因为那时候服务器已经将数据发送到客户端了,即:就无法发送Session ID 了)
解决办法:
你只需要在你的程序中将创建访问Session的语句【request.getSession()】提前至Response输出数据之前就好了。
二.明天的计划
1.在云服务器上搞Redis
三.遇到的问题
分析:部署一个Web没有报错;部署到两个Web竟然报错???虽然查到了大致的原因但我代码中没有创建Session啊??
@RequestMapping(value="/signIn",method=RequestMethod.POST)
public ModelAndView selectUserByPhone(HttpServletRequest request,HttpServletResponse response) throws Exception{
ModelAndView mav = new ModelAndView();
Long studentPhone = Long.valueOf(request.getParameter("studentPhone"));
String password = request.getParameter("password");
Student student = studentService.selectStudentByPhone(studentPhone);
if(student != null) {
if(MD5Util.verify(password, student.getStudentPassword())) {
mav.addObject("message", "登录成功...");
//cookie中的Token介绍
String encryptPassword = "wsx12345";
String DESAcount = DESUtil.encrypt(studentPhone+"", encryptPassword);
//1小时(3600秒)cookie存活期
Cookie accountCookie = new Cookie("userAcount", DESAcount);
response.addCookie(accountCookie);
response.sendRedirect(request.getContextPath()+"/homePage");
}else{
mav.addObject("message", "输入密码错误...");
mav.addObject("judge", "1");
}
}else{
mav.addObject("message", "输入手机号码错误...");
mav.addObject("judge", "1");
}
mav.setViewName("loginMessage");
return mav;
}
解决:此问题已解决,在controller中删除红色部分,转移到jsp中。
四.收获
评论