服务器压力测试

简单动手,写一个windows平台的服务器承压测试软件. 类似于apache的ab.

 

#include<iostream>
#include<atomic>
#include<thread>
#include<condition_variable>
#include<mutex>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<regex>
#include<ws2tcpip.h>

#include<vector>

#include<windows.h>
#pragma comment(lib,"Ws2_32.lib")
#include <winsock2.h>


#define BUF_SIZE 65535
#define _WINSOCK_DEPRECATED_NO_WARNINGS




bool Start = false;
std::mutex mut;
std::condition_variable cv;

std::atomic<int> Count = 0; //for Count working Thread.
std::atomic<int> N_request = 1000;
std::atomic<int> N_data = 0;
std::atomic<int> N_Fished = 0;

const char* request = "GET /gdl/poems/ HTTP/1.1\r\n\r\n";

const int len_r = strlen(request);

const std::regex r("\\r\\nContent-Length:[ ]*([0-9]+)");


DWORD T0;

class RAII
{

public:
	~RAII() {
		std::lock_guard<std::mutex> lock(mut);
		std::cout << "threadId: " << std::this_thread::get_id() << " end working. " << " sum threads: " << --Count << std::endl;
	}
};

bool flag = true;

void
do_work(SOCKET sock) {

	RAII ra;
	char *buf = new 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值