* Oddness with reading /proc/net/tcp
@ 2007-04-13 16:46 Witold Krecicki
2007-04-13 17:40 ` Eric Dumazet
0 siblings, 1 reply; 2+ messages in thread
From: Witold Krecicki @ 2007-04-13 16:46 UTC (permalink / raw)
To: linux-kernel
Reading data from /proc/net/tcp is slower with progress of reading data,
tested on system with >200k active connections.
Sample code:
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
int main(int argc, char ** argv)
{
struct timeval starttime, endtime;
FILE * fd;
char buf[1024*1024*4];
int pk;
fd=fopen("/proc/net/tcp","r");
gettimeofday(&starttime,0);
pk=0;
while (!feof(fd) && pk<10000)
{
fread(buf, 1, 1024, fd);
pk++;
if (pk%512==0)
{
gettimeofday(&endtime,0);
printf("%d %ld\n",pk, (endtime.tv_usec-starttime.tv_usec)
+1000000*(endtime.tv_sec - starttime.tv_sec));
gettimeofday(&starttime,0);
}
}
fclose(fd);
return 0;
}
Result:
$ time ./a.out
512 231781
1024 1057159
1536 1726530
2048 2474851
2560 3236269
3072 3856587
3584 3438862
4096 3108675
4608 3500559
5120 4090534
5632 4612594
6144 5135624
6656 5266945
7168 5491547
7680 6355916
8192 6661789
8704 7095428
9216 7565589
9728 7982981
real 1m27.347s
user 0m0.024s
sys 1m27.309s
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Oddness with reading /proc/net/tcp
2007-04-13 16:46 Oddness with reading /proc/net/tcp Witold Krecicki
@ 2007-04-13 17:40 ` Eric Dumazet
0 siblings, 0 replies; 2+ messages in thread
From: Eric Dumazet @ 2007-04-13 17:40 UTC (permalink / raw)
To: Witold Krecicki; +Cc: linux-kernel
Witold Krecicki a écrit :
> Reading data from /proc/net/tcp is slower with progress of reading data,
> tested on system with >200k active connections.
>
Yes, this is a known problem.
This is O(N^2) algo.
Use ss from iproute package to get better performance... (less than 15 seconds
for 200k active connections)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-04-13 17:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-13 16:46 Oddness with reading /proc/net/tcp Witold Krecicki
2007-04-13 17:40 ` Eric Dumazet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox