Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data structures, interface, and basic unit tests for hotkey sampl… #123

Merged
merged 3 commits into from
Feb 23, 2017

Conversation

kevyang
Copy link
Contributor

@kevyang kevyang commented Jan 21, 2017

…ing/detection

Copy link
Contributor

@thinkingfish thinkingfish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed the data structure not the tests.

STAILQ_ENTRY(counter_table_entry) next; /* entry in hash table or pool */

char key[MAX_KEY_LEN];
uint32_t nkey;

This comment was marked as spam.

@@ -0,0 +1,242 @@
#include "counter_table.h"

This comment was marked as spam.

}

uint32_t
counter_table_incr(char *key, uint32_t nkey)

This comment was marked as spam.


#define HOTKEY_NSAMPLE 10000 /* keep last 10000 keys sampled by default */
#define HOTKEY_RATE 100 /* sample one in every 100 keys by default */
#define HOTKEY_THRESHOLD 10 /* signal for hotkey if 10 or more keys in sample by default */

This comment was marked as spam.


/* TODO(kevyang): add stats for hotkey module */

#define HOTKEY_NSAMPLE 10000 /* keep last 10000 keys sampled by default */

This comment was marked as spam.


#define hotkey_sample(key, nkey) do { \
if (hotkey_enabled) { \
_hotkey_sample(key, nkey); \

This comment was marked as spam.

@@ -0,0 +1,190 @@
#include "queue.h"

This comment was marked as spam.

static bool qnp_init = false;

struct queue_node {
char key[MAX_KEY_LEN];

This comment was marked as spam.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do this in a separate pull request. This is a larger change than it seems, as in order to do this we need to make the queue aware of the counting map

struct counter_table_entry *cte, *tcte;

if (!ctep_init) {
log_warn("counter_table_entry pool was not created, ignore");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a return;?

log_info("Tear down the %s module", HOTKEY_MODULE_NAME);

if (!hotkey_init) {
log_warn("%s was not setup", HOTKEY_MODULE_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing return;?

struct queue_node *qn, *tqn;

if (!qnp_init) {
log_warn("queue_node pool was not created, ignore");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once again

log_info("tear down the %s module", QUEUE_MODULE_NAME);

if (!queue_init) {
log_warn("%s was not setup", QUEUE_MODULE_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

START_TEST(test_basic)
{
char *key1 = "key1", *key2 = "key2";
uint32_t klen = 4;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use two keys with different length. Also, since the char* is actually 5 bytes as it has a NULL termination, use 5 instead of 4 in this case, as it may help catch off-by-one errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the sizes the length of the strings without null termination, because we don't use null terminated keys in cache.

queue_pop(char *buf)
{
struct queue_node *qn = STAILQ_FIRST(&q);
uint32_t nkey;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASSERT(queue_size);?

START_TEST(test_multiple)
{
char *key1 = "key1", *key2 = "key22", *key3 = "key333";
uint32_t klen1 = 4, klen2 = 5, klen3 = 6;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5, 6 and 7?

#include <stdint.h>

/*
* The key_window module provides a FIFO key_window interface to help with bookkeeping the

This comment was marked as spam.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the benefits of using ring_array do not significantly outweigh the drawbacks. Although it would provide a clean push/pop, using STAILQ is also a one liner in this aspect and is not significantly harder to understand. ring_array also lacks a foreach equivalent, which means we would need to write a messier loop for freeing the contents. Additionally, using ring_array still does not remove the need to check whether the the window is full. Furthermore, if we are to port this hotkey change to twemcache, twemcache already has mc_queue so it would be mostly read to go; however, were we to switch to ring_array we would need to port ring_array over to twemcache as well. For these reasons, I think we should keep it as it is for now.

This comment was marked as spam.

This comment was marked as spam.


START_TEST(test_multiple)
{
char *key1str = "key1", *key2str = "key22", *key3str = "key333";

This comment was marked as spam.

@kevyang kevyang merged commit 0d32128 into twitter:master Feb 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants