From: Suanming Mou <suanmingm@nvidia.com>
To: Leyi Rong <leyi.rong@intel.com>,
"yipeng1.wang@intel.com" <yipeng1.wang@intel.com>,
"zaoxingliu@gmail.com" <zaoxingliu@gmail.com>,
"sameh.gobriel@intel.com" <sameh.gobriel@intel.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: RE: [PATCH 2/2] test/member: add functional and perf tests for sketch
Date: Thu, 11 Aug 2022 02:33:23 +0000 [thread overview]
Message-ID: <CO6PR12MB5396036E67F845CF7C7E8DB6C1649@CO6PR12MB5396.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20220810074518.1695013-3-leyi.rong@intel.com>
Hi,
> -----Original Message-----
> From: Leyi Rong <leyi.rong@intel.com>
> Sent: Wednesday, August 10, 2022 3:45 PM
> To: yipeng1.wang@intel.com; zaoxingliu@gmail.com; sameh.gobriel@intel.com
> Cc: dev@dpdk.org; Leyi Rong <leyi.rong@intel.com>
> Subject: [PATCH 2/2] test/member: add functional and perf tests for sketch
>
> This patch adds functional and performance tests for sketch mode of
> membership library.
>
> Signed-off-by: Yipeng Wang <yipeng1.wang@intel.com>
> Signed-off-by: Leyi Rong <leyi.rong@intel.com>
> ---
> app/test/test_member.c | 258 ++++++++++++++++++++++++++++++++++++
> app/test/test_member_perf.c | 153 ++++++++++++++++++++-
> 2 files changed, 407 insertions(+), 4 deletions(-)
>
> diff --git a/app/test/test_member.c b/app/test/test_member.c index
> 26a712439f..abe59bb9f8 100644
> --- a/app/test/test_member.c
> +++ b/app/test/test_member.c
> @@ -4,6 +4,7 @@
>
> /* This test is for membership library's simple feature test */
>
> +#include <math.h>
> #include "test.h"
>
> #include <rte_memcpy.h>
> @@ -28,6 +29,7 @@ test_member(void)
> struct rte_member_setsum *setsum_ht;
> struct rte_member_setsum *setsum_cache; struct rte_member_setsum
> *setsum_vbf;
> +struct rte_member_setsum *setsum_sketch;
>
> /* 5-tuple key type */
> struct flow_key {
> @@ -108,6 +110,21 @@ static struct rte_member_parameters params = {
> .socket_id = 0 /* NUMA Socket ID for
> memory. */
> };
>
> +/* for sketch definitions */
> +#define TOP_K 10
> +#define HH_PKT_SIZE 16
> +#define SKETCH_ERROR_RATE 0.05
> +#define SKETCH_SAMPLE_RATE 0.001
> +#define PRINT_OUT_COUNT 20
> +
> +#define SKETCH_LARGEST_KEY_SIZE 1000000 #define SKETCH_TOTAL_KEY 500
> +#define NUM_OF_KEY(key) {\
> + (unsigned int)ceil(SKETCH_LARGEST_KEY_SIZE / (key + 1)) \ }
> +
> +void *heavy_hitters[TOP_K];
> +
> /*
> * Sequence of operations for find existing setsummary
> *
> @@ -684,6 +701,243 @@ perform_free(void)
> rte_member_free(setsum_vbf);
> }
>
> +static void
> +print_out_sketch_results(uint64_t *count_result, member_set_t *heavy_set,
> + uint32_t print_num, bool count_byte) {
> + uint32_t i;
> +
> + for (i = 0; i < print_num; i++) {
> + if (count_byte)
> + printf("key %2u, count %8lu, real count %8u, "
> + "heavy_set %u, deviation rate [%.04f]\n",
> + i, count_result[i],
> + (unsigned int)ceil(SKETCH_LARGEST_KEY_SIZE /
> (i + 1)) *
> + HH_PKT_SIZE,
> + heavy_set[i],
> + fabs((float)count_result[i] -
> (float)NUM_OF_KEY(i) * HH_PKT_SIZE) /
> + ((float)NUM_OF_KEY(i) * HH_PKT_SIZE));
> + else
> + printf("key %2u, count %8lu, real count %8u, "
> + "heavy_set %u, deviation rate [%.04f]\n",
> + i, count_result[i],
> + (unsigned int)ceil(SKETCH_LARGEST_KEY_SIZE /
> (i + 1)),
> + heavy_set[i],
> + fabs((float)count_result[i] -
> (float)NUM_OF_KEY(i)) /
> + (float)NUM_OF_KEY(i));
> + }
> +}
> +
> +static int
> +sketch_test(uint32_t *keys, uint32_t total_pkt, int count_byte, int
> +reset_test) {
> + uint32_t i;
> + uint64_t result_count[SKETCH_TOTAL_KEY];
> + member_set_t heavy_set[SKETCH_TOTAL_KEY];
> + uint64_t count[TOP_K];
> + int ret;
> + int hh_cnt;
> +
> + setsum_sketch = rte_member_create(¶ms);
> + if (setsum_sketch == NULL) {
> + printf("Creation of setsums fail\n");
> + return -1;
> + }
> +
> + for (i = 0; i < total_pkt; i++) {
> + if (count_byte)
> + ret = rte_member_add_byte_count(setsum_sketch,
> &keys[i], HH_PKT_SIZE);
> + else
> + ret = rte_member_add(setsum_sketch, &keys[i], 1);
> +
> + if (ret < 0) {
> + printf("rte_member_add Failed! Error [%d]\n", ret);
I'm afraid rte_member_free(setsum_sketch) is missing here.
Same code below with "return -1;" should be checked.
> +
> + return -1;
> + }
> + }
> +
> + for (i = 0; i < SKETCH_TOTAL_KEY; i++) {
> + uint32_t tmp_key = i;
> +
> + rte_member_query_count(setsum_sketch, (void *)&tmp_key,
> &result_count[i]);
> + rte_member_lookup(setsum_sketch, (void *)&tmp_key,
> &heavy_set[i]);
> + }
> +
> + print_out_sketch_results(result_count, heavy_set, PRINT_OUT_COUNT,
> +count_byte);
> +
> + hh_cnt = rte_member_report_heavyhitter(setsum_sketch, heavy_hitters,
> count);
> + if (hh_cnt < 0) {
> + printf("sketch report heavy hitter error!");
> +
> + return -1;
> + }
> +
> + printf("Report heavy hitters:");
> + for (i = 0; i < (unsigned int)hh_cnt; i++) {
> + printf("%u: %lu\t",
> + *((uint32_t *)heavy_hitters[i]), count[i]);
> + }
> + printf("\n");
> +
> + if (reset_test) {
> + printf("\nEntering Sketch Reset Test Process!\n");
> + rte_member_reset(setsum_sketch);
> +
> + /* after reset, check some key's count */
> + for (i = 0; i < SKETCH_TOTAL_KEY; i++) {
> + uint32_t tmp_key = i;
> +
> + rte_member_query_count(setsum_sketch, (void
> *)&tmp_key, &result_count[i]);
> + rte_member_lookup(setsum_sketch, (void *)&tmp_key,
> &heavy_set[i]);
> + }
> +
> + print_out_sketch_results(result_count, heavy_set,
> PRINT_OUT_COUNT,
> +count_byte);
> +
> + printf("\nReinsert keys after Sketch Reset!\n");
> + for (i = 0; i < total_pkt; i++) {
> + if (count_byte)
> + ret = rte_member_add_byte_count
> + (setsum_sketch, &keys[i],
> HH_PKT_SIZE);
> + else
> + ret = rte_member_add(setsum_sketch, &keys[i],
> 1);
> +
> + if (ret < 0) {
> + printf("rte_member_add Failed! Error [%d]\n",
> ret);
> +
> + return -1;
> + }
> + }
> +
> + for (i = 0; i < SKETCH_TOTAL_KEY; i++) {
> + uint32_t tmp_key = i;
> +
> + rte_member_query_count(setsum_sketch, (void
> *)&tmp_key, &result_count[i]);
> + rte_member_lookup(setsum_sketch, (void *)&tmp_key,
> &heavy_set[i]);
> + }
> +
> + print_out_sketch_results(result_count, heavy_set,
> PRINT_OUT_COUNT,
> +count_byte);
> +
> + hh_cnt = rte_member_report_heavyhitter(setsum_sketch,
> heavy_hitters, count);
> + if (hh_cnt < 0) {
> + printf("sketch report heavy hitter error!");
> +
> + return -1;
> + }
> + printf("Report heavy hitters:");
> + for (i = 0; i < (unsigned int)hh_cnt; i++) {
> + printf("%u: %lu\t",
> + *((uint32_t *)heavy_hitters[i]), count[i]);
> + }
> + printf("\n");
> +
> + printf("\nDelete some keys!\n");
> + uint32_t tmp_key = 0;
> +
> + rte_member_delete(setsum_sketch, (void *)&tmp_key, 0);
> + tmp_key = 1;
> + rte_member_delete(setsum_sketch, (void *)&tmp_key, 0);
> +
> + for (i = 0; i < SKETCH_TOTAL_KEY; i++) {
> + uint32_t tmp_key = i;
> +
> + rte_member_query_count(setsum_sketch, (void
> *)&tmp_key, &result_count[i]);
> + rte_member_lookup(setsum_sketch, (void *)&tmp_key,
> &heavy_set[i]);
> + }
> +
> + print_out_sketch_results(result_count, heavy_set,
> PRINT_OUT_COUNT,
> +count_byte);
> +
> + hh_cnt = rte_member_report_heavyhitter(setsum_sketch,
> heavy_hitters, count);
> + if (hh_cnt < 0) {
> + printf("sketch report heavy hitter error!");
> +
> + return -1;
> + }
> + printf("Report heavy hitters:");
> + for (i = 0; i < (unsigned int)hh_cnt; i++) {
> + printf("%u: %lu\t",
> + *((uint32_t *)heavy_hitters[i]), count[i]);
> + }
> + printf("\n");
> + }
> +
> + rte_member_free(setsum_sketch);
> + return 0;
> +}
> +
> +static int
> +test_member_sketch(void)
> +{
> + unsigned int i, j, index;
> + uint32_t total_pkt = 0;
> + uint32_t *keys;
> + int count_byte = 0;
> +
> + for (i = 0; i < SKETCH_TOTAL_KEY; i++)
> + total_pkt += ceil(SKETCH_LARGEST_KEY_SIZE / (i + 1));
> +
> + printf("\nTotal key count [%u] in Sketch Autotest\n", total_pkt);
> +
> + keys = rte_zmalloc(NULL, sizeof(uint32_t) * total_pkt, 0);
> +
> + if (keys == NULL) {
> + printf("RTE_ZMALLOC failed\n");
> + return -1;
> + }
> +
> + index = 0;
> + for (i = 0; i < SKETCH_TOTAL_KEY; i++) {
> + for (j = 0; j < ceil(SKETCH_LARGEST_KEY_SIZE / (i + 1)); j++)
> + keys[index++] = i;
> + }
> +
> + /* shuffle the keys */
> + for (i = index - 1; i > 0; i--) {
> + uint32_t swap_idx = rte_rand() % i;
> + uint32_t tmp_key = keys[i];
> +
> + keys[i] = keys[swap_idx];
> + keys[swap_idx] = tmp_key;
> + }
> +
> + params.key_len = 4;
> + params.name = "test_member_sketch";
> + params.type = RTE_MEMBER_TYPE_SKETCH;
> + params.error_rate = SKETCH_ERROR_RATE;
> + params.sample_rate = SKETCH_SAMPLE_RATE;
> + params.extra_flag = 0;
> + params.top_k = TOP_K;
> + params.prim_hash_seed = rte_rdtsc();
> + int reset_test = 0;
> +
> + printf("Default sketching params: Error Rate: [%f]\tSample Rate:
> [%f]\tTopK: [%d]\n",
> + SKETCH_ERROR_RATE, SKETCH_SAMPLE_RATE, TOP_K);
> +
> + printf("\n[Sketch with Fixed Sampling Rate Mode]\n");
> + if (sketch_test(keys, total_pkt, count_byte, reset_test) < 0)
Same here, will keys memory allocated by rte_zmalloc be freed in other place?
> + return -1;
> +
> + params.extra_flag |= RTE_MEMBER_SKETCH_ALWAYS_BOUNDED;
> + printf("\n[Sketch with Always Bounded Mode]\n");
> + if (sketch_test(keys, total_pkt, count_byte, reset_test) < 0)
> + return -1;
> +
> + count_byte = 1;
> + params.extra_flag |= RTE_MEMBER_SKETCH_COUNT_BYTE;
> + printf("\n[Sketch with Packet Size Mode]\n");
> + if (sketch_test(keys, total_pkt, count_byte, reset_test) < 0)
> + return -1;
> +
> + count_byte = 0;
> + params.extra_flag = 0;
snip
next prev parent reply other threads:[~2022-08-11 2:33 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-10 7:45 [PATCH 0/2] introduce NitroSketch Mode into membership library Leyi Rong
2022-08-10 7:45 ` [PATCH 1/2] member: implement NitroSketch mode Leyi Rong
2022-08-16 8:59 ` Ferruh Yigit
2022-08-26 2:32 ` Rong, Leyi
2022-08-10 7:45 ` [PATCH 2/2] test/member: add functional and perf tests for sketch Leyi Rong
2022-08-11 2:33 ` Suanming Mou [this message]
2022-08-26 2:26 ` Rong, Leyi
2022-08-31 6:46 ` [PATCH v2 0/2] introduce NitroSketch Mode into membership library Leyi Rong
2022-08-31 6:46 ` [PATCH v2 1/2] member: implement NitroSketch mode Leyi Rong
2022-09-13 14:56 ` David Marchand
2022-09-14 9:42 ` Rong, Leyi
2022-08-31 6:46 ` [PATCH v2 2/2] test/member: add functional and perf tests for sketch Leyi Rong
2022-09-15 2:14 ` [PATCH v3 0/2] introduce NitroSketch Mode into membership library Leyi Rong
2022-09-15 2:14 ` [PATCH v3 1/2] member: implement NitroSketch mode Leyi Rong
2022-09-15 7:47 ` David Marchand
2022-09-15 13:02 ` Rong, Leyi
2022-09-15 2:14 ` [PATCH v3 2/2] test/member: add functional and perf tests for sketch Leyi Rong
2022-09-15 7:30 ` Jiang, YuX
2022-09-15 7:41 ` David Marchand
2022-09-15 13:03 ` [PATCH v4 0/2] introduce NitroSketch Mode into membership library Leyi Rong
2022-09-15 13:03 ` [PATCH v4 1/2] member: implement NitroSketch mode Leyi Rong
2022-09-15 14:12 ` Bruce Richardson
2022-09-16 2:30 ` Rong, Leyi
2022-09-15 13:03 ` [PATCH v4 2/2] test/member: add functional and perf tests for sketch Leyi Rong
2022-09-16 3:03 ` [PATCH v5 0/2] introduce NitroSketch Mode into membership library Leyi Rong
2022-09-16 3:03 ` [PATCH v5 1/2] member: implement NitroSketch mode Leyi Rong
2022-09-22 3:00 ` Jiang, YuX
2022-10-03 12:37 ` Thomas Monjalon
2022-10-08 3:36 ` Rong, Leyi
2022-09-16 3:03 ` [PATCH v5 2/2] test/member: add functional and perf tests for sketch Leyi Rong
2022-10-09 23:13 ` [PATCH v5 0/2] introduce NitroSketch Mode into membership library Thomas Monjalon
2022-10-10 2:36 ` Rong, Leyi
2022-10-10 7:30 ` Thomas Monjalon
2022-10-10 8:28 ` Rong, Leyi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CO6PR12MB5396036E67F845CF7C7E8DB6C1649@CO6PR12MB5396.namprd12.prod.outlook.com \
--to=suanmingm@nvidia.com \
--cc=dev@dpdk.org \
--cc=leyi.rong@intel.com \
--cc=sameh.gobriel@intel.com \
--cc=yipeng1.wang@intel.com \
--cc=zaoxingliu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).