@cryptotaxi247 / netdata-1 / commits / e15a5a565

registry update for counters

Costa Tsaousis committed May 8, 2016 at 03:53 UTC e15a5a565bf78ea13aa1c4fda19403bacdcdca36
1 file changed +66 -33
src/registry.c
+66 -33
@@ -25,6 +25,9 @@ struct registry {
25 unsigned long long persons_count;
26 unsigned long long machines_count;
27 unsigned long long usages_count;
28 + unsigned long long urls_count;
29 + unsigned long long persons_urls_count;
30 + unsigned long long machines_urls_count;
31
32 DICTIONARY *persons; // dictionary of PERSON *, with key the PERSON.guid
33 DICTIONARY *machines; // dictionary of MACHINE *, with key the MACHINE.guid
@@ -119,6 +122,8 @@ static inline URL *registry_url_get(const char *url) {
122
123 debug(D_DICTIONARY, "Registry: registry_url_get('%s'): indexing it", url);
124 dictionary_set(registry.urls, url, u, sizeof(URL) + len + 1);
125 +
126 + registry.urls_count++;
127 }
128
129 return u;
@@ -236,7 +241,10 @@ MACHINE *registry_machine_get(const char *machine_guid) {
241
242 machine_guid = buf;
243 m = registry_machine_find(machine_guid);
239 - if(!m) m = registry_machine_allocate(machine_guid);
244 + if(!m) {
245 + m = registry_machine_allocate(machine_guid);
246 + registry.machines_count++;
247 + }
248 }
249 }
250
@@ -366,7 +374,10 @@ PERSON *registry_person_get(const char *person_guid) {
374 }
375 }
376
369 - if(!p) p = registry_person_allocate(NULL);
377 + if(!p) {
378 + p = registry_person_allocate(NULL);
379 + registry.persons_count++;
380 + }
381
382 return p;
383 }
@@ -391,6 +402,7 @@ PERSON_URL *registry_person_link_to_url(PERSON *p, MACHINE *m, URL *u) {
402 debug(D_REGISTRY, "registry_person_link_to_url('%s', '%s', '%s'): indexing URL in person", p->guid, m->guid, u->url);
403 dictionary_set(p->urls, u->url, pu, sizeof(PERSON_URL));
404 registry_url_link(u);
405 + registry.persons_urls_count++;
406 }
407 else {
408 debug(D_REGISTRY, "registry_person_link_to_url('%s', '%s', '%s'): found", p->guid, m->guid, u->url);
@@ -432,6 +444,7 @@ MACHINE_URL *registry_machine_link_to_url(PERSON *p, MACHINE *m, URL *u) {
444 debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s', '%s'): indexing URL in machine", p->guid, m->guid, u->url);
445 dictionary_set(m->urls, u->url, mu, sizeof(MACHINE_URL));
446 registry_url_link(u);
447 + registry.machines_urls_count++;
448 }
449 else {
450 debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s', '%s'): found", p->guid, m->guid, u->url);
@@ -472,6 +485,8 @@ PERSON *registry_request(const char *person_guid, const char *machine_guid, cons
485 debug(D_REGISTRY, "Registry: registry_request('%s', '%s', '%s'): saving", person_guid, machine_guid, url);
486 registry_person_save(p);
487 registry_machine_save(m);
488 +
489 + registry.usages_count++;
490 registry_save();
491
492 return p;
@@ -481,6 +496,13 @@ PERSON *registry_request(const char *person_guid, const char *machine_guid, cons
496 // REGISTRY
497
498 void registry_init(void) {
499 + registry.persons_count = 0;
500 + registry.machines_count = 0;
501 + registry.usages_count = 0;
502 + registry.urls_count = 0;
503 + registry.persons_urls_count = 0;
504 + registry.machines_urls_count = 0;
505 +
506 debug(D_REGISTRY, "Registry: creating global registry dictionary for persons.");
507 registry.persons = dictionary_create(DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE|DICTIONARY_FLAG_NAME_LINK_DONT_CLONE|DICTIONARY_FLAG_SINGLE_THREADED);
508
@@ -574,17 +596,27 @@ void registry_free(void) {
596 }
597
598 int test1(int argc, char **argv) {
599 +
600 + void print_stats(uint32_t requests, unsigned long long start, unsigned long long end) {
601 + fprintf(stderr, " > SPEED: %u requests served in %0.2f seconds ( >>> %llu per second <<< )\n",
602 + requests, (end-start) / 1000000.0, (unsigned long long)requests * 1000000ULL / (end-start));
603 +
604 + fprintf(stderr, " > DB : persons %llu, machines %llu, unique URLs %llu, accesses %llu, URLs: for persons %llu, for machines %llu\n",
605 + registry.persons_count, registry.machines_count, registry.urls_count, registry.usages_count,
606 + registry.persons_urls_count, registry.machines_urls_count);
607 + }
608 +
609 (void) argc;
610 (void) argv;
611
580 - uint32_t u, users = 1000000;
612 + uint32_t u, users = 500000;
613 uint32_t m, machines = 50000;
614 uint32_t machines2 = machines * 2;
615
616 char **users_guids = malloc(users * sizeof(char *));
617 char **machines_guids = malloc(machines2 * sizeof(char *));
618 char **machines_urls = malloc(machines2 * sizeof(char *));
587 - unsigned long long start, end;
619 + unsigned long long start;
620
621 registry_init();
622
@@ -611,8 +643,7 @@ int test1(int argc, char **argv) {
643 PERSON *p = registry_request(NULL, machines_guids[m], machines_urls[m]);
644 users_guids[u] = p->guid;
645 }
614 - end = timems();
615 - fprintf(stderr, "%u accesses served in %0.2f seconds (%llu per second)\n", u, (end-start) / 1000000.0, (unsigned long long)u * 1000000ULL / (end-start));
646 + print_stats(u, start, timems());
647
648 start = timems();
649 fprintf(stderr, "\nAll %u users accessing again the same %u servers\n", users, machines);
@@ -625,8 +656,7 @@ int test1(int argc, char **argv) {
656 if(p->guid != users_guids[u])
657 fprintf(stderr, "ERROR: expected to get user guid '%s' but git '%s'", users_guids[u], p->guid);
658 }
628 - end = timems();
629 - fprintf(stderr, "%u accesses served in %0.2f seconds (%llu per second)\n", u, (end-start) / 1000000.0, (unsigned long long)u * 1000000ULL / (end-start));
659 + print_stats(u, start, timems());
660
661 start = timems();
662 fprintf(stderr, "\nAll %u users accessing a new server, out of the %u servers\n", users, machines);
@@ -639,8 +669,7 @@ int test1(int argc, char **argv) {
669 if(p->guid != users_guids[u])
670 fprintf(stderr, "ERROR: expected to get user guid '%s' but git '%s'", users_guids[u], p->guid);
671 }
642 - end = timems();
643 - fprintf(stderr, "%u accesses served in %0.2f seconds (%llu per second)\n", u, (end-start) / 1000000.0, (unsigned long long)u * 1000000ULL / (end-start));
672 + print_stats(u, start, timems());
673
674 start = timems();
675 fprintf(stderr, "\n%u random users accessing a random server, out of the %u servers\n", users, machines);
@@ -653,8 +682,7 @@ int test1(int argc, char **argv) {
682 if(p->guid != users_guids[tu])
683 fprintf(stderr, "ERROR: expected to get user guid '%s' but git '%s'", users_guids[tu], p->guid);
684 }
656 - end = timems();
657 - fprintf(stderr, "%u accesses served in %0.2f seconds (%llu per second)\n", u, (end-start) / 1000000.0, (unsigned long long)u * 1000000ULL / (end-start));
685 + print_stats(u, start, timems());
686
687 start = timems();
688 fprintf(stderr, "\n%u random users accessing a random server, out of %u servers\n", users, machines2);
@@ -667,33 +695,38 @@ int test1(int argc, char **argv) {
695 if(p->guid != users_guids[tu])
696 fprintf(stderr, "ERROR: expected to get user guid '%s' but git '%s'", users_guids[tu], p->guid);
697 }
670 - end = timems();
671 - fprintf(stderr, "%u accesses served in %0.2f seconds (%llu per second)\n", u, (end-start) / 1000000.0, (unsigned long long)u * 1000000ULL / (end-start));
698 + print_stats(u, start, timems());
699 +
700 + for(m = 0; m < 10; m++) {
701 + start = timems();
702 + fprintf(stderr,
703 + "\n%u random user accesses to a random server, out of %u servers,\n > using 1/10000 with a random url, 1/1000 with a mismatched url\n",
704 + users * 2, machines2);
705 + for (u = 0; u < users * 2; u++) {
706 + uint32_t tu = random() * users / RAND_MAX;
707 + uint32_t tm = random() * machines2 / RAND_MAX;
708 +
709 + char *url = machines_urls[tm];
710 + char buf[FILENAME_MAX + 1];
711 + if (random() % 10000 == 1234) {
712 + snprintf(buf, FILENAME_MAX, "http://random.%ld.netdata.rocks/", random());
713 + url = buf;
714 + }
715 + else if (random() % 1000 == 123)
716 + url = machines_urls[random() * machines2 / RAND_MAX];
717
673 - start = timems();
674 - fprintf(stderr, "\n%u random user accesses to a random server, out of %u servers, using 1 out of 3 a random url\n", users * 2, machines2);
675 - for(u = 0; u < users * 2 ; u++) {
676 - uint32_t tu = random() * users / RAND_MAX;
677 - uint32_t tm = random() * machines2 / RAND_MAX;
718 + PERSON *p = registry_request(users_guids[tu], machines_guids[tm], url);
719
679 - char *url = machines_urls[tm];
680 - char buf[FILENAME_MAX + 1];
681 - if(random() % 3 == 1) {
682 - snprintf(buf, FILENAME_MAX, "http://random.%ld.netdata.rocks/", random());
683 - url = buf;
720 + if (p->guid != users_guids[tu])
721 + fprintf(stderr, "ERROR: expected to get user guid '%s' but git '%s'", users_guids[tu], p->guid);
722 }
685 -
686 - PERSON *p = registry_request(users_guids[tu], machines_guids[tm], url);
687 -
688 - if(p->guid != users_guids[tu])
689 - fprintf(stderr, "ERROR: expected to get user guid '%s' but git '%s'", users_guids[tu], p->guid);
723 + print_stats(u, start, timems());
724 }
691 - end = timems();
692 - fprintf(stderr, "%u accesses served in %0.2f seconds (%llu per second)\n", u, (end-start) / 1000000.0, (unsigned long long)u * 1000000ULL / (end-start));
693 -
694 - exit(0);
725
726 + fprintf(stderr, "\n\nCLEANUP\n");
727 + start = timems();
728 registry_free();
729 + print_stats(registry.persons_count, start, timems());
730 return 0;
731 }
732