Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ademco_hb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
ademco_hb
Commits
8eec0067
Commit
8eec0067
authored
Sep 17, 2020
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bench client now only works in load test mode
parent
a49fafdf
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
628 additions
and
38 deletions
+628
-38
bench_client.cpp
examples/bench_client/bench_client.cpp
+14
-38
bench_client_ex.cpp
examples/bench_client_ex/bench_client_ex.cpp
+422
-0
bench_client_ex.vcxproj
examples/bench_client_ex/bench_client_ex.vcxproj
+150
-0
bench_client_ex.vcxproj.filters
examples/bench_client_ex/bench_client_ex.vcxproj.filters
+22
-0
bench_client_ex.vcxproj.user
examples/bench_client_ex/bench_client_ex.vcxproj.user
+4
-0
examples.sln
examples/examples.sln
+16
-0
No files found.
examples/bench_client/bench_client.cpp
View file @
8eec0067
...
@@ -52,7 +52,6 @@ uint64_t gettid() {
...
@@ -52,7 +52,6 @@ uint64_t gettid() {
int
thread_count
=
0
;
int
thread_count
=
0
;
int
session_count
=
0
;
int
session_count
=
0
;
int
session_connected
=
0
;
int
session_connected
=
0
;
int
load_test
=
0
;
int
timeout
=
0
;
int
timeout
=
0
;
int
print_data
=
0
;
int
print_data
=
0
;
...
@@ -68,7 +67,7 @@ struct Session {
...
@@ -68,7 +67,7 @@ struct Session {
int
fd
=
0
;
int
fd
=
0
;
int
thread_id
=
0
;
int
thread_id
=
0
;
bufferevent
*
bev
=
nullptr
;
bufferevent
*
bev
=
nullptr
;
event
*
timer
=
nullptr
;
// life
or heartbeat
timer
event
*
timer
=
nullptr
;
// life timer
int
id
=
0
;
int
id
=
0
;
std
::
string
acct
=
{};
std
::
string
acct
=
{};
AdemcoId
ademco_id
=
0
;
AdemcoId
ademco_id
=
0
;
...
@@ -110,7 +109,7 @@ void handle_ademco_msg(Session* session, bufferevent* bev)
...
@@ -110,7 +109,7 @@ void handle_ademco_msg(Session* session, bufferevent* bev)
auto
output
=
bufferevent_get_output
(
bev
);
auto
output
=
bufferevent_get_output
(
bev
);
switch
(
session
->
packet
.
id_
.
eid_
)
{
switch
(
session
->
packet
.
id_
.
eid_
)
{
case
AdemcoMsgId
:
:
id_ack
:
case
AdemcoMsgId
:
:
id_ack
:
if
(
load_test
)
{
{
auto
now
=
std
::
chrono
::
steady_clock
::
now
();
auto
now
=
std
::
chrono
::
steady_clock
::
now
();
char
buf
[
1024
];
char
buf
[
1024
];
session
->
lastTimePacketSize
=
session
->
packet
.
make_null
(
buf
,
sizeof
(
buf
),
session
->
nextSeq
(),
session
->
acct
,
session
->
ademco_id
);
session
->
lastTimePacketSize
=
session
->
packet
.
make_null
(
buf
,
sizeof
(
buf
),
session
->
nextSeq
(),
session
->
acct
,
session
->
ademco_id
);
...
@@ -174,30 +173,11 @@ void timer_cb(evutil_socket_t, short, void* arg)
...
@@ -174,30 +173,11 @@ void timer_cb(evutil_socket_t, short, void* arg)
{
{
auto
session
=
(
Session
*
)
arg
;
auto
session
=
(
Session
*
)
arg
;
if
(
load_test
)
{
printf
(
"session #%d timeout
\n
"
,
session
->
id
);
printf
(
"session #%d timeout
\n
"
,
session
->
id
);
session
->
timer
=
nullptr
;
session
->
timer
=
nullptr
;
bufferevent_disable
(
session
->
bev
,
EV_WRITE
);
bufferevent_disable
(
session
->
bev
,
EV_WRITE
);
// SHUT_WR
// SHUT_WR
shutdown
(
session
->
fd
,
1
);
shutdown
(
session
->
fd
,
1
);
}
else
{
session
->
timer
=
event_new
(
threadContexts
[
session
->
thread_id
]
->
base
,
-
1
,
0
,
timer_cb
,
session
);
if
(
!
session
->
timer
)
{
fprintf
(
stderr
,
"create heartbeat_timer failed
\n
"
);
event_base_loopbreak
(
threadContexts
[
session
->
thread_id
]
->
base
);
return
;
}
struct
timeval
heartbeat_tv
=
{
timeout
,
0
};
event_add
(
session
->
timer
,
&
heartbeat_tv
);
char
buf
[
1024
];
session
->
lastTimePacketSize
=
session
->
packet
.
make_null
(
buf
,
sizeof
(
buf
),
session
->
nextSeq
(),
session
->
acct
,
session
->
ademco_id
);
evbuffer_add
(
bufferevent_get_output
(
session
->
bev
),
buf
,
session
->
lastTimePacketSize
);
if
(
print_data
)
{
printf
(
"session #%d send:%s
\n
"
,
session
->
id
,
session
->
packet
.
toString
().
data
());
}
}
}
}
void
eventcb
(
struct
bufferevent
*
bev
,
short
events
,
void
*
user_data
)
void
eventcb
(
struct
bufferevent
*
bev
,
short
events
,
void
*
user_data
)
...
@@ -343,11 +323,8 @@ int main(int argc, char** argv)
...
@@ -343,11 +323,8 @@ int main(int argc, char** argv)
}
}
#endif
#endif
if
(
argc
<
7
)
{
if
(
argc
<
6
)
{
printf
(
"Usage: %s ip port thread_count session_count load_test timeout [print_data]
\n
"
printf
(
"Usage: %s ip port thread_count session_count timeout [print_data]
\n
"
,
argv
[
0
]);
" load_test: 0 or 1:
\n
"
" 0 to disable load test mode, timeout is client's heartbeat timeout in seconds
\n
"
" 1 to enable load test mode, timeout is client's lifecycle timeout in seconds
\n
"
,
argv
[
0
]);
return
1
;
return
1
;
}
}
...
@@ -375,20 +352,19 @@ int main(int argc, char** argv)
...
@@ -375,20 +352,19 @@ int main(int argc, char** argv)
puts
(
"session_count must times thread_count"
);
puts
(
"session_count must times thread_count"
);
return
1
;
return
1
;
}
}
load_test
=
atoi
(
argv
[
5
])
==
1
;
timeout
=
atoi
(
argv
[
5
]);
timeout
=
atoi
(
argv
[
6
]);
if
(
timeout
<=
0
)
{
if
(
timeout
<=
0
)
{
puts
(
"Invalid timeout"
);
puts
(
"Invalid timeout"
);
return
1
;
return
1
;
}
}
if
(
argc
>
7
)
{
if
(
argc
>
6
)
{
print_data
=
atoi
(
argv
[
7
])
==
1
;
print_data
=
atoi
(
argv
[
6
])
==
1
;
}
}
printf
(
"using libevent %s
\n
"
,
event_get_version
());
printf
(
"using libevent %s
\n
"
,
event_get_version
());
int
session_per_thread
=
session_count
/
thread_count
;
int
session_per_thread
=
session_count
/
thread_count
;
printf
(
"starting %s to %s:%d with %d threads, %d sessions, %d sessions per thread,
load_test is %s,
timeout=%ds
\n
"
,
printf
(
"starting %s to %s:%d with %d threads, %d sessions, %d sessions per thread, timeout=%ds
\n
"
,
argv
[
0
],
ip
,
port
,
thread_count
,
session_count
,
session_per_thread
,
load_test
?
"on"
:
"off"
,
timeout
);
argv
[
0
],
ip
,
port
,
thread_count
,
session_count
,
session_per_thread
,
timeout
);
sockaddr_in
sin
=
{
0
};
sockaddr_in
sin
=
{
0
};
sin
.
sin_family
=
AF_INET
;
sin
.
sin_family
=
AF_INET
;
...
...
examples/bench_client_ex/bench_client_ex.cpp
0 → 100644
View file @
8eec0067
#ifndef _WIN32
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/syscall.h>
#else
# ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS
# endif
# ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
# define _WINSOCK_DEPRECATED_NO_WARNINGS
# endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <WinSock2.h>
#pragma comment(lib, "ws2_32.lib")
#endif
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <time.h>
#include <string>
#include <algorithm>
#include <chrono>
#include <thread>
#include <mutex>
#include <unordered_set>
#include <event2/listener.h>
#include <event2/buffer.h>
#include <event2/bufferevent.h>
#include <event2/thread.h>
#define DISABLE_JLIB_LOG2
#define ENABLE_COMMON_MACHINE_TYPE_TO_STRING
#include <hb_helper.h>
using
namespace
ademco
;
using
namespace
hb
;
using
namespace
hb
::
common
;
uint64_t
gettid
()
{
#ifdef _WIN32
return
static_cast
<
uint64_t
>
(
GetCurrentThreadId
());
#else
return
static_cast
<
uint64_t
>
(
::
syscall
(
SYS_gettid
));
#endif
}
int
thread_count
=
0
;
int
session_count
=
0
;
int
session_connected
=
0
;
int
load_test
=
0
;
int
timeout
=
0
;
int
print_data
=
0
;
std
::
mutex
mutex
=
{};
int64_t
totalBytesRead
=
0
;
int64_t
totalBytesWrite
=
0
;
int64_t
totalMsgRead
=
0
;
int64_t
totalMsgWritten
=
0
;
int64_t
totalEncodeTime
=
0
;
int64_t
totalDecodeTime
=
0
;
struct
Session
{
int
fd
=
0
;
int
thread_id
=
0
;
bufferevent
*
bev
=
nullptr
;
event
*
timer
=
nullptr
;
// life or heartbeat timer
int
id
=
0
;
std
::
string
acct
=
{};
AdemcoId
ademco_id
=
0
;
MachineType
type
=
MachineType
::
Gprs
;
MachineStatus
status
=
MachineStatus
::
Arm
;
MachineStatus
status1
=
MachineStatus
::
Arm
;
MachineStatus
status2
=
MachineStatus
::
Arm
;
MachineStatus
status3
=
MachineStatus
::
Arm
;
uint16_t
seq
=
0
;
uint16_t
nextSeq
()
{
if
(
++
seq
==
10000
)
{
seq
=
1
;
}
return
seq
;
}
AdemcoPacket
packet
=
{};
size_t
lastTimePacketSize
=
0
;
int64_t
bytesRead
=
0
;
int64_t
bytesWritten
=
0
;
int64_t
msgRead
=
0
;
int64_t
msgWritten
=
0
;
int64_t
encodeTime
=
0
;
int64_t
decodeTime
=
0
;
};
struct
ThreadContext
{
int
thread_id
=
0
;
event_base
*
base
=
nullptr
;
sockaddr_in
addr
=
{};
int
session_start
=
0
;
int
session_end
=
0
;
void
connectNext
();
};
typedef
ThreadContext
*
ThreadContextPtr
;
ThreadContextPtr
*
threadContexts
=
nullptr
;
void
handle_ademco_msg
(
Session
*
session
,
bufferevent
*
bev
)
{
if
(
print_data
)
{
printf
(
"session #%d recv:%s
\n
"
,
session
->
id
,
session
->
packet
.
toString
().
data
());
}
auto
output
=
bufferevent_get_output
(
bev
);
switch
(
session
->
packet
.
id_
.
eid_
)
{
case
AdemcoMsgId
:
:
id_ack
:
if
(
load_test
)
{
auto
now
=
std
::
chrono
::
steady_clock
::
now
();
char
buf
[
1024
];
session
->
lastTimePacketSize
=
session
->
packet
.
make_null
(
buf
,
sizeof
(
buf
),
session
->
nextSeq
(),
session
->
acct
,
session
->
ademco_id
);
evbuffer_add
(
output
,
buf
,
session
->
lastTimePacketSize
);
auto
us
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
std
::
chrono
::
steady_clock
::
now
()
-
now
).
count
();
session
->
encodeTime
+=
us
;
}
break
;
default:
break
;
}
}
void
readcb
(
struct
bufferevent
*
bev
,
void
*
user_data
)
{
auto
input
=
bufferevent_get_input
(
bev
);
auto
session
=
(
Session
*
)
user_data
;
while
(
1
)
{
size_t
len
=
evbuffer_get_length
(
input
);
if
(
len
<
9
)
{
return
;
}
char
buff
[
1024
]
=
{
0
};
evbuffer_copyout
(
input
,
buff
,
std
::
min
(
len
,
sizeof
(
buff
)));
size_t
cb_commited
=
0
;
auto
now
=
std
::
chrono
::
steady_clock
::
now
();
auto
res
=
session
->
packet
.
parse
(
buff
,
1024
,
cb_commited
);
auto
us
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
std
::
chrono
::
steady_clock
::
now
()
-
now
).
count
();
session
->
decodeTime
+=
us
;
bool
done
=
false
;
switch
(
res
)
{
case
ademco
:
:
ParseResult
::
RESULT_OK
:
evbuffer_drain
(
input
,
cb_commited
);
session
->
bytesRead
+=
cb_commited
;
session
->
msgRead
++
;
handle_ademco_msg
(
session
,
bev
);
break
;
case
ademco
:
:
ParseResult
::
RESULT_NOT_ENOUGH
:
done
=
true
;
break
;
case
ademco
:
:
ParseResult
::
RESULT_DATA_ERROR
:
fprintf
(
stderr
,
"error while parsing data
\n
"
);
evbuffer_drain
(
input
,
len
);
done
=
true
;
break
;
}
if
(
done
)
{
break
;
}
}
}
void
writecb
(
struct
bufferevent
*
bev
,
void
*
user_data
)
{
auto
session
=
(
Session
*
)
user_data
;
if
(
0
==
evbuffer_get_length
(
bufferevent_get_output
(
bev
)))
{
session
->
bytesWritten
+=
session
->
lastTimePacketSize
;
session
->
msgWritten
++
;
}
}
void
timer_cb
(
evutil_socket_t
,
short
,
void
*
arg
)
{
auto
session
=
(
Session
*
)
arg
;
if
(
load_test
)
{
printf
(
"session #%d timeout
\n
"
,
session
->
id
);
session
->
timer
=
nullptr
;
bufferevent_disable
(
session
->
bev
,
EV_WRITE
);
// SHUT_WR
shutdown
(
session
->
fd
,
1
);
}
else
{
session
->
timer
=
event_new
(
threadContexts
[
session
->
thread_id
]
->
base
,
-
1
,
0
,
timer_cb
,
session
);
if
(
!
session
->
timer
)
{
fprintf
(
stderr
,
"create heartbeat_timer failed
\n
"
);
event_base_loopbreak
(
threadContexts
[
session
->
thread_id
]
->
base
);
return
;
}
struct
timeval
heartbeat_tv
=
{
timeout
,
0
};
event_add
(
session
->
timer
,
&
heartbeat_tv
);
char
buf
[
1024
];
session
->
lastTimePacketSize
=
session
->
packet
.
make_null
(
buf
,
sizeof
(
buf
),
session
->
nextSeq
(),
session
->
acct
,
session
->
ademco_id
);
evbuffer_add
(
bufferevent_get_output
(
session
->
bev
),
buf
,
session
->
lastTimePacketSize
);
if
(
print_data
)
{
printf
(
"session #%d send:%s
\n
"
,
session
->
id
,
session
->
packet
.
toString
().
data
());
}
}
}
void
eventcb
(
struct
bufferevent
*
bev
,
short
events
,
void
*
user_data
)
{
auto
session
=
(
Session
*
)
user_data
;
printf
(
"eventcb on session #%d events=%04X
\n
"
,
session
->
id
,
events
);
if
(
events
&
BEV_EVENT_CONNECTED
)
{
auto
ctx
=
threadContexts
[
session
->
thread_id
];
printf
(
"session #%d acct=%s ademco_id=%06X connected fd=%d
\n
"
,
session
->
id
,
session
->
acct
.
data
(),
session
->
ademco_id
,
session
->
fd
);
{
std
::
lock_guard
<
std
::
mutex
>
lg
(
mutex
);
printf
(
"live connections %d
\n
"
,
++
session_connected
);
if
(
session_connected
==
session_count
)
{
printf
(
"All connected
\n
"
);
}
}
char
buf
[
1024
];
session
->
lastTimePacketSize
=
session
->
packet
.
make_hb
(
buf
,
sizeof
(
buf
),
session
->
nextSeq
(),
session
->
acct
,
session
->
ademco_id
,
0
,
ademcoEventFromMachineStatus
(
session
->
status
),
0
);
if
(
print_data
)
{
printf
(
"session #%d send:%s
\n
"
,
session
->
id
,
session
->
packet
.
toString
().
data
());
}
session
->
lastTimePacketSize
+=
session
->
packet
.
make_hb
(
buf
+
session
->
lastTimePacketSize
,
sizeof
(
buf
)
-
session
->
lastTimePacketSize
,
session
->
nextSeq
(),
session
->
acct
,
session
->
ademco_id
,
0
,
ademcoEventFromMachineType
(
session
->
type
),
0
);
if
(
print_data
)
{
printf
(
"session #%d send:%s
\n
"
,
session
->
id
,
session
->
packet
.
toString
().
data
());
}
evbuffer_add
(
bufferevent_get_output
(
bev
),
buf
,
session
->
lastTimePacketSize
);
auto
base
=
bufferevent_get_base
(
bev
);
session
->
timer
=
event_new
(
base
,
-
1
,
EV_TIMEOUT
,
timer_cb
,
session
);
if
(
!
session
->
timer
)
{
fprintf
(
stderr
,
"create timer failed
\n
"
);
event_base_loopbreak
(
base
);
return
;
}
struct
timeval
tv
=
{
timeout
,
0
};
event_add
(
session
->
timer
,
&
tv
);
if
(
++
ctx
->
session_start
<
ctx
->
session_end
)
{
ctx
->
connectNext
();
}
return
;
}
else
if
(
events
&
(
BEV_EVENT_EOF
))
{
printf
(
"session #%d fd=%d acct=%s ademco_id=%06X closed.
\n
"
,
session
->
id
,
session
->
fd
,
session
->
acct
.
data
(),
session
->
ademco_id
);
}
else
if
(
events
&
BEV_EVENT_ERROR
)
{
printf
(
"Got an error on session #%d: %s
\n
"
,
session
->
id
,
strerror
(
errno
));
}
{
std
::
lock_guard
<
std
::
mutex
>
lg
(
mutex
);
totalBytesRead
+=
session
->
bytesRead
;
totalBytesWrite
+=
session
->
bytesWritten
;
totalMsgRead
+=
session
->
msgRead
;
totalMsgWritten
+=
session
->
msgWritten
;
totalEncodeTime
+=
session
->
encodeTime
;
totalDecodeTime
+=
session
->
decodeTime
;
--
session_connected
;
printf
(
"live connections %d
\n
"
,
session_connected
);
if
(
session_connected
==
0
)
{
printf
(
"All disconnected
\n
"
);
double
encodeSpeed
=
totalEncodeTime
*
1.0
/
totalMsgWritten
;
double
decodeSpeed
=
totalDecodeTime
*
1.0
/
totalMsgRead
;
printf
(
"Read %.2f MiB %"
PRId64
" packets, Write %.2f MiB %"
PRId64
" packets
\n
"
"Average msg size is %.2f bytes
\n
"
"Throughput is %.2f MiB/s %.2f packets/s
\n
"
"Encode average time %.2f us, %.2f packets/s
\n
"
"Decode average time %.2f us, %.2f packets/s
\n
"
,
totalBytesRead
/
1024.0
/
1024
,
totalMsgRead
,
totalBytesWrite
/
1024.0
/
1024
,
totalMsgWritten
,
(
totalBytesRead
+
totalBytesWrite
)
*
1.0
/
(
totalMsgRead
+
totalMsgWritten
),
totalBytesRead
*
1.0
/
(
timeout
*
1024.0
*
1024
),
totalMsgRead
*
1.0
/
timeout
,
encodeSpeed
,
1000000.0
/
encodeSpeed
,
decodeSpeed
,
1000000.0
/
decodeSpeed
);
}
}
if
(
session
->
timer
)
{
event_del
(
session
->
timer
);
session
->
timer
=
nullptr
;
}
delete
session
;
bufferevent_free
(
bev
);
//event_base_loopbreak(bufferevent_get_base(bev));
}
ThreadContext
*
init_thread
(
int
thread_id
,
const
sockaddr_in
&
sin
,
int
session_start
,
int
session_per_thread
)
{
ThreadContext
*
context
=
new
ThreadContext
();
context
->
thread_id
=
thread_id
;
context
->
base
=
event_base_new
();
if
(
!
context
->
base
)
{
fprintf
(
stderr
,
"init libevent failed
\n
"
);
exit
(
-
1
);
}
memcpy
(
&
context
->
addr
,
&
sin
,
sizeof
(
sin
));
context
->
session_start
=
session_start
;
context
->
session_end
=
session_start
+
session_per_thread
;
threadContexts
[
thread_id
]
=
context
;
context
->
connectNext
();
return
context
;
}
void
ThreadContext
::
connectNext
()
{
auto
bev
=
bufferevent_socket_new
(
base
,
-
1
,
BEV_OPT_CLOSE_ON_FREE
);
if
(
!
bev
)
{
fprintf
(
stderr
,
"allocate bufferevent failed
\n
"
);
exit
(
-
1
);
}
auto
session
=
new
Session
();
session
->
thread_id
=
thread_id
;
session
->
bev
=
bev
;
session
->
id
=
session_start
;
session
->
acct
=
std
::
string
(
"861234567890"
)
+
std
::
to_string
(
session_start
);
session
->
ademco_id
=
session_start
+
1
;
session
->
seq
=
0
;
bufferevent_setcb
(
bev
,
readcb
,
writecb
,
eventcb
,
session
);
bufferevent_enable
(
bev
,
EV_READ
|
EV_WRITE
);
if
(
bufferevent_socket_connect
(
bev
,
(
const
sockaddr
*
)(
&
addr
),
sizeof
(
addr
))
<
0
)
{
fprintf
(
stderr
,
"error starting connection
\n
"
);
exit
(
-
1
);
}
session
->
fd
=
(
int
)
bufferevent_getfd
(
bev
);
}
int
main
(
int
argc
,
char
**
argv
)
{
#ifdef _WIN32
WSADATA
wsa_data
;
WSAStartup
(
0x0201
,
&
wsa_data
);
if
(
0
!=
evthread_use_windows_threads
())
{
fprintf
(
stderr
,
"failed to init libevent with thread by calling evthread_use_windows_threads
\n
"
);
return
-
1
;
}
#else
if
(
0
!=
evthread_use_pthreads
())
{
fprintf
(
stderr
,
"failed to init libevent with thread by calling evthread_use_pthreads
\n
"
);
return
-
1
;
}
#endif
if
(
argc
<
7
)
{
printf
(
"Usage: %s ip port thread_count session_count load_test timeout [print_data]
\n
"
" load_test: 0 or 1:
\n
"
" 0 to disable load test mode, timeout is client's heartbeat timeout in seconds
\n
"
" 1 to enable load test mode, timeout is client's lifecycle timeout in seconds
\n
"
,
argv
[
0
]);
return
1
;
}
auto
ip
=
argv
[
1
];
int
port
=
atoi
(
argv
[
2
]);
if
(
port
<=
0
||
port
>
65535
)
{
puts
(
"Invalid port"
);
return
1
;
}
thread_count
=
atoi
(
argv
[
3
]);
if
(
thread_count
<=
0
)
{
puts
(
"Invalid thread_count"
);
return
1
;
}
session_count
=
atoi
(
argv
[
4
]);
if
(
session_count
<=
0
)
{
puts
(
"Invalid session_count"
);
return
1
;
}
if
(
thread_count
>
session_count
)
{
puts
(
"thread_count must not bigger than session_count"
);
return
1
;
}
if
(
session_count
%
thread_count
)
{
puts
(
"session_count must times thread_count"
);
return
1
;
}
load_test
=
atoi
(
argv
[
5
])
==
1
;
timeout
=
atoi
(
argv
[
6
]);
if
(
timeout
<=
0
)
{
puts
(
"Invalid timeout"
);
return
1
;
}
if
(
argc
>
7
)
{
print_data
=
atoi
(
argv
[
7
])
==
1
;
}
printf
(
"using libevent %s
\n
"
,
event_get_version
());
int
session_per_thread
=
session_count
/
thread_count
;
printf
(
"starting %s to %s:%d with %d threads, %d sessions, %d sessions per thread, load_test is %s, timeout=%ds
\n
"
,
argv
[
0
],
ip
,
port
,
thread_count
,
session_count
,
session_per_thread
,
load_test
?
"on"
:
"off"
,
timeout
);
sockaddr_in
sin
=
{
0
};
sin
.
sin_family
=
AF_INET
;
sin
.
sin_addr
.
s_addr
=
inet_addr
(
ip
);
sin
.
sin_port
=
htons
(
port
);
std
::
vector
<
std
::
thread
>
threads
;
threadContexts
=
new
ThreadContextPtr
[
thread_count
];
for
(
int
i
=
1
;
i
<
thread_count
;
i
++
)
{
threads
.
push_back
(
std
::
thread
([
&
sin
,
i
,
session_per_thread
]()
{
auto
context
=
init_thread
(
i
,
sin
,
i
*
session_per_thread
,
session_per_thread
);
event_base_dispatch
(
context
->
base
);
}));
}
auto
main_thread_context
=
init_thread
(
0
,
sin
,
0
,
session_per_thread
);
event_base_dispatch
(
main_thread_context
->
base
);
for
(
auto
&
t
:
threads
)
{
t
.
join
();
}
return
0
;
}
examples/bench_client_ex/bench_client_ex.vcxproj
0 → 100644
View file @
8eec0067
<?xml version="1.0" encoding="utf-8"?>
<Project
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<ItemGroup
Label=
"ProjectConfigurations"
>
<ProjectConfiguration
Include=
"Debug|Win32"
>
<Configuration>
Debug
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Release|Win32"
>
<Configuration>
Release
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Debug|x64"
>
<Configuration>
Debug
</Configuration>
<Platform>
x64
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Release|x64"
>
<Configuration>
Release
</Configuration>
<Platform>
x64
</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup
Label=
"Globals"
>
<VCProjectVersion>
16.0
</VCProjectVersion>
<Keyword>
Win32Proj
</Keyword>
<ProjectGuid>
{12e806be-ba3e-452a-ab9d-09f4b379deb2}
</ProjectGuid>
<RootNamespace>
benchclientex
</RootNamespace>
<WindowsTargetPlatformVersion>
10.0
</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.Default.props"
/>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<UseDebugLibraries>
true
</UseDebugLibraries>
<PlatformToolset>
v142
</PlatformToolset>
<CharacterSet>
Unicode
</CharacterSet>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<UseDebugLibraries>
false
</UseDebugLibraries>
<PlatformToolset>
v142
</PlatformToolset>
<WholeProgramOptimization>
true
</WholeProgramOptimization>
<CharacterSet>
Unicode
</CharacterSet>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<UseDebugLibraries>
true
</UseDebugLibraries>
<PlatformToolset>
v142
</PlatformToolset>
<CharacterSet>
Unicode
</CharacterSet>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<UseDebugLibraries>
false
</UseDebugLibraries>
<PlatformToolset>
v142
</PlatformToolset>
<WholeProgramOptimization>
true
</WholeProgramOptimization>
<CharacterSet>
Unicode
</CharacterSet>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.props"
/>
<ImportGroup
Label=
"ExtensionSettings"
>
</ImportGroup>
<ImportGroup
Label=
"Shared"
>
</ImportGroup>
<ImportGroup
Label=
"PropertySheets"
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
</ImportGroup>
<ImportGroup
Label=
"PropertySheets"
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
</ImportGroup>
<ImportGroup
Label=
"PropertySheets"
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
</ImportGroup>
<ImportGroup
Label=
"PropertySheets"
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
</ImportGroup>
<PropertyGroup
Label=
"UserMacros"
/>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<LinkIncremental>
true
</LinkIncremental>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<LinkIncremental>
false
</LinkIncremental>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<LinkIncremental>
true
</LinkIncremental>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<LinkIncremental>
false
</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<ClCompile>
<WarningLevel>
Level3
</WarningLevel>
<SDLCheck>
true
</SDLCheck>
<PreprocessorDefinitions>
WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<ConformanceMode>
true
</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>
Console
</SubSystem>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<ClCompile>
<WarningLevel>
Level3
</WarningLevel>
<FunctionLevelLinking>
true
</FunctionLevelLinking>
<IntrinsicFunctions>
true
</IntrinsicFunctions>
<SDLCheck>
true
</SDLCheck>
<PreprocessorDefinitions>
WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<ConformanceMode>
true
</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>
Console
</SubSystem>
<EnableCOMDATFolding>
true
</EnableCOMDATFolding>
<OptimizeReferences>
true
</OptimizeReferences>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<ClCompile>
<WarningLevel>
Level3
</WarningLevel>
<SDLCheck>
true
</SDLCheck>
<PreprocessorDefinitions>
_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<ConformanceMode>
true
</ConformanceMode>
<AdditionalIncludeDirectories>
$(SolutionDir)..\include;$(DEVLIBS)\libevent-2.1.12-stable-install-x64\include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>
Console
</SubSystem>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
<AdditionalLibraryDirectories>
$(DEVLIBS)\libevent-2.1.12-stable-install-x64\lib;%(AdditionalLibraryDirectories)
</AdditionalLibraryDirectories>
<AdditionalDependencies>
event_core.lib;%(AdditionalDependencies)
</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<ClCompile>
<WarningLevel>
Level3
</WarningLevel>
<FunctionLevelLinking>
true
</FunctionLevelLinking>
<IntrinsicFunctions>
true
</IntrinsicFunctions>
<SDLCheck>
true
</SDLCheck>
<PreprocessorDefinitions>
NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<ConformanceMode>
true
</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>
Console
</SubSystem>
<EnableCOMDATFolding>
true
</EnableCOMDATFolding>
<OptimizeReferences>
true
</OptimizeReferences>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile
Include=
"bench_client_ex.cpp"
/>
</ItemGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.targets"
/>
<ImportGroup
Label=
"ExtensionTargets"
>
</ImportGroup>
</Project>
\ No newline at end of file
examples/bench_client_ex/bench_client_ex.vcxproj.filters
0 → 100644
View file @
8eec0067
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"4.0"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<ItemGroup>
<Filter
Include=
"Source Files"
>
<UniqueIdentifier>
{4FC737F1-C7A5-4376-A066-2A32D752A2FF}
</UniqueIdentifier>
<Extensions>
cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
</Extensions>
</Filter>
<Filter
Include=
"Header Files"
>
<UniqueIdentifier>
{93995380-89BD-4b04-88EB-625FBE52EBFB}
</UniqueIdentifier>
<Extensions>
h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
</Extensions>
</Filter>
<Filter
Include=
"Resource Files"
>
<UniqueIdentifier>
{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
</UniqueIdentifier>
<Extensions>
rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"bench_client_ex.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
examples/bench_client_ex/bench_client_ex.vcxproj.user
0 → 100644
View file @
8eec0067
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"Current"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup
/>
</Project>
\ No newline at end of file
examples/examples.sln
View file @
8eec0067
...
@@ -40,6 +40,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "include", "include", "{332E
...
@@ -40,6 +40,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "include", "include", "{332E
EndProject
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server_demo_libevent_linux", "server_demo_libevent_linux\server_demo_libevent_linux.vcxproj", "{7657FAE6-1ABF-45C3-AA89-ACAC1110C228}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server_demo_libevent_linux", "server_demo_libevent_linux\server_demo_libevent_linux.vcxproj", "{7657FAE6-1ABF-45C3-AA89-ACAC1110C228}"
EndProject
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bench_client_ex", "bench_client_ex\bench_client_ex.vcxproj", "{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}"
EndProject
Global
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Any CPU = Debug|Any CPU
...
@@ -226,6 +228,20 @@ Global
...
@@ -226,6 +228,20 @@ Global
{7657FAE6-1ABF-45C3-AA89-ACAC1110C228}.Release|x86.ActiveCfg = Release|x86
{7657FAE6-1ABF-45C3-AA89-ACAC1110C228}.Release|x86.ActiveCfg = Release|x86
{7657FAE6-1ABF-45C3-AA89-ACAC1110C228}.Release|x86.Build.0 = Release|x86
{7657FAE6-1ABF-45C3-AA89-ACAC1110C228}.Release|x86.Build.0 = Release|x86
{7657FAE6-1ABF-45C3-AA89-ACAC1110C228}.Release|x86.Deploy.0 = Release|x86
{7657FAE6-1ABF-45C3-AA89-ACAC1110C228}.Release|x86.Deploy.0 = Release|x86
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Debug|Any CPU.ActiveCfg = Debug|Win32
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Debug|ARM.ActiveCfg = Debug|Win32
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Debug|ARM64.ActiveCfg = Debug|Win32
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Debug|x64.ActiveCfg = Debug|x64
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Debug|x64.Build.0 = Debug|x64
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Debug|x86.ActiveCfg = Debug|Win32
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Debug|x86.Build.0 = Debug|Win32
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Release|Any CPU.ActiveCfg = Release|Win32
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Release|ARM.ActiveCfg = Release|Win32
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Release|ARM64.ActiveCfg = Release|Win32
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Release|x64.ActiveCfg = Release|x64
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Release|x64.Build.0 = Release|x64
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Release|x86.ActiveCfg = Release|Win32
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
HideSolutionNode = FALSE
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment