首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

对java测试web服务器程序最大连接

2012-12-14 
求一个对java测试web服务器程序最大连接接到boss要求写一个模拟测试web服务器访问,当最大连接数的多少,这

求一个对java测试web服务器程序最大连接
接到boss要求写一个模拟测试web服务器访问,当最大连接数的多少,这台服务器不可访问。
程序不用很复杂,只要能在web服务器上运行,而且能记录模拟接连接的峰值与时间,到达多少是不能访问。

就是不知怎么同一时间发起这种大量模拟连接,哪位有程序代码能提供一份吗,谢谢。
还有种访问模拟客户端最好是用web程序网页的,另不要给我推荐一些工具测试之类的。
[最优解释]
可以找个开源项目现在很多
[其他解释]
1,你机器可以开这个多访问线程吗?
2,如果连上就关闭,这样的话很不准确的哦
[其他解释]
这个不要写程序啊,现成的压力软件就可以满足他的要求啊,而且比他的还要详细,还可以输出压力检测图来的。




[其他解释]
WAS(Web Application Stress) 和 LoadRunner 都可以满足,而且是专业的测试工具。

上手也不难,网上资料也很多。


[其他解释]
linux下的 jmeter + probe
[其他解释]
那你不要關閉連接 無限讀數據庫 然後輸出數值
[其他解释]
jmeter吧
[其他解释]
WAS+LOADRUNNER
[其他解释]
 jmeter貌似也可以让web程序集成到系统中吧..  lz实在不行就用corba接口
[其他解释]
关注中。。。
[其他解释]
学习啦
[其他解释]

引用:
这个不要写程序啊,现成的压力软件就可以满足他的要求啊,而且比他的还要详细,还可以输出压力检测图来的。


up...
[其他解释]
引用:
这个不要写程序啊,现成的压力软件就可以满足他的要求啊,而且比他的还要详细,还可以输出压力检测图来的。

我说了,不用工具工具我能找到。
[其他解释]
引用:
那你不要關閉連接 無限讀數據庫 然後輸出數值

这是关于线程上的问题,不是输出值就能解决的,网上倒时找了一个文章就是并发用户,但问题就是不知怎么才能知道,多少用户时服务器当了测试服务端代码怎么判断。

import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.net.HttpURLConnection;
  import java.net.URL;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.concurrent.ExecutorService;
  import java.util.concurrent.Executors;
  import java.util.concurrent.Semaphore;
  public class ConcurrentTest {
  private static int thread_num = 200;
  private static int client_num = 460;
  private static Map keywordMap = new HashMap();
  static {
  try {
  InputStreamReader isr = new InputStreamReader(new FileInputStream(
  new File("clicks.txt")), "GBK");
  BufferedReader buffer = new BufferedReader(isr);
  String line = "";
  while ((line = buffer.readLine()) != null) {
  keywordMap.put(line.substring(0, line.lastIndexOf(":")), "");
  }
  } catch (Exception e) {
  e.printStackTrace();
  }
  }
  public static void main(String[] args) {


  int size = keywordMap.size();
  // TODO Auto-generated method stub
  ExecutorService exec = Executors.newCachedThreadPool();
  // 50个线程可以同时访问
  final Semaphore semp = new Semaphore(thread_num);
  // 模拟2000个客户端访问
  for (int index = 0; index < client_num; index++) {
  final int NO = index;
  Runnable run = new Runnable() {
  public void run() {
  try {
  // 获取许可
  semp.acquire();
  System.out.println("Thread:" + NO);
  String host = "http://10.99.23.42:7001/KMQueryCenter/query.do?";
  String para = "method=getQueryResult&pageNum=1&pageSize=5&"
  + "queryKeyWord="
  + getRandomSearchKey(NO)
  + "&questionID=-1&questionIdPath=-1&searchType=1"
  + "&proLine=&proSeries=&proType=" + NO;
  System.out.println(host + para);
URL url = new URL(host);// 此处填写供测试的url
  HttpURLConnection connection = (HttpURLConnection) url
  .openConnection();
  // connection.setRequestMethod("POST");
  // connection.setRequestProperty("Proxy-Connection",
  // "Keep-Alive");
  connection.setDoOutput(true);
  connection.setDoInput(true);
  PrintWriter out = new PrintWriter(connection
  .getOutputStream());
  out.print(para);
  out.flush();
  out.close();
  BufferedReader in = new BufferedReader(
  new InputStreamReader(connection
  .getInputStream()));
  String line = "";
  String result = "";
  while ((line = in.readLine()) != null) {
  result += line;
  }
  // System.out.println(result);
  // Thread.sleep((long) (Math.random()) * 1000);
  // 释放
  System.out.println("第:" + NO + " 个");
  semp.release();
  } catch (Exception e) {
  e.printStackTrace();
  }
  }
  };
  exec.execute(run);
  }
  // 退出线程池
  exec.shutdown();
  }
  private static String getRandomSearchKey(final int no) {
  String ret = "";
  int size = keywordMap.size();
  // int wanna = (int) (Math.random()) * (size - 1);
  ret = (keywordMap.entrySet().toArray())[no].toString();
  ret = ret.substring(0, ret.lastIndexOf("="));
  System.out.println("\t" + ret);
  return ret;
  }
  }


[其他解释]
引用:
jmeter吧

看起来不错,但主要是我要web程序还要集成到系统中网页调用。
[其他解释]
引用:
 jmeter貌似也可以让web程序集成到系统中吧..  lz实在不行就用corba接口

我要的东西就是功能简单目标明确,开源项目太大了,看明白任务早过期了。
[其他解释]
............
[其他解释]
实现2个功能
1,不断的开新的线程去访问web页面,每开1个计数器加1。
2,一个线程重复访问web,在服务器当掉的时候输出计数器的值。(判断条件我不能完全确定,就不说了)

这个么做结果肯定是不精确的,但是误差应该不大。

热点排行