Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Beyond Protocol
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Beyond AKA
Beyond Protocol
Commits
5410f99f
Commit
5410f99f
authored
3 years ago
by
Nicolas Pope
Browse files
Options
Downloads
Patches
Plain Diff
Reduce buffer size and remove logs
parent
0bbe1530
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/peer.cpp
+5
-27
5 additions, 27 deletions
src/peer.cpp
src/peer.hpp
+1
-1
1 addition, 1 deletion
src/peer.hpp
src/universe.cpp
+1
-6
1 addition, 6 deletions
src/universe.cpp
with
7 additions
and
34 deletions
src/peer.cpp
+
5
−
27
View file @
5410f99f
...
@@ -174,7 +174,7 @@ bool Peer::reconnect() {
...
@@ -174,7 +174,7 @@ bool Peer::reconnect() {
URI
uri
(
uri_
);
URI
uri
(
uri_
);
LOG
(
INFO
)
<<
"Reconnecting to "
<<
uri_
.
to_string
()
<<
" ..."
;
LOG
(
1
)
<<
"Reconnecting to "
<<
uri_
.
to_string
()
<<
" ..."
;
try
{
try
{
_connect
();
_connect
();
...
@@ -254,31 +254,17 @@ NodeType Peer::getType() const {
...
@@ -254,31 +254,17 @@ NodeType Peer::getType() const {
}
}
void
Peer
::
data
()
{
void
Peer
::
data
()
{
//UNIQUE_LOCK(recv_mtx_,lk);
if
(
!
sock_
->
is_valid
())
{
return
;
}
if
(
!
sock_
->
is_valid
())
{
return
;
}
int
rc
=
0
;
int
rc
=
0
;
{
// Only need to lock and reserve buffer if there isn't enough
if
(
recv_buf_
.
buffer_capacity
()
<
kMaxMessage
)
{
UNIQUE_LOCK
(
recv_mtx_
,
lk
);
UNIQUE_LOCK
(
recv_mtx_
,
lk
);
recv_buf_
.
reserve_buffer
(
kMaxMessage
);
recv_buf_
.
reserve_buffer
(
kMaxMessage
);
}
}
if
(
recv_buf_
.
buffer_capacity
()
<
(
kMaxMessage
/
10
))
{
net_
->
_notifyError
(
this
,
ftl
::
protocol
::
Error
::
kBufferSize
,
"Buffer is at capacity"
);
return
;
}
int
cap
=
static_cast
<
int
>
(
recv_buf_
.
buffer_capacity
());
int
cap
=
static_cast
<
int
>
(
recv_buf_
.
buffer_capacity
());
// Buffer acquired, recv can be called outside the lock.
// TODO: Check if this is actually correct. If two threads call recv()
// outside the lock and the second thread to call recv() re-acquires
// the lock first, buffer_consumed() will be called first with second
// thread's number of bytes (rc).
//auto ctr = dbg_recv_begin_ctr_++;
//lk.unlock();
try
{
try
{
rc
=
sock_
->
recv
(
recv_buf_
.
buffer
(),
recv_buf_
.
buffer_capacity
());
rc
=
sock_
->
recv
(
recv_buf_
.
buffer
(),
recv_buf_
.
buffer_capacity
());
...
@@ -308,16 +294,9 @@ void Peer::data() {
...
@@ -308,16 +294,9 @@ void Peer::data() {
return
;
return
;
}
}
// Re-acquire lock before processing buffer further
// May possibly need locking
//lk.lock();
// buffer_consumed() will not be updated with correct value, race condition
// described above has occurred
//CHECK(ctr == dbg_recv_end_ctr_++) << "race in Peer::data()";
recv_buf_
.
buffer_consumed
(
rc
);
recv_buf_
.
buffer_consumed
(
rc
);
//UNIQUE_LOCK(recv_mtx_, lk);
recv_checked_
.
clear
();
recv_checked_
.
clear
();
if
(
!
already_processing_
.
test_and_set
())
{
if
(
!
already_processing_
.
test_and_set
())
{
//lk.unlock();
//lk.unlock();
...
@@ -543,7 +522,6 @@ bool Peer::waitConnection(int s) {
...
@@ -543,7 +522,6 @@ bool Peer::waitConnection(int s) {
});
});
cv
.
wait_for
(
lk
,
seconds
(
s
),
[
this
]()
{
return
status_
==
NodeStatus
::
kConnected
;});
cv
.
wait_for
(
lk
,
seconds
(
s
),
[
this
]()
{
return
status_
==
NodeStatus
::
kConnected
;});
LOG
(
ERROR
)
<<
"CONN STAT = "
<<
int
(
status_
);
return
status_
==
NodeStatus
::
kConnected
;
return
status_
==
NodeStatus
::
kConnected
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/peer.hpp
+
1
−
1
View file @
5410f99f
...
@@ -195,7 +195,7 @@ class Peer {
...
@@ -195,7 +195,7 @@ class Peer {
int
connectionCount
()
const
{
return
connection_count_
;
}
int
connectionCount
()
const
{
return
connection_count_
;
}
public
:
public
:
static
const
int
kMaxMessage
=
10
*
1024
*
1024
;
// 10Mb currently
static
const
int
kMaxMessage
=
2
*
1024
*
1024
;
// 10Mb currently
protected
:
protected
:
void
data
();
// Process one message from socket
void
data
();
// Process one message from socket
...
...
This diff is collapsed.
Click to expand it.
src/universe.cpp
+
1
−
6
View file @
5410f99f
...
@@ -374,8 +374,6 @@ void Universe::_removePeer(PeerPtr &p) {
...
@@ -374,8 +374,6 @@ void Universe::_removePeer(PeerPtr &p) {
}
}
}
}
LOG
(
INFO
)
<<
"Remove peer: "
<<
int
(
p
->
status
());
if
(
p
->
status
()
==
NodeStatus
::
kReconnecting
)
{
if
(
p
->
status
()
==
NodeStatus
::
kReconnecting
)
{
reconnects_
.
push_back
({
reconnect_attempts_
,
1.0
f
,
p
});
reconnects_
.
push_back
({
reconnect_attempts_
,
1.0
f
,
p
});
}
else
{
}
else
{
...
@@ -427,7 +425,6 @@ std::list<PeerPtr> Universe::getPeers() const {
...
@@ -427,7 +425,6 @@ std::list<PeerPtr> Universe::getPeers() const {
}
}
void
Universe
::
_periodic
()
{
void
Universe
::
_periodic
()
{
LOG
(
INFO
)
<<
"PERIODIC "
<<
reconnects_
.
size
();
auto
i
=
reconnects_
.
begin
();
auto
i
=
reconnects_
.
begin
();
while
(
i
!=
reconnects_
.
end
())
{
while
(
i
!=
reconnects_
.
end
())
{
...
@@ -458,9 +455,7 @@ void Universe::_periodic() {
...
@@ -458,9 +455,7 @@ void Universe::_periodic() {
peer
->
status_
=
NodeStatus
::
kConnecting
;
peer
->
status_
=
NodeStatus
::
kConnecting
;
i
=
reconnects_
.
erase
(
i
);
i
=
reconnects_
.
erase
(
i
);
//ftl::pool.push([peer](int id) {
//ftl::pool.push([peer](int id) {
if
(
!
peer
->
reconnect
())
{
peer
->
reconnect
();
LOG
(
INFO
)
<<
"Reconnect failed"
;
}
//});
//});
/*if ((*i).peer->reconnect()) {
/*if ((*i).peer->reconnect()) {
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment