Re: reduce the number of missed PCB cache with tcpbench -su

2014-09-01 Thread Mike Belopuhov
On 29 August 2014 18:01, Damien Miller  wrote:
> What's the benefit of this?

This creates a UDP PCB per connection.  Otherwise we always rely on
matching the wildcard PCB.

> I've never seen an application do this;

I doubt that.  However, things like NTP or DNS servers usually expect
requests from everyone so they don't do it.  Now I have actually
identified one use case that this diff breaks: multiple senders won't
work.  Which is kind of annoying.

> wouldn't it be better to improve the PCB cache so it caught this case
> (which seems the usual way UDP applications behave) instead?
>

Definitely!  Using something like a prefix tree (mickey advocates hash
array mapped tries) would eliminate this second lookup and also solve
problems with attacking PCB hash with collisions and resizing the hash
table.

> -d
>



Re: reduce the number of missed PCB cache with tcpbench -su

2014-08-31 Thread Mike Belopuhov
Daniel,  don't reply anything to Damien just yet.  Can you please run
a simple test on Monday.  Try "tcpbench -u -n 2 " (as in multi-
connection test) without your patch and then with the patch and see
if behavior is changed.

Thanks

On 29 August 2014 18:01, Damien Miller  wrote:
> On Fri, 29 Aug 2014, Daniel Jakots wrote:
>
>> Hi,
>>
>> When running tcpbench -su, a lot of them are counted as "missed PCB
>> cache".
> ...
>> + n = recvfrom(fd, ptb->dummybuf, ptb->dummybuf_len, 0,
>> + (struct sockaddr *)&ss, &slen);
>> + if (n > 0 && connect(fd, (const struct sockaddr *)&ss, slen))
>> + warn("fail to connect");
>
> What's the benefit of this? I've never seen an application do this;
> wouldn't it be better to improve the PCB cache so it caught this case
> (which seems the usual way UDP applications behave) instead?
>
> -d
>



Re: reduce the number of missed PCB cache with tcpbench -su

2014-08-29 Thread Damien Miller
On Fri, 29 Aug 2014, Daniel Jakots wrote:

> Hi,
> 
> When running tcpbench -su, a lot of them are counted as "missed PCB
> cache".
...
> + n = recvfrom(fd, ptb->dummybuf, ptb->dummybuf_len, 0,
> + (struct sockaddr *)&ss, &slen);
> + if (n > 0 && connect(fd, (const struct sockaddr *)&ss, slen))
> + warn("fail to connect");

What's the benefit of this? I've never seen an application do this;
wouldn't it be better to improve the PCB cache so it caught this case
(which seems the usual way UDP applications behave) instead?

-d



reduce the number of missed PCB cache with tcpbench -su

2014-08-29 Thread Daniel Jakots
Hi,

When running tcpbench -su, a lot of them are counted as "missed PCB
cache".

I reboot the computer then netstat -sp udp gives

udp:
10 datagrams received
0 with incomplete header
0 with bad data length field
0 with bad checksum
0 with no checksum
0 input packets software-checksummed
0 output packets software-checksummed
0 dropped due to no socket
0 broadcast/multicast datagrams dropped due to no socket
0 dropped due to missing IPsec protection
0 dropped due to full socket buffers
10 delivered
14 datagrams output
0 missed PCB cache

I run tcpbench -su and use a client and I netstat -sp udp again :

udp:
1086364 datagrams received
0 with incomplete header
0 with bad data length field
0 with bad checksum
0 with no checksum
0 input packets software-checksummed
0 output packets software-checksummed
0 dropped due to no socket
3 broadcast/multicast datagrams dropped due to no socket
0 dropped due to missing IPsec protection
1201 dropped due to full socket buffers
1085160 delivered
14 datagrams output
1086351 missed PCB cache

After the bind(2), a PCB is created with a wildcard source address which
is not a direct match for incoming packets which means that we need to
perform a second lookup to find the "listener PCB". And the connect(2)
creates a new PCB for this connection thus avoiding a second lookup.

Patch with (a lot of) help from mikeb@

Reboot the laptop and run the test again:

udp:
1074985 datagrams received
0 with incomplete header
0 with bad data length field
0 with bad checksum
0 with no checksum
0 input packets software-checksummed
0 output packets software-checksummed
0 dropped due to no socket
1 broadcast/multicast datagram dropped due to no socket
0 dropped due to missing IPsec protection
1295 dropped due to full socket buffers
1073689 delivered
14 datagrams output
6 missed PCB cache

Index: tcpbench.c
===
RCS file: /cvs/src/usr.bin/tcpbench/tcpbench.c,v
retrieving revision 1.42
diff -u -p -r1.42 tcpbench.c
--- tcpbench.c  19 Aug 2014 03:28:53 -  1.42
+++ tcpbench.c  29 Aug 2014 14:22:35 -
@@ -610,8 +610,17 @@ udp_server_handle_sc(int fd, short event
 {
ssize_t n;
struct statctx *sc = v_sc;
+   struct sockaddr_storage ss;
+   socklen_t slen;
 
-   n = read(fd, ptb->dummybuf, ptb->dummybuf_len);
+   /* If this was our first packet, perform a connect */
+   if (mainstats.peak_mbps == 0) {
+   n = recvfrom(fd, ptb->dummybuf, ptb->dummybuf_len, 0,
+   (struct sockaddr *)&ss, &slen);
+   if (n > 0 && connect(fd, (const struct sockaddr *)&ss, slen))
+   warn("fail to connect");
+   } else
+   n = read(fd, ptb->dummybuf, ptb->dummybuf_len);
if (n == 0)
return;
else if (n == -1) {