测试性能才265.47 pps,严重怀疑自己测试有问题,先记录下来
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <event2/event.h>
#include <event2/buffer.h>
#include <event2/http.h>
#include <event2/http_struct.h>
#include <event2/keyvalq_struct.h>
#include <event2/listener.h>
#include <event2/util.h>
#include <event2/bufferevent.h>
static char *post_data = "{\n"
" \"dawn_ts0\": 1483468791574000,\n"
" \"guid\": \"31\",\n"
" \"device_id\": \"79bf7e53-d92f-5cdd-a7c3-3e9e97685c2c\",\n"
" \"probe\": {\n"
" \"name\": \"cloudsensor\"\n"
" },\n"
" \"appname\": \"cloudsensor\",\n"
" \"type\": \"tcp\",\n"
" \"kafka\": {\n"
" \"topic\": \"cloudsensor\"\n"
" },\n"
" \"aggregate_count\": 1,\n"
" \"tcp\": {\n"
" \"src_isp\": 0,\n"
" \"l4_proto\": 6,\n"
" \"out_bytes\": 0,\n"
" \"dst_port\": 3306,\n"
" \"retransmitted_out_fin_pkts\": 0,\n"
" \"client_latency_sec\": 0,\n"
" \"window_zero_size\": 0,\n"
" \"src_ipv4\": 178257969,\n"
" \"topic\": \"tcp\",\n"
" \"in_pkts\": 0,\n"
" \"src_region\": 0,\n"
" \"retransmitted_out_payload_pkts\": 0,\n"
" \"dst_ipv4\": 178808905,\n"
" \"ts\": 1483468791,\n"
" \"final_status\": 3,\n"
" \"retransmitted_in_syn_pkts\": 0,\n"
" \"src_ip\": 178257969,\n"
" \"server_latency_sec\": 0,\n"
" \"l4_protocol\": 6,\n"
" \"bytes_in\": 0,\n"
" \"src_port\": 57366,\n"
" \"retransmitted_out_syn_pkts\": 0,\n"
" \"retransmitted_in_ack_pkts\": 0,\n"
" \"out_pkts\": 0,\n"
" \"device_id\": \"79bf7e53-d92f-5cdd-a7c3-3e9e97685c2c\",\n"
" \"guid\": \"31\",\n"
" \"bytes_out\": 0,\n"
" \"retransmitted_in_payload_pkts\": 0,\n"
" \"dst_ip\": 178808905,\n"
" \"in_bytes\": 0,\n"
" \"retransmitted_out_ack_pkts\": 0,\n"
" \"server_latency_usec\": 3314,\n"
" \"client_latency_usec\": 3740006,\n"
" \"retransmitted_in_fin_pkts\": 0\n"
" },\n"
" \"probe_ts\": 1483468791,\n"
" \"dawn_ts1\": 1483468791574000,\n"
" \"topic\": \"cloudsensor\"\n"
"}";
void http_request_done(struct evhttp_request *req, void *arg){
char buf[1024];
int s = evbuffer_remove(req->input_buffer, &buf, sizeof(buf) - 1);
buf[s] = '\0';
// printf("%s\n", buf);
// terminate event_base_dispatch()
event_base_loopbreak((struct event_base *)arg);
}
int main(int argc, char **argv)
{
struct event_base *base;
struct evhttp_connection *conn;
struct evhttp_request *req;
base = event_base_new();
conn = evhttp_connection_base_new(base, NULL, "192.168.10.212", 9200);
evhttp_connection_set_timeout(conn, 600);
evhttp_connection_set_retries(conn, -1);
int i = 0;
struct timeval start, end;
gettimeofday(&start, NULL);
for (i = 0; i < 10000; i++) {
req = evhttp_request_new(http_request_done, base);
evhttp_add_header(req->output_headers, "Host", "192.168.10.212");
evbuffer_add(req->output_buffer, post_data, strlen(post_data));
evhttp_make_request(conn, req, EVHTTP_REQ_POST, "/cc-2017.01.17/test");
event_base_dispatch(base);
}
gettimeofday(&end, NULL);
long time_cost = ((end.tv_sec - start.tv_sec) * 1000000 + \
end.tv_usec - start.tv_usec);
printf("cost time: %ld us, %.2f pps\n", time_cost, 10000 / (time_cost * 1.0) * 1000000);
return 0;
}