Skip to content

Commit e7c182a

Browse files
authored
refactor socket pool (#1484)
1. define a new interface ```ISocketPool``` that supports connection grouping by user-defined keys, in addition to Endpoints 2. allow for user-defined callback for connection heartbeat, as construction argument 3. support TCP-Keepalive 4. re-design the implementation to support these new features 5. optimization of the data structure to eliminate redundant stores of keys (Endpoints), as well as fds 6. merge the timer and the collector thread The keys (Endpoints) were stored 3 times in: unordered_map (fdmap), StreamListNode, and PooledTCPSocketStream. Now they are stored once in StreamListHead, located at the end of StreamListHead to support variable length. And the unordered_map is changed to unordered_set. The maintainance routines, e.g. evict(), release(), collect(), etc., are changed accordingly.
1 parent c856a10 commit e7c182a

7 files changed

Lines changed: 1334 additions & 128 deletions

File tree

common/checksum/test/test_checksum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ TEST(Perf, crc32c_sw) {
169169

170170
void do_test64(const char* name, CRC64ECMA crc64ecma) {
171171
auto start = std::chrono::system_clock::now();
172-
for (int i = 0; i < 100; ++i)
172+
// for (int i = 0; i < 100; ++i)
173173
for (auto& c: cases) {
174174
auto crc64 = crc64ecma((uint8_t*)c.s.data(), c.s.length(), 0);
175175
if (crc64 != c.crc64ecma) puts(c.s.data());

common/intrusive_list.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class intrusive_list
358358
{
359359
return node;
360360
}
361-
bool empty()
361+
bool empty() const
362362
{
363363
return node == nullptr;
364364
}
@@ -430,17 +430,19 @@ class intrusive_list
430430
}
431431
return split_front_exclusive(first_not_fit);
432432
}
433-
void delete_all()
433+
size_t delete_all()
434434
{
435435
auto ptr = node;
436+
size_t n = 0;
436437
if (ptr) {
437438
do {
438439
auto next = ptr->next();
439-
delete ptr;
440+
delete ptr; n++;
440441
ptr = next;
441442
} while (ptr != node);
442443
}
443444
node = nullptr;
445+
return n;
444446
}
445447
NodeType* round_robin_next() {
446448
auto x = node;

common/timeout.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ class Timeout {
5656
bool operator < (const Timeout& rhs) const {
5757
return m_expiration < rhs.m_expiration;
5858
}
59+
bool operator <= (const Timeout& rhs) const {
60+
return m_expiration < rhs.m_expiration;
61+
}
62+
bool operator > (const Timeout& rhs) const {
63+
return m_expiration > rhs.m_expiration;
64+
}
65+
bool operator >= (const Timeout& rhs) const {
66+
return m_expiration >= rhs.m_expiration;
67+
}
68+
bool operator == (const Timeout& rhs) const {
69+
return m_expiration == rhs.m_expiration;
70+
}
5971
Timeout& timeout_at_most(uint64_t x) {
6072
x = sat_add(now, x);
6173
if (x < m_expiration)

include/sys/socket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ limitations under the License.
2727
#include <winsock2.h>
2828
#include <ws2tcpip.h>
2929
#include <mswsock.h>
30+
#include <mstcpip.h>
3031

3132
// Winsock's getsockname / getpeername / accept / recvfrom all take `int*` for
3233
// the address-length parameter, while POSIX uses `socklen_t*`. MinGW

0 commit comments

Comments
 (0)