微型玩具长连接简单测试工具
2010-02-25 22:08
344 查看
本文章为本人个人博客相应文章的镜像:
原文地址: http://www.greatony.com/index.php/2010/02/25/mini-toy-long-connection-tester/
好吧,我承认我起了个很罗嗦的名字。
事实是这样的,今天研究mochiweb,然后利用mochiweb写了一个长连接web服务器用以实现游戏中的聊天功能。
写到一半的时候,当然要弄个小测试自high一下啦,于是就有了这个“微型玩具长连接简单测试工具”,写的非常简单粗暴,大家就当玩笑看看吧:
1 using System;
2 using System.Net;
3 using System.Threading;
4
5 namespace AutoLongConnectionTester
6 {
7 class Program
8 {
9 // The service url
private const string ServiceUrl = "http://192.168.0.104:8000/msg/get";
// The supposed response
private const string SupposedResponse = "Hello, world";
// Concurrent connection count
private const int RequestCount = 10000;
// Global lock
private static readonly object Lock = new object();
// The number of requests in progress
private static int _requesting = 0;
// The number of successful requests
private static int _succeed = 0;
// The number of failed requests
private static int _failed = 0;
static void Main(string[] args)
{
// prelimit the number of connections per domain limitation (the original value is 2,
// which specified in the HTTP 1.1 specification)
ServicePointManager.DefaultConnectionLimit = 30000;
// create request with asynchronize network io api
for(var i = 0; i < RequestCount; i++)
{
var webClient = new WebClient();
webClient.DownloadStringCompleted += WebClientDownloadStringCompleted;
webClient.DownloadStringAsync(new Uri(ServiceUrl));
lock(Lock)
{
_requesting++;
}
}
Action writeStatus = () => Console.Write("\rRequesting: {0,8}, Succeed: {1,8}, Failed: {2,8}", _requesting, _succeed, _failed);
// loop while some of the requests are still in progress
while(_requesting > 0)
{
writeStatus();
Thread.Sleep(100);
}
// finished write the final result
writeStatus();
}
static void WebClientDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
lock (Lock)
{
_requesting--;
if (e.Error != null || e.Result != SupposedResponse)
_failed++;
else
_succeed++;
}
}
}
}
原文地址: http://www.greatony.com/index.php/2010/02/25/mini-toy-long-connection-tester/
好吧,我承认我起了个很罗嗦的名字。
事实是这样的,今天研究mochiweb,然后利用mochiweb写了一个长连接web服务器用以实现游戏中的聊天功能。
写到一半的时候,当然要弄个小测试自high一下啦,于是就有了这个“微型玩具长连接简单测试工具”,写的非常简单粗暴,大家就当玩笑看看吧:
1 using System;
2 using System.Net;
3 using System.Threading;
4
5 namespace AutoLongConnectionTester
6 {
7 class Program
8 {
9 // The service url
private const string ServiceUrl = "http://192.168.0.104:8000/msg/get";
// The supposed response
private const string SupposedResponse = "Hello, world";
// Concurrent connection count
private const int RequestCount = 10000;
// Global lock
private static readonly object Lock = new object();
// The number of requests in progress
private static int _requesting = 0;
// The number of successful requests
private static int _succeed = 0;
// The number of failed requests
private static int _failed = 0;
static void Main(string[] args)
{
// prelimit the number of connections per domain limitation (the original value is 2,
// which specified in the HTTP 1.1 specification)
ServicePointManager.DefaultConnectionLimit = 30000;
// create request with asynchronize network io api
for(var i = 0; i < RequestCount; i++)
{
var webClient = new WebClient();
webClient.DownloadStringCompleted += WebClientDownloadStringCompleted;
webClient.DownloadStringAsync(new Uri(ServiceUrl));
lock(Lock)
{
_requesting++;
}
}
Action writeStatus = () => Console.Write("\rRequesting: {0,8}, Succeed: {1,8}, Failed: {2,8}", _requesting, _succeed, _failed);
// loop while some of the requests are still in progress
while(_requesting > 0)
{
writeStatus();
Thread.Sleep(100);
}
// finished write the final result
writeStatus();
}
static void WebClientDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
lock (Lock)
{
_requesting--;
if (e.Error != null || e.Result != SupposedResponse)
_failed++;
else
_succeed++;
}
}
}
}
相关文章推荐
- 简单测试数据库连接
- 分享一个.NET实现的简单高效WEB压力测试工具
- 网络诊断工具之—IP连接测试ping命令 推荐
- php一个简单的测试工具simpletest
- 简单了解snapdragon的分析测试工具
- 一个简单的猴子测试小工具
- 简单Dream-ORACLE_RAC故障透明切换测试,已连接的应用不会自动切换到第二个节点上
- [AD]使用NetDiag工具测试工作站和服务器的网络连接和DNS解析
- Linux串口测试工具简单程序展示
- dbcp连接数据库简单测试
- 简单的并发测试工具 ab.exe ab.zip可下载 -摘自网络
- 简单介绍嵌入式软件测试工具及测试内容
- 连接管理工具httpclient的简单使用
- 简单的JAVA TCP/IP连接测试
- Mysql远程测试连接工具
- Java实现简单的截图工具(未测试)
- 利用ping/ipconfig/nslookup/dig/whois简单工具测试DNS
- 第一次编写简单的中间件测试工具(2) - 读代码的方法
- C#与数据库连接简单测试