从mysql查询10条记录,通过网页显示该列表,测试程序使用组件anorm,play mvc.playframework 版本2.2.4.
数据库: mysql 5.6 .
操作系统:windows 2003 server
硬件服务器:amd 双核四线程
网页长度:3.3kB
测试客户端:jmeter
测试线程数:2000
测试结果:
样本数:232199
avg:237ms
中值:154ms
偏离:249
测试程序源码:
controller:
http://localhost:9000/salerlist
package controllers
import play.api._
import play.api.mvc._
import models._
/**
* Created by Administrator on 15-11-21.
*/
object Saleradmin extends Controller {
def listenable = Action{
val saler=Saler
val list= saler.findSalerListEnable()
Ok(views.html.salerlist.render("salerList",list))
}
}
models:
package models
import java.util.{Date}
import play.api.db._
import anorm._
import anorm.SqlParser._
import play.api.Play.current
import scala.language.postfixOps
case class Saler( userLocid : Pk[Long]= NotAssigned,userName : String , enable : Boolean, remoteUserId : Option[Long] ){
}
object Saler {
def findSalerListEnable():List[Saler]= {
var isenable: Boolean = true
DB.withConnection { implicit connection =>
val sql= SQL(
"""select * from saler where enable={enable}"""
).on("enable" -> isenable)
val list:List[Saler]= sql().map( row =>
Saler(row[Pk[Long]] ("userLocid"),row[String]("userName"),row[Boolean]("enable"),row[Option[Long] ]("remoteUserId"))
).toList
list
}
}
}
/*
object Saler {
val simple = {
get[Pk[Int] ]("saler.userLocid") ~
get[String]("saler.userName" )~
get[Boolean]("saler.enable") ~
get[Option[Int]]("saler.remoteUserId").map{
case userLocid~userName~enable~remoteUserId => Saler( userLocid , userName , enable ,remoteUserId )
}
}
def findSalerListEnable():Seq[Saler]= {
var isenable: Boolean = true
DB.withConnection { implicit connection =>
SQL(
"""select * from saler where enable={enable}"""
).on("enable" -> isenable)
.as(simple *)
}
}
*/
templete main:
@(title:String)(list:List[Saler])
@salerListTemplete("aabbcc"){
<h1>业务员列表</h1>
<ul>
@for(saler<-list){
<li>@saler.userName</li>
}
</ul>
}
templete:
@(title: String)(content: Html)
<!DOCTYPE html>
<html>
<head>
<title>@title</title>
<meta charset="UTF-8">
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
<script src="@routes.Assets.at("javascripts/jquery-1.9.0.min.js")" type="text/javascript"></script>
<style type="text/css">
</style>
</head>
<body>
<link rel="stylesheet" media="screen" href="/resources/style/main.css">
<section id="top">
<div class="wrapper">
<h1><a href="">广告采集系统</a></h1>
<nav>
<span class="versions">
<span>采集管理中心</span>
<select οnchange="document.location=this.value">
<option selected disabled>选择网站</option>
<option value="/adspider_admin_ali">采集</option>
<option value="/adspider_admin_hc">hc采集</option>
</select>
</span>
</nav>
</div>
</section>
<div id="news">
version: 1.0 time:2015
</div>
<div id="content" class="wrapper doc">
<article>
<p>
@content
</p>
</article>
<aside>
<h3>al广告采集</h3>
<ul>
<li><a href="">启动</a></li>
<li><a href="/api/scala/index.html">停止</a></li>
<li><a href="/api/scala/index.html">采集报告</a></li>
<li><a href="/api/scala/index.html">监听</a></li>
</ul>
<h3>hc广告采集</h3>
<ul>
<li><a href="">启动</a></li>
<li><a href="/api/scala/index.html">停止</a></li>
<li><a href="/api/scala/index.html">采集报告</a></li>
<li><a href="/api/scala/index.html">监听</a></li>
</ul>
<h3>浏览广告</h3>
<ul>
<li><a href="">广告列表(本地版)</a></li>
<li><a href="/api/scala/index.html">广告列表(业务员版)</a></li>
</ul>
<h3>项目测试</h3>
<ul>
<li><a href="/PlayConsole">数据库测试</a></li>
<li><a href="/PlayConsole">WEB文档下载测试</a></li>
<li><a href="/ScalaTodoList">HTML源码分析测试</a></li>
<li><a href="/ScalaTodoList">广告记录CURD测试</a></li>
</ul>
<h3>业务员管理</h3>
<ul>
<li><a href="/salerlist">业务员列表</a></li>
</ul>
</aside>
</div>
</body>
</html>
mysql sql ddl:
DROP TABLE IF EXISTS `alihc_ad_spider_db`.`saler`;
CREATE TABLE `alihc_ad_spider_db`.`saler` (
`userLocid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`userName` varchar(45) DEFAULT NULL,
`enable` tinyint(1) unsigned DEFAULT NULL,
`remoteUserId` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`userLocid`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;