Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
ce0be326
Commit
ce0be326
authored
Oct 31, 2017
by
gejun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shorten the delay that -defer_close_second takes effect in worse cases from 2 seconds to 1 second
parent
57cc25d1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
10 deletions
+8
-10
socket_map.cpp
src/brpc/socket_map.cpp
+4
-6
socket_map.h
src/brpc/socket_map.h
+1
-1
brpc_socket_map_unittest.cpp
test/brpc_socket_map_unittest.cpp
+3
-3
No files found.
src/brpc/socket_map.cpp
View file @
ce0be326
...
...
@@ -326,15 +326,13 @@ void SocketMap::List(std::vector<butil::EndPoint>* pts) {
}
}
void
SocketMap
::
ListOrphans
(
int
defer_seconds
,
std
::
vector
<
butil
::
EndPoint
>*
out
)
{
void
SocketMap
::
ListOrphans
(
int64_t
defer_us
,
std
::
vector
<
butil
::
EndPoint
>*
out
)
{
out
->
clear
();
int64_t
now
=
butil
::
cpuwide_time_
s
();
const
int64_t
now
=
butil
::
cpuwide_time_u
s
();
BAIDU_SCOPED_LOCK
(
_mutex
);
for
(
Map
::
iterator
it
=
_map
.
begin
();
it
!=
_map
.
end
();
++
it
)
{
SingleConnection
&
sc
=
it
->
second
;
if
(
sc
.
ref_count
==
0
&&
now
-
sc
.
no_ref_us
/
1000000L
>
defer_seconds
)
{
if
(
sc
.
ref_count
==
0
&&
now
-
sc
.
no_ref_us
>=
defer_us
)
{
out
->
push_back
(
it
->
first
);
}
}
...
...
@@ -378,7 +376,7 @@ void SocketMap::WatchConnections() {
const
int
defer_seconds
=
_options
.
defer_close_second_dynamic
?
*
_options
.
defer_close_second_dynamic
:
_options
.
defer_close_second
;
ListOrphans
(
defer_seconds
,
&
orphan_sockets
);
ListOrphans
(
defer_seconds
*
1000000L
,
&
orphan_sockets
);
for
(
size_t
i
=
0
;
i
<
orphan_sockets
.
size
();
++
i
)
{
RemoveInternal
(
orphan_sockets
[
i
],
(
SocketId
)
-
1
,
true
);
}
...
...
src/brpc/socket_map.h
View file @
ce0be326
...
...
@@ -97,7 +97,7 @@ public:
private
:
void
RemoveInternal
(
const
butil
::
EndPoint
&
pt
,
SocketId
id
,
bool
remove_orphan
);
void
ListOrphans
(
int
defer_second
s
,
std
::
vector
<
butil
::
EndPoint
>*
out
);
void
ListOrphans
(
int
64_t
defer_u
s
,
std
::
vector
<
butil
::
EndPoint
>*
out
);
void
WatchConnections
();
static
void
*
RunWatchConnections
(
void
*
);
void
Print
(
std
::
ostream
&
os
);
...
...
test/brpc_socket_map_unittest.cpp
View file @
ce0be326
...
...
@@ -56,7 +56,7 @@ TEST_F(SocketMapTest, idle_timeout) {
brpc
::
SocketId
id
;
// Socket still exists since it has not reached timeout yet
ASSERT_EQ
(
0
,
brpc
::
SocketMapFind
(
g_endpoint
,
&
id
));
sleep
(
TIMEOUT
+
1
);
usleep
(
TIMEOUT
*
1000000L
+
1100000L
);
// Socket should be removed after timeout
ASSERT_EQ
(
-
1
,
brpc
::
SocketMapFind
(
g_endpoint
,
&
id
));
...
...
@@ -66,7 +66,7 @@ TEST_F(SocketMapTest, idle_timeout) {
ASSERT_EQ
(
0
,
brpc
::
SocketMapFind
(
g_endpoint
,
&
id
));
// Change `FLAGS_idle_timeout_second' to 0 to disable checking
brpc
::
FLAGS_defer_close_second
=
0
;
sleep
(
1
);
usleep
(
1100000L
);
// And then Socket should be removed
ASSERT_EQ
(
-
1
,
brpc
::
SocketMapFind
(
g_endpoint
,
&
id
));
...
...
@@ -82,7 +82,7 @@ TEST_F(SocketMapTest, idle_timeout) {
id
=
ptr
->
id
();
ptr
->
ReturnToPool
();
ptr
.
reset
(
NULL
);
sleep
(
TIMEOUT
+
1
);
usleep
(
TIMEOUT
*
1000000L
+
1100000L
);
// Pooled connection should be `ReleaseAdditionalReference',
// which destroyed the Socket. As a result `GetSocketFromPool'
// should return a new one
...
...
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