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
19f1785c
Commit
19f1785c
authored
Oct 18, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nghttpx: Avoid extra allocation on look up host key
parent
109de15c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
15 deletions
+28
-15
src/shrpx_downstream_queue.cc
src/shrpx_downstream_queue.cc
+13
-9
src/shrpx_downstream_queue.h
src/shrpx_downstream_queue.h
+15
-6
No files found.
src/shrpx_downstream_queue.cc
View file @
19f1785c
...
...
@@ -31,7 +31,8 @@
namespace
shrpx
{
DownstreamQueue
::
HostEntry
::
HostEntry
()
:
num_active
(
0
)
{}
DownstreamQueue
::
HostEntry
::
HostEntry
(
ImmutableString
&&
key
)
:
key
(
std
::
move
(
key
)),
num_active
(
0
)
{}
DownstreamQueue
::
DownstreamQueue
(
size_t
conn_max_per_host
,
bool
unified_host
)
:
conn_max_per_host_
(
conn_max_per_host
==
0
...
...
@@ -57,25 +58,28 @@ void DownstreamQueue::mark_failure(Downstream *downstream) {
}
DownstreamQueue
::
HostEntry
&
DownstreamQueue
::
find_host_entry
(
const
std
::
string
&
host
)
{
DownstreamQueue
::
find_host_entry
(
const
StringRef
&
host
)
{
auto
itr
=
host_entries_
.
find
(
host
);
if
(
itr
==
std
::
end
(
host_entries_
))
{
auto
key
=
ImmutableString
{
std
::
begin
(
host
),
std
::
end
(
host
)};
auto
key_ref
=
StringRef
{
key
};
#ifdef HAVE_STD_MAP_EMPLACE
std
::
tie
(
itr
,
std
::
ignore
)
=
host_entries_
.
emplace
(
host
,
HostEntry
());
std
::
tie
(
itr
,
std
::
ignore
)
=
host_entries_
.
emplace
(
key_ref
,
HostEntry
(
std
::
move
(
key
)));
#else // !HAVE_STD_MAP_EMPLACE
// for g++-4.7
std
::
tie
(
itr
,
std
::
ignore
)
=
host_entries_
.
insert
(
std
::
make_pair
(
host
,
HostEntry
(
)));
std
::
tie
(
itr
,
std
::
ignore
)
=
host_entries_
.
insert
(
std
::
make_pair
(
key_ref
,
HostEntry
(
std
::
move
(
key
)
)));
#endif // !HAVE_STD_MAP_EMPLACE
}
return
(
*
itr
).
second
;
}
std
::
string
DownstreamQueue
::
make_host_key
(
const
StringRef
&
host
)
const
{
return
unified_host_
?
""
:
host
.
str
()
;
StringRef
DownstreamQueue
::
make_host_key
(
const
StringRef
&
host
)
const
{
return
unified_host_
?
StringRef
{}
:
host
;
}
std
::
string
DownstreamQueue
::
make_host_key
(
Downstream
*
downstream
)
const
{
StringRef
DownstreamQueue
::
make_host_key
(
Downstream
*
downstream
)
const
{
return
make_host_key
(
downstream
->
request
().
authority
);
}
...
...
@@ -108,7 +112,7 @@ bool DownstreamQueue::can_activate(const StringRef &host) const {
namespace
{
bool
remove_host_entry_if_empty
(
const
DownstreamQueue
::
HostEntry
&
ent
,
DownstreamQueue
::
HostEntryMap
&
host_entries
,
const
std
::
string
&
host
)
{
const
StringRef
&
host
)
{
if
(
ent
.
blocked
.
empty
()
&&
ent
.
num_active
==
0
)
{
host_entries
.
erase
(
host
);
return
true
;
...
...
src/shrpx_downstream_queue.h
View file @
19f1785c
...
...
@@ -51,14 +51,23 @@ struct BlockedLink {
class
DownstreamQueue
{
public:
struct
HostEntry
{
HostEntry
(
ImmutableString
&&
key
);
HostEntry
(
HostEntry
&&
)
=
default
;
HostEntry
&
operator
=
(
HostEntry
&&
)
=
default
;
HostEntry
(
const
HostEntry
&
)
=
delete
;
HostEntry
&
operator
=
(
const
HostEntry
&
)
=
delete
;
// Key that associates this object
ImmutableString
key
;
// Set of stream ID that blocked by conn_max_per_host_.
DList
<
BlockedLink
>
blocked
;
// The number of connections currently made to this host.
size_t
num_active
;
HostEntry
();
};
using
HostEntryMap
=
std
::
map
<
std
::
string
,
HostEntry
>
;
using
HostEntryMap
=
std
::
map
<
StringRef
,
HostEntry
,
std
::
less
<
StringRef
>
>
;
// conn_max_per_host == 0 means no limit for downstream connection.
DownstreamQueue
(
size_t
conn_max_per_host
=
0
,
bool
unified_host
=
true
);
...
...
@@ -86,14 +95,14 @@ public:
Downstream
*
remove_and_get_blocked
(
Downstream
*
downstream
,
bool
next_blocked
=
true
);
Downstream
*
get_downstreams
()
const
;
HostEntry
&
find_host_entry
(
const
std
::
string
&
host
);
std
::
string
make_host_key
(
const
StringRef
&
host
)
const
;
std
::
string
make_host_key
(
Downstream
*
downstream
)
const
;
HostEntry
&
find_host_entry
(
const
StringRef
&
host
);
StringRef
make_host_key
(
const
StringRef
&
host
)
const
;
StringRef
make_host_key
(
Downstream
*
downstream
)
const
;
private:
// Per target host structure to keep track of the number of
// connections to the same host.
std
::
map
<
std
::
string
,
HostEntry
>
host_entries_
;
HostEntryMap
host_entries_
;
DList
<
Downstream
>
downstreams_
;
// Maximum number of concurrent connections to the same host.
size_t
conn_max_per_host_
;
...
...
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