Skip to content

Commit 0a3e060

Browse files
Tuong Liendavem330
authored andcommitted
tipc: add test for Nagle algorithm effectiveness
When streaming in Nagle mode, we try to bundle small messages from user as many as possible if there is one outstanding buffer, i.e. not ACK-ed by the receiving side, which helps boost up the overall throughput. So, the algorithm's effectiveness really depends on when Nagle ACK comes or what the specific network latency (RTT) is, compared to the user's message sending rate. In a bad case, the user's sending rate is low or the network latency is small, there will not be many bundles, so making a Nagle ACK or waiting for it is not meaningful. For example: a user sends its messages every 100ms and the RTT is 50ms, then for each messages, we require one Nagle ACK but then there is only one user message sent without any bundles. In a better case, even if we have a few bundles (e.g. the RTT = 300ms), but now the user sends messages in medium size, then there will not be any difference at all, that says 3 x 1000-byte data messages if bundled will still result in 3 bundles with MTU = 1500. When Nagle is ineffective, the delay in user message sending is clearly wasted instead of sending directly. Besides, adding Nagle ACKs will consume some processor load on both the sending and receiving sides. This commit adds a test on the effectiveness of the Nagle algorithm for an individual connection in the network on which it actually runs. Particularly, upon receipt of a Nagle ACK we will compare the number of bundles in the backlog queue to the number of user messages which would be sent directly without Nagle. If the ratio is good (e.g. >= 2), Nagle mode will be kept for further message sending. Otherwise, we will leave Nagle and put a 'penalty' on the connection, so it will have to spend more 'one-way' messages before being able to re-enter Nagle. In addition, the 'ack-required' bit is only set when really needed that the number of Nagle ACKs will be reduced during Nagle mode. Testing with benchmark showed that with the patch, there was not much difference in throughput for small messages since the tool continuously sends messages without a break, so Nagle would still take in effect. Acked-by: Ying Xue <ying.xue@windriver.com> Acked-by: Jon Maloy <jmaloy@redhat.com> Signed-off-by: Tuong Lien <tuong.t.lien@dektech.com.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 03b6fef commit 0a3e060

3 files changed

Lines changed: 64 additions & 17 deletions

File tree

‎net/tipc/msg.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,6 @@ int tipc_msg_append(struct tipc_msg *_hdr, struct msghdr *m, int dlen,
235235
msg_set_size(hdr, MIN_H_SIZE);
236236
__skb_queue_tail(txq, skb);
237237
total += 1;
238-
if (prev)
239-
msg_set_ack_required(buf_msg(prev), 0);
240-
msg_set_ack_required(hdr, 1);
241238
}
242239
hdr = buf_msg(skb);
243240
curr = msg_blocks(hdr);

‎net/tipc/msg.h‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,19 @@ static inline int msg_ack_required(struct tipc_msg *m)
340340
return msg_bits(m, 0, 18, 1);
341341
}
342342

343-
static inline void msg_set_ack_required(struct tipc_msg *m, u32 d)
343+
static inline void msg_set_ack_required(struct tipc_msg *m)
344344
{
345-
msg_set_bits(m, 0, 18, 1, d);
345+
msg_set_bits(m, 0, 18, 1, 1);
346+
}
347+
348+
static inline int msg_nagle_ack(struct tipc_msg *m)
349+
{
350+
return msg_bits(m, 0, 18, 1);
351+
}
352+
353+
static inline void msg_set_nagle_ack(struct tipc_msg *m)
354+
{
355+
msg_set_bits(m, 0, 18, 1, 1);
346356
}
347357

348358
static inline bool msg_is_rcast(struct tipc_msg *m)

‎net/tipc/socket.c‎

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#include "group.h"
4949
#include "trace.h"
5050

