nfnl_ct_alloc_cache() high CPU usage, while no CPU usage in just fetching messages from kernel.

Марк Коренберг socketpair at gmail.com
Thu Jul 14 16:00:23 PDT 2016


nfnl_ct_alloc_cache() works, but 0.9 seconds for 3500 connections.

nfnl_ct_dump_request() +
nl_recvmsgs_default(callback=nfnlmsg_ct_parse()) return same result,
but significantly faster: about 0.014 seconds.

What's wrong ? Why so slow ? about 100 times slower. Seems speed of
adding to the cache is reduced exponentially with growing conntrack
list. If yes, it is not so good cache.

Everything is run under Centos6 32bit X86, libnl3 3.2.21 (but patched
for the bug https://github.com/thom311/libnl/commit/87bbfb6b12322d79abc979d6a001c18eb875ae45
)

VERY SLOW VERSION:
============
#include <netlink/netlink.h>
#include <netlink/netfilter/nfnl.h>
#include <netlink/netfilter/ct.h>

int main (void)
{
  struct nl_sock *sock = nl_socket_alloc ();
  if (sock == NULL)
    return 1;
  if (nfnl_connect (sock) < 0)
    return 1;
  if (nl_socket_set_buffer_size (sock, 10 * 1024 * 1024, 10 * 1024 *
1024) <      0)
    return 1;

  struct nl_cache* cache;
  if (nfnl_ct_alloc_cache(sock, &cache)<0)
    return 1;
 return 0;
}
============

FAST VERSION:
============
#include <netlink/netlink.h>
#include <netlink/msg.h>
#include <netlink/netfilter/nfnl.h>
#include <netlink/netfilter/ct.h>

static int callback (struct nl_msg *msg, void *arg)
{
  struct nfnl_ct *ct;
  if (nfnlmsg_ct_parse (nlmsg_hdr (msg), &ct) < 0)
    return -42;
  nfnl_ct_put (ct);
  printf ("ct\n");
return 0;
}

int main (void)
{
  struct nl_sock *sock = nl_socket_alloc ();
  if (sock == NULL)
    return 1;
  if (nfnl_connect (sock) < 0)
    return 1;
  if (nl_socket_set_buffer_size (sock, 10 * 1024 * 1024, 10 * 1024 * 1024) < 0)
    return 1;
  if (nfnl_ct_dump_request (sock) < 0)
    return 1;
  if (nl_socket_modify_cb (sock, NL_CB_VALID, NL_CB_CUSTOM, callback, NULL) < 0)
    return 1;
  if (nl_recvmsgs_default (sock) < 0)
    return 1;
  return 0;
}
============




-- 
Segmentation fault



More information about the libnl mailing list