Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
5cfb51c8
Commit
5cfb51c8
authored
Mar 04, 2014
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
h2load: Support parellel native threads execution with -t option
parent
f3183efe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
12 deletions
+74
-12
src/h2load.cc
src/h2load.cc
+70
-10
src/h2load.h
src/h2load.h
+4
-2
No files found.
src/h2load.cc
View file @
5cfb51c8
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#include <cstdlib>
#include <cstdlib>
#include <iostream>
#include <iostream>
#include <chrono>
#include <chrono>
#include <thread>
#ifdef HAVE_SPDYLAY
#ifdef HAVE_SPDYLAY
#include <spdylay/spdylay.h>
#include <spdylay/spdylay.h>
...
@@ -60,7 +61,7 @@ Config::Config()
...
@@ -60,7 +61,7 @@ Config::Config()
:
addrs
(
nullptr
),
:
addrs
(
nullptr
),
nreqs
(
1
),
nreqs
(
1
),
nclients
(
1
),
nclients
(
1
),
n
worker
s
(
1
),
n
thread
s
(
1
),
max_concurrent_streams
(
1
),
max_concurrent_streams
(
1
),
window_bits
(
16
),
window_bits
(
16
),
connection_window_bits
(
16
),
connection_window_bits
(
16
),
...
@@ -191,7 +192,8 @@ void Client::process_abandoned_streams()
...
@@ -191,7 +192,8 @@ void Client::process_abandoned_streams()
void
Client
::
report_progress
()
void
Client
::
report_progress
()
{
{
if
(
worker
->
stats
.
req_done
%
worker
->
progress_interval
==
0
)
{
if
(
worker
->
id
==
0
&&
worker
->
stats
.
req_done
%
worker
->
progress_interval
==
0
)
{
std
::
cout
<<
"progress: "
std
::
cout
<<
"progress: "
<<
worker
->
stats
.
req_done
*
100
/
worker
->
stats
.
req_todo
<<
worker
->
stats
.
req_done
*
100
/
worker
->
stats
.
req_todo
<<
"% done"
<<
"% done"
...
@@ -299,13 +301,14 @@ int Client::on_write()
...
@@ -299,13 +301,14 @@ int Client::on_write()
return
session
->
on_write
();
return
session
->
on_write
();
}
}
Worker
::
Worker
(
SSL_CTX
*
ssl_ctx
,
Config
*
config
)
Worker
::
Worker
(
uint32_t
id
,
SSL_CTX
*
ssl_ctx
,
size_t
req_todo
,
size_t
nclients
,
Config
*
config
)
:
stats
{
0
},
evbase
(
event_base_new
()),
ssl_ctx
(
ssl_ctx
),
config
(
config
),
:
stats
{
0
},
evbase
(
event_base_new
()),
ssl_ctx
(
ssl_ctx
),
config
(
config
),
term_timer_started
(
false
)
id
(
id
),
term_timer_started
(
false
)
{
{
stats
.
req_todo
=
config
->
nreqs
;
stats
.
req_todo
=
req_todo
;
progress_interval
=
std
::
max
((
size_t
)
1
,
config
->
nreqs
/
10
);
progress_interval
=
std
::
max
((
size_t
)
1
,
req_todo
/
10
);
for
(
size_t
i
=
0
;
i
<
config
->
nclients
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
nclients
;
++
i
)
{
clients
.
push_back
(
util
::
make_unique
<
Client
>
(
this
));
clients
.
push_back
(
util
::
make_unique
<
Client
>
(
this
));
}
}
}
}
...
@@ -539,6 +542,8 @@ void print_help(std::ostream& out)
...
@@ -539,6 +542,8 @@ void print_help(std::ostream& out)
<<
config
.
nreqs
<<
"
\n
"
<<
config
.
nreqs
<<
"
\n
"
<<
" -c, --clients=<N> Number of concurrent clients. Default: "
<<
" -c, --clients=<N> Number of concurrent clients. Default: "
<<
config
.
nclients
<<
"
\n
"
<<
config
.
nclients
<<
"
\n
"
<<
" -t, --threads=<N> Number of native threads. Default: "
<<
config
.
nthreads
<<
"
\n
"
<<
" -m, --max-concurrent-streams=<N>
\n
"
<<
" -m, --max-concurrent-streams=<N>
\n
"
<<
" Max concurrent streams to issue per session.
\n
"
<<
" Max concurrent streams to issue per session.
\n
"
<<
" Default: "
<<
" Default: "
...
@@ -566,7 +571,7 @@ int main(int argc, char **argv)
...
@@ -566,7 +571,7 @@ int main(int argc, char **argv)
static
option
long_options
[]
=
{
static
option
long_options
[]
=
{
{
"requests"
,
required_argument
,
nullptr
,
'n'
},
{
"requests"
,
required_argument
,
nullptr
,
'n'
},
{
"clients"
,
required_argument
,
nullptr
,
'c'
},
{
"clients"
,
required_argument
,
nullptr
,
'c'
},
{
"
worker
s"
,
required_argument
,
nullptr
,
't'
},
{
"
thread
s"
,
required_argument
,
nullptr
,
't'
},
{
"max-concurrent-streams"
,
required_argument
,
nullptr
,
'm'
},
{
"max-concurrent-streams"
,
required_argument
,
nullptr
,
'm'
},
{
"window-bits"
,
required_argument
,
nullptr
,
'w'
},
{
"window-bits"
,
required_argument
,
nullptr
,
'w'
},
{
"connection-window-bits"
,
required_argument
,
nullptr
,
'W'
},
{
"connection-window-bits"
,
required_argument
,
nullptr
,
'W'
},
...
@@ -589,7 +594,7 @@ int main(int argc, char **argv)
...
@@ -589,7 +594,7 @@ int main(int argc, char **argv)
config
.
nclients
=
strtoul
(
optarg
,
nullptr
,
10
);
config
.
nclients
=
strtoul
(
optarg
,
nullptr
,
10
);
break
;
break
;
case
't'
:
case
't'
:
config
.
n
worker
s
=
strtoul
(
optarg
,
nullptr
,
10
);
config
.
n
thread
s
=
strtoul
(
optarg
,
nullptr
,
10
);
break
;
break
;
case
'm'
:
case
'm'
:
config
.
max_concurrent_streams
=
strtoul
(
optarg
,
nullptr
,
10
);
config
.
max_concurrent_streams
=
strtoul
(
optarg
,
nullptr
,
10
);
...
@@ -653,6 +658,12 @@ int main(int argc, char **argv)
...
@@ -653,6 +658,12 @@ int main(int argc, char **argv)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
config
.
nthreads
==
0
)
{
std
::
cerr
<<
"-t: the number of threads must be strictly greater than 0."
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
if
(
config
.
nreqs
<
config
.
nclients
)
{
if
(
config
.
nreqs
<
config
.
nclients
)
{
std
::
cerr
<<
"-n, -c: the number of requests must be greater than or "
std
::
cerr
<<
"-n, -c: the number of requests must be greater than or "
<<
"equal to the concurrent clients."
<<
"equal to the concurrent clients."
...
@@ -660,6 +671,12 @@ int main(int argc, char **argv)
...
@@ -660,6 +671,12 @@ int main(int argc, char **argv)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
config
.
nthreads
>
std
::
thread
::
hardware_concurrency
())
{
std
::
cerr
<<
"-t: warning: the number of threads is greater than hardware "
<<
"cores."
<<
std
::
endl
;
}
struct
sigaction
act
;
struct
sigaction
act
;
memset
(
&
act
,
0
,
sizeof
(
struct
sigaction
));
memset
(
&
act
,
0
,
sizeof
(
struct
sigaction
));
act
.
sa_handler
=
SIG_IGN
;
act
.
sa_handler
=
SIG_IGN
;
...
@@ -728,12 +745,55 @@ int main(int argc, char **argv)
...
@@ -728,12 +745,55 @@ int main(int argc, char **argv)
resolve_host
();
resolve_host
();
Worker
worker
(
ssl_ctx
,
&
config
);
size_t
nreqs_per_thread
=
config
.
nreqs
/
config
.
nthreads
;
ssize_t
nreqs_rem
=
config
.
nreqs
%
config
.
nthreads
;
size_t
nclients_per_thread
=
config
.
nclients
/
config
.
nthreads
;
ssize_t
nclients_rem
=
config
.
nclients
%
config
.
nthreads
;
std
::
cout
<<
"starting benchmark..."
<<
std
::
endl
;
std
::
cout
<<
"starting benchmark..."
<<
std
::
endl
;
std
::
vector
<
std
::
thread
>
threads
;
auto
start
=
std
::
chrono
::
steady_clock
::
now
();
auto
start
=
std
::
chrono
::
steady_clock
::
now
();
std
::
vector
<
std
::
unique_ptr
<
Worker
>>
workers
;
for
(
size_t
i
=
0
;
i
<
config
.
nthreads
-
1
;
++
i
)
{
auto
nreqs
=
nreqs_per_thread
+
(
nreqs_rem
--
>
0
);
auto
nclients
=
nclients_per_thread
+
(
nclients_rem
--
>
0
);
std
::
cout
<<
"spawning thread #"
<<
i
<<
": "
<<
nclients
<<
" concurrent clients, "
<<
nreqs
<<
" total requests"
<<
std
::
endl
;
workers
.
push_back
(
util
::
make_unique
<
Worker
>
(
i
,
ssl_ctx
,
nreqs
,
nclients
,
&
config
));
threads
.
emplace_back
(
&
Worker
::
run
,
workers
.
back
().
get
());
}
auto
nreqs_last
=
nreqs_per_thread
+
(
nreqs_rem
--
>
0
);
auto
nclients_last
=
nclients_per_thread
+
(
nclients_rem
--
>
0
);
std
::
cout
<<
"spawning thread #"
<<
(
config
.
nthreads
-
1
)
<<
": "
<<
nclients_last
<<
" concurrent clients, "
<<
nreqs_last
<<
" total requests"
<<
std
::
endl
;
Worker
worker
(
config
.
nthreads
-
1
,
ssl_ctx
,
nreqs_last
,
nclients_last
,
&
config
);
worker
.
run
();
worker
.
run
();
for
(
size_t
i
=
0
;
i
<
config
.
nthreads
-
1
;
++
i
)
{
threads
[
i
].
join
();
worker
.
stats
.
req_todo
+=
workers
[
i
]
->
stats
.
req_todo
;
worker
.
stats
.
req_started
+=
workers
[
i
]
->
stats
.
req_started
;
worker
.
stats
.
req_done
+=
workers
[
i
]
->
stats
.
req_done
;
worker
.
stats
.
req_success
+=
workers
[
i
]
->
stats
.
req_success
;
worker
.
stats
.
req_failed
+=
workers
[
i
]
->
stats
.
req_failed
;
worker
.
stats
.
req_error
+=
workers
[
i
]
->
stats
.
req_error
;
worker
.
stats
.
bytes_total
+=
workers
[
i
]
->
stats
.
bytes_total
;
worker
.
stats
.
bytes_head
+=
workers
[
i
]
->
stats
.
bytes_head
;
worker
.
stats
.
bytes_body
+=
workers
[
i
]
->
stats
.
bytes_body
;
for
(
size_t
j
=
0
;
j
<
6
;
++
j
)
{
worker
.
stats
.
status
[
j
]
+=
workers
[
i
]
->
stats
.
status
[
j
];
}
}
auto
end
=
std
::
chrono
::
steady_clock
::
now
();
auto
end
=
std
::
chrono
::
steady_clock
::
now
();
auto
duration
=
auto
duration
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
end
-
start
).
count
();
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
end
-
start
).
count
();
...
...
src/h2load.h
View file @
5cfb51c8
...
@@ -56,7 +56,7 @@ struct Config {
...
@@ -56,7 +56,7 @@ struct Config {
addrinfo
*
addrs
;
addrinfo
*
addrs
;
size_t
nreqs
;
size_t
nreqs
;
size_t
nclients
;
size_t
nclients
;
size_t
n
worker
s
;
size_t
n
thread
s
;
// The maximum number of concurrent streams per session.
// The maximum number of concurrent streams per session.
size_t
max_concurrent_streams
;
size_t
max_concurrent_streams
;
size_t
window_bits
;
size_t
window_bits
;
...
@@ -109,9 +109,11 @@ struct Worker {
...
@@ -109,9 +109,11 @@ struct Worker {
SSL_CTX
*
ssl_ctx
;
SSL_CTX
*
ssl_ctx
;
Config
*
config
;
Config
*
config
;
size_t
progress_interval
;
size_t
progress_interval
;
uint32_t
id
;
bool
term_timer_started
;
bool
term_timer_started
;
Worker
(
SSL_CTX
*
ssl_ctx
,
Config
*
config
);
Worker
(
uint32_t
id
,
SSL_CTX
*
ssl_ctx
,
size_t
nreq_todo
,
size_t
nclients
,
Config
*
config
);
~
Worker
();
~
Worker
();
void
run
();
void
run
();
void
schedule_terminate
();
void
schedule_terminate
();
...
...
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