51+
#define NAGLE_START_INIT 4
52+
#define NAGLE_START_MAX 1024
5153
#define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */
5254
#define CONN_PROBING_INTV msecs_to_jiffies(3600000) /* [ms] => 1 h */
5355
#define TIPC_FWD_MSG 1
@@ -119,7 +121,10 @@ struct tipc_sock {
119121
struct rcu_head rcu;
120122
struct tipc_group *group;
121123
u32 oneway;
124+
u32 nagle_start;
122125
u16 snd_backlog;
126+
u16 msg_acc;
127+
u16 pkt_cnt;
123128
bool expect_ack;
124129
bool nodelay;
125130
bool group_is_open;
@@ -143,7 +148,7 @@ static int tipc_sk_insert(struct tipc_sock *tsk);
143148
static void tipc_sk_remove(struct tipc_sock *tsk);
144149
static int __tipc_sendstream(struct socket *sock, struct msghdr *m, size_t dsz);
145150
static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dsz);
146-
static void tipc_sk_push_backlog(struct tipc_sock *tsk);
151+
static void tipc_sk_push_backlog(struct tipc_sock *tsk, bool nagle_ack);
147152

148153
static const struct proto_ops packet_ops;
149154
static const struct proto_ops stream_ops;
@@ -474,6 +479,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
474479
tsk = tipc_sk(sk);
475480
tsk->max_pkt = MAX_PKT_DEFAULT;
476481
tsk->maxnagle = 0;
482+
tsk->nagle_start = NAGLE_START_INIT;
477483
INIT_LIST_HEAD(&tsk->publications);
478484
INIT_LIST_HEAD(&tsk->cong_links);
479485
msg = &tsk->phdr;
@@ -541,7 +547,7 @@ static void __tipc_shutdown(struct socket *sock, int error)
541547
!tsk_conn_cong(tsk)));
542548

543549
/* Push out delayed messages if in Nagle mode */
544-
tipc_sk_push_backlog(tsk);
550+
tipc_sk_push_backlog(tsk, false);
545551
/* Remove pending SYN */
546552
__skb_queue_purge(&sk->sk_write_queue);
547553

