-
Notifications
You must be signed in to change notification settings - Fork 174
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
Conversation
There was a problem hiding this 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.
src/hotkey/counter_table.c
Outdated
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.
This comment was marked as spam.
Sorry, something went wrong.
src/hotkey/counter_table.c
Outdated
@@ -0,0 +1,242 @@ | |||
#include "counter_table.h" |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/hotkey/counter_table.c
Outdated
} | ||
|
||
uint32_t | ||
counter_table_incr(char *key, uint32_t nkey) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/hotkey/hotkey.h
Outdated
|
||
#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.
This comment was marked as spam.
Sorry, something went wrong.
src/hotkey/hotkey.h
Outdated
|
||
/* TODO(kevyang): add stats for hotkey module */ | ||
|
||
#define HOTKEY_NSAMPLE 10000 /* keep last 10000 keys sampled by default */ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/hotkey/hotkey.h
Outdated
|
||
#define hotkey_sample(key, nkey) do { \ | ||
if (hotkey_enabled) { \ | ||
_hotkey_sample(key, nkey); \ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/hotkey/queue.c
Outdated
@@ -0,0 +1,190 @@ | |||
#include "queue.h" |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/hotkey/queue.c
Outdated
static bool qnp_init = false; | ||
|
||
struct queue_node { | ||
char key[MAX_KEY_LEN]; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
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
src/hotkey/counter_table.c
Outdated
struct counter_table_entry *cte, *tcte; | ||
|
||
if (!ctep_init) { | ||
log_warn("counter_table_entry pool was not created, ignore"); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing return;
?
src/hotkey/queue.c
Outdated
struct queue_node *qn, *tqn; | ||
|
||
if (!qnp_init) { | ||
log_warn("queue_node pool was not created, ignore"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once again
src/hotkey/queue.c
Outdated
log_info("tear down the %s module", QUEUE_MODULE_NAME); | ||
|
||
if (!queue_init) { | ||
log_warn("%s was not setup", QUEUE_MODULE_NAME); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/hotkey/queue.c
Outdated
queue_pop(char *buf) | ||
{ | ||
struct queue_node *qn = STAILQ_FIRST(&q); | ||
uint32_t nkey; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ASSERT(queue_size);
?
test/hotkey/queue/check_queue.c
Outdated
START_TEST(test_multiple) | ||
{ | ||
char *key1 = "key1", *key2 = "key22", *key3 = "key333"; | ||
uint32_t klen1 = 4, klen2 = 5, klen3 = 6; |
There was a problem hiding this comment.
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.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
START_TEST(test_multiple) | ||
{ | ||
char *key1str = "key1", *key2str = "key22", *key3str = "key333"; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
…ing/detection