import java.io.*;
import java.net.*;
import java.util.Date;
import java.util.regex.*;
public class wcs_benchmark {
static String hostname;
static int wcs_port = 5280;
static int users;
static int offset = 0;
static HttpURLConnection httpcon;
static String sids[]; // he we store the sids from logged in users
/* default values as they are used in jabber testsuite */
static String user_prefix = "test_";
static String pass = "password";
static int num_threads = 16;
static Thread threads[];
static String default_message = "HalloWelt";
public static void usage() {
System.out.println("java wcs_benchmark <host>:[port] <users> [offset]");
System.exit(0);
}
public static String getURL(String url) {
try {
httpcon = (HttpURLConnection)(new URL("http",hostname,wcs_port,url)).openConnection();
// System.out.println(httpcon.getResponseMessage());
BufferedReader br = new BufferedReader(new InputStreamReader(httpcon.getInputStream()));
String content;
String retval = "";
while ((content = br.readLine()) != null) { retval += content; }
br.close();
return retval;
} catch (IOException e) {
System.err.println(e.toString());
return null;
}
}
public static void main(String args[]) {
/* do some command line parsing */
if (args.length < 2 || args.length > 3)
usage();
if (args[0].indexOf(':') != -1) {
hostname = args[0].substring(0,args[0].indexOf(':'));
wcs_port = (new Integer(args[0].substring(args[0].indexOf(':')+1))).intValue();
} else
hostname = args[0];
users = (new Integer(args[1])).intValue();
sids = new String[users];
if (args.length == 3)
offset = new Integer(args[2]).intValue();
threads = new Thread[num_threads];
/*
* log in users
*/
System.out.print("Logging in "+ users+" users ");
Date starttime = new Date();
Pattern sid = Pattern.compile(".*jabber.sid='(.*)';.*");
for (int i=offset; i<users+offset; i++) {
String url = "/login-sid.js?jid="+user_prefix+i+"@"+hostname+"&pass="+pass;
Matcher m = sid.matcher(getURL(url));
if (m.matches())
sids[i-offset] = m.group(1);
else {
System.err.println("Couldn't get sid for user test_"+i);
System.exit(1);
}
/* send presence */
getURL("/presence.js?sid="+sids[i-offset]+"&status=available");
/* get roster */
getURL("/roster.js?sid="+sids[i-offset]);
System.out.print(".");
}
Date endtime = new Date();
System.out.println(" done (" + (endtime.getTime()-starttime.getTime())/1000.0 + "sec.)");
// for (int i=0;i<sids.length;i++)
// System.out.println(sids[i]);
/*
* created workers and let them work
*/
// for (int i=0; i<threads.length; i++)
// threads[i] = new Thread(new BenchmarkWorker(i));
// for (int i=0; i<threads.length; i++)
// threads[i].start();
// for (int i=0; i<threads.length; i++)
// threads[i].join();
int request_counter = 0;
java.util.Random rand = new java.util.Random();
starttime = new Date();
int num_requests = 10000;
while (request_counter++ < num_requests) {
String urls[];
if (request_counter%10==0) {
urls = new String[4];
urls[0] = "/logout-sid.js?sid=";
urls[1] = "/login-sid.js";
urls[2] = "/presence.js?sid=";
urls[3] = "/roster.js?sid=";
System.out.print(" L");
} else if (request_counter%3==0) {
urls = new String[1];
urls[0] = "/message.js?body="+default_message+"&sid=";
System.out.print(" M");
} else {
urls = new String[1];
urls[0] = "/cache.js?sid=";
}
// choose user
int user = rand.nextInt(users);
// System.out.print(" "+user);
for (int i=0; i<urls.length; i++) {
String url;
if (urls[i].indexOf("login-sid") != -1) {
url = urls[i] + "?jid="+user_prefix+user+"@"+hostname+"&pass="+pass;
Matcher m = sid.matcher(getURL(url));
if (m.matches())
sids[i] = m.group(1);
else {
System.err.println("Couldn't get sid for user test_"+i);
System.exit(1);
}
} else {
url = urls[i] + sids[user];
getURL(url);
}
}
}
endtime = new Date();
double duration = (endtime.getTime()-starttime.getTime())/1000.0;
System.out.println(" 1000 requests served in " + duration + "sec. ("+num_requests/duration+"/sec)");
/*
* log out users
*/
System.out.print("Logging out users ");
for (int i=0; i<users; i++) {
String url = "/logout-sid.js?sid="+sids[i];
getURL(url);
System.out.print('.');
}
System.out.println(" done.");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
WebIM研究整理
共274个文件
gif:135个
html:48个
po:13个
4星 · 超过85%的资源 需积分: 10 12 下载量 160 浏览量
2016-06-01
15:57:50
上传
评论 2
收藏 23.43MB ZIP 举报
温馨提示
WebIM研究集合帖,绝对有所值 1.WebIM目录对应http://blog.csdn.net/zwdsmileface/article/details/45111111和http://blog.csdn.net/ibm_hoojo/article/details/7850540 2个帖子集合可以,但是后一篇帖子的jsjac.js版本没找到,希望网友们提供 2.pingstream目录对应http://blog.csdn.net/xyy511/article/details/51517989 3.jwchat目录对应http://download.csdn.net/download/wll52/6033547 4.http://mineral.iteye.com/blog/448260
资源推荐
资源详情
资源评论
收起资源包目录
WebIM研究整理 (274个子文件)
AUTHORS 297B
ChangeLog 2KB
config 329B
COPYING 18KB
jwchat.css 3KB
README.CVS 1KB
description 73B
config.js.example 4KB
exclude 240B
jwchat-contextmenu.gif 22KB
jwchat.gif 17KB
water_molecule.gif 16KB
trinity_glowing.gif 8KB
context_menu.gif 7KB
jwc.gif 7KB
bg.gif 2KB
spin.gif 2KB
jumpto.gif 1KB
pref-button.gif 1KB
help.gif 1KB
preferences.gif 1KB
arrow_right_blinking.gif 928B
beer.gif 680B
penguin.gif 603B
coffee.gif 569B
heart.gif 560B
add-button.gif 399B
music.gif 371B
apple.gif 364B
globe.gif 358B
mushroom.gif 353B
add.gif 353B
camera.gif 339B
stalker.gif 337B
heart broken.gif 333B
tv.gif 333B
available.gif 331B
xa.gif 331B
invisible.gif 325B
chat.gif 256B
away.gif 256B
dnd.gif 256B
unavailable.gif 256B
error.gif 256B
gasmask.gif 249B
phone.gif 249B
lick.gif 246B
smoker.gif 245B
ninja.gif 243B
dinosaur.gif 243B
speaker.gif 242B
scared.gif 242B
old-man.gif 240B
cherry.gif 240B
cyclops.gif 240B
confused.gif 239B
evil.gif 238B
rambo.gif 238B
fish.gif 238B
angel.gif 237B
laugh.gif 237B
disappointed.gif 236B
cheeky.gif 236B
letter.gif 235B
bored.gif 235B
robot.gif 234B
grimreaper.gif 234B
dog.gif 234B
ogre.gif 234B
jaguar.gif 233B
chinese.gif 233B
mad.gif 233B
grin.gif 232B
cheerful.gif 232B
silly.gif 231B
pirate.gif 231B
devil.gif 230B
surprised.gif 228B
calm.gif 228B
alien.gif 227B
house.gif 225B
carrot.gif 223B
bandit.gif 223B
message.gif 222B
drink.gif 221B
bulb.gif 214B
helicopter.gif 213B
cocktail.gif 204B
thumbup.gif 203B
thumbdown.gif 200B
faceyukky.gif 191B
dead.gif 184B
paranoid.gif 180B
embarrassed.gif 180B
shocked.gif 179B
tired.gif 178B
ditsy.gif 178B
ponder.gif 177B
groupchat.gif 176B
cat.gif 176B
共 274 条
- 1
- 2
- 3
资源评论
- aaaaaa20072017-01-06谢谢分享~感谢
xcgh
- 粉丝: 98
- 资源: 144
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功