@@ -1252,24 +1258,48 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq,
12521258
/* tipc_sk_push_backlog(): send accumulated buffers in socket write queue
12531259
* when socket is in Nagle mode
12541260
*/
1255-
static void tipc_sk_push_backlog(struct tipc_sock *tsk)
1261+
static void tipc_sk_push_backlog(struct tipc_sock *tsk, bool nagle_ack)
12561262
{
12571263
struct sk_buff_head *txq = &tsk->sk.sk_write_queue;
1264+
struct sk_buff *skb = skb_peek_tail(txq);
12581265
struct net *net = sock_net(&tsk->sk);
12591266
u32 dnode = tsk_peer_node(tsk);
1260-
struct sk_buff *skb = skb_peek(txq);
12611267
int rc;
12621268

1269+
if (nagle_ack) {
1270+
tsk->pkt_cnt += skb_queue_len(txq);
1271+
if (!tsk->pkt_cnt || tsk->msg_acc / tsk->pkt_cnt < 2) {
1272+
tsk->oneway = 0;
1273+
if (tsk->nagle_start < NAGLE_START_MAX)
1274+
tsk->nagle_start *= 2;
1275+
tsk->expect_ack = false;
1276+
pr_debug("tsk %10u: bad nagle %u -> %u, next start %u!\n",
1277+
tsk->portid, tsk->msg_acc, tsk->pkt_cnt,
1278+
tsk->nagle_start);
1279+
} else {
1280+
tsk->nagle_start = NAGLE_START_INIT;
1281+
if (skb) {
1282+
msg_set_ack_required(buf_msg(skb));
1283+
tsk->expect_ack = true;
1284+
} else {
1285+
tsk->expect_ack = false;
1286+
}
1287+
}
1288+
tsk->msg_acc = 0;
1289+
tsk->pkt_cnt = 0;
1290+
}
1291+
12631292
if (!skb || tsk->cong_link_cnt)
12641293
return;
12651294

12661295
/* Do not send SYN again after congestion */
12671296
if (msg_is_syn(buf_msg(skb)))
12681297
return;
12691298

1299+
if (tsk->msg_acc)
1300+
tsk->pkt_cnt += skb_queue_len(txq);
12701301
tsk->snt_unacked += tsk->snd_backlog;
12711302
tsk->snd_backlog = 0;
1272-
tsk->expect_ack = true;
12731303
rc = tipc_node_xmit(net, txq, dnode, tsk->portid);
12741304
if (rc == -ELINKCONG)
12751305
tsk->cong_link_cnt = 1;
@@ -1322,8 +1352,7 @@ static void tipc_sk_conn_proto_rcv(struct tipc_sock *tsk, struct sk_buff *skb,
13221352
return;
13231353
} else if (mtyp == CONN_ACK) {
13241354
was_cong = tsk_conn_cong(tsk);
1325-
tsk->expect_ack = false;
1326-
tipc_sk_push_backlog(tsk);
1355+
tipc_sk_push_backlog(tsk, msg_nagle_ack(hdr));
13271356
tsk->snt_unacked -= msg_conn_ack(hdr);
13281357
if (tsk->peer_caps & TIPC_BLOCK_FLOWCTL)
13291358
tsk->snd_win = msg_adv_win(hdr);
@@ -1516,6 +1545,7 @@ static int __tipc_sendstream(struct socket *sock, struct msghdr *m, size_t dlen)
15161545
struct tipc_sock *tsk = tipc_sk(sk);
15171546
struct tipc_msg *hdr = &tsk->phdr;
15181547
struct net *net = sock_net(sk);
1548+
struct sk_buff *skb;
15191549
u32 dnode = tsk_peer_node(tsk);
15201550
int maxnagle = tsk->maxnagle;
15211551
int maxpkt = tsk->max_pkt;
@@ -1544,17 +1574,25 @@ static int __tipc_sendstream(struct socket *sock, struct msghdr *m, size_t dlen)
15441574
break;
15451575
send = min_t(size_t, dlen - sent, TIPC_MAX_USER_MSG_SIZE);
15461576
blocks = tsk->snd_backlog;
1547-
if (tsk->oneway++ >= 4 && send <= maxnagle) {
1577+
if (tsk->oneway++ >= tsk->nagle_start && send <= maxnagle) {
15481578
rc = tipc_msg_append(hdr, m, send, maxnagle, txq);
15491579
if (unlikely(rc < 0))
15501580
break;
15511581
blocks += rc;
1582+
tsk->msg_acc++;
15521583
if (blocks <= 64 && tsk->expect_ack) {
15531584
tsk->snd_backlog = blocks;
15541585
sent += send;
15551586
break;
1587+
} else if (blocks > 64) {
1588+
tsk->pkt_cnt += skb_queue_len(txq);
1589+
} else {
1590+
skb = skb_peek_tail(txq);
1591+
msg_set_ack_required(buf_msg(skb));
1592+
tsk->expect_ack = true;
1593+
tsk->msg_acc = 0;
1594+
tsk->pkt_cnt = 0;
15561595
}
1557-
tsk->expect_ack = true;
15581596
} else {
15591597
rc = tipc_msg_build(hdr, m, sent, send, maxpkt, txq);
15601598
if (unlikely(rc != send))
@@ -2091,7 +2129,7 @@ static void tipc_sk_proto_rcv(struct sock *sk,
20912129
smp_wmb();
20922130
tsk->cong_link_cnt--;
20932131
wakeup = true;
2094-
tipc_sk_push_backlog(tsk);
2132+
tipc_sk_push_backlog(tsk, false);
20952133
break;
20962134
case GROUP_PROTOCOL:
20972135
tipc_group_proto_rcv(grp, &wakeup, hdr, inputq, xmitq);
@@ -2180,16 +2218,18 @@ static bool tipc_sk_filter_connect(struct tipc_sock *tsk, struct sk_buff *skb,
21802218
return false;
21812219
case TIPC_ESTABLISHED:
21822220
if (!skb_queue_empty(&sk->sk_write_queue))
2183-
tipc_sk_push_backlog(tsk);
2221+
tipc_sk_push_backlog(tsk, false);
21842222
/* Accept only connection-based messages sent by peer */
21852223
if (likely(con_msg && !err && pport == oport &&
21862224
pnode == onode)) {
21872225
if (msg_ack_required(hdr)) {
21882226
struct sk_buff *skb;
21892227

21902228
skb = tipc_sk_build_ack(tsk);
2191-
if (skb)
2229+
if (skb) {
2230+
msg_set_nagle_ack(buf_msg(skb));
21922231
__skb_queue_tail(xmitq, skb);
2232+
}
21932233
}
21942234
return true;
21952235
}

0 commit comments

Comments
 (0)