diff --git a/hey copy.txt b/hey copy.txt new file mode 100644 index 0000000..23ae0d0 --- /dev/null +++ b/hey copy.txt @@ -0,0 +1,46 @@ + +Summary: + Total: 5.2029 secs + Slowest: 0.2684 secs + Fastest: 0.0281 secs + Average: 0.2039 secs + Requests/sec: 573.9092 + + Total data: 158614 bytes + Size/request: 53 bytes + +Response time histogram: + 0.028 [1] | + 0.052 [26] |■ + 0.076 [15] |■ + 0.100 [16] |■ + 0.124 [11] | + 0.148 [16] |■ + 0.172 [46] |■■ + 0.196 [1042] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ + 0.220 [968] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ + 0.244 [702] |■■■■■■■■■■■■■■■■■■■■■■■■■■■ + 0.268 [143] |■■■■■ + + +Latency distribution: + 10% in 0.1811 secs + 25% in 0.1894 secs + 50% in 0.2028 secs + 75% in 0.2231 secs + 90% in 0.2385 secs + 95% in 0.2441 secs + 99% in 0.2531 secs + +Details (average, fastest, slowest): + DNS+dialup: 0.0004 secs, 0.0281 secs, 0.2684 secs + DNS-lookup: 0.0000 secs, 0.0000 secs, 0.0000 secs + req write: 0.0002 secs, 0.0000 secs, 0.0249 secs + resp wait: 0.2026 secs, 0.0102 secs, 0.2680 secs + resp read: 0.0001 secs, 0.0000 secs, 0.0012 secs + +Status code distribution: + [200] 2986 responses + + + diff --git a/hey.txt b/hey.txt index 5d5aeac..1721b6e 100644 --- a/hey.txt +++ b/hey.txt @@ -1,46 +1,26 @@ Summary: - Total: 12.2647 secs - Slowest: 3.3362 secs - Fastest: 0.5028 secs - Average: 2.1634 secs - Requests/sec: 49.5730 + Total: 5.0283 secs + Slowest: 0.0000 secs + Fastest: 0.0000 secs + Average: NaN secs + Requests/sec: 51018.3313 - Total data: 27968 bytes - Size/request: 46 bytes Response time histogram: - 0.503 [1] | - 0.786 [16] |■■■■ - 1.069 [17] |■■■■ - 1.353 [17] |■■■■ - 1.636 [19] |■■■■ - 1.919 [112] |■■■■■■■■■■■■■■■■■■■■■■■■■ - 2.203 [176] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ - 2.486 [121] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■ - 2.769 [22] |■■■■■ - 3.053 [27] |■■■■■■ - 3.336 [80] |■■■■■■■■■■■■■■■■■■ Latency distribution: - 10% in 1.5052 secs - 25% in 1.8882 secs - 50% in 2.1174 secs - 75% in 2.3524 secs - 90% in 3.1907 secs - 95% in 3.2670 secs - 99% in 3.3261 secs Details (average, fastest, slowest): - DNS+dialup: 0.0150 secs, 0.5028 secs, 3.3362 secs - DNS-lookup: 0.0000 secs, 0.0000 secs, 0.0000 secs - req write: 0.0057 secs, 0.0000 secs, 0.1496 secs - resp wait: 2.1384 secs, 0.3501 secs, 3.3357 secs - resp read: 0.0002 secs, 0.0000 secs, 0.0169 secs + DNS+dialup: NaN secs, 0.0000 secs, 0.0000 secs + DNS-lookup: NaN secs, 0.0000 secs, 0.0000 secs + req write: NaN secs, 0.0000 secs, 0.0000 secs + resp wait: NaN secs, 0.0000 secs, 0.0000 secs + resp read: NaN secs, 0.0000 secs, 0.0000 secs Status code distribution: - [200] 608 responses - +Error distribution: + [256536] Post "http://127.0.0.1:10000": dial tcp 127.0.0.1:10000: connect: connection refused diff --git a/hey1.txt b/hey1.txt deleted file mode 100644 index c113ade..0000000 --- a/hey1.txt +++ /dev/null @@ -1,46 +0,0 @@ - -Summary: - Total: 11.2523 secs - Slowest: 2.9288 secs - Fastest: 0.0329 secs - Average: 1.2459 secs - Requests/sec: 90.8258 - - Total data: 47012 bytes - Size/request: 46 bytes - -Response time histogram: - 0.033 [1] | - 0.322 [18] |■ - 0.612 [23] |■ - 0.902 [26] |■ - 1.191 [127] |■■■■■■■ - 1.481 [740] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ - 1.770 [59] |■■■ - 2.060 [17] |■ - 2.350 [8] | - 2.639 [1] | - 2.929 [2] | - - -Latency distribution: - 10% in 1.1377 secs - 25% in 1.2114 secs - 50% in 1.2531 secs - 75% in 1.3035 secs - 90% in 1.4574 secs - 95% in 1.5758 secs - 99% in 2.0799 secs - -Details (average, fastest, slowest): - DNS+dialup: 0.0004 secs, 0.0329 secs, 2.9288 secs - DNS-lookup: 0.0000 secs, 0.0000 secs, 0.0000 secs - req write: 0.0001 secs, 0.0000 secs, 0.0179 secs - resp wait: 1.2442 secs, 0.0245 secs, 2.9283 secs - resp read: 0.0001 secs, 0.0000 secs, 0.0005 secs - -Status code distribution: - [200] 1022 responses - - - diff --git a/runtime/include/hash.h b/runtime/include/hash.h deleted file mode 100644 index 6d1049d..0000000 --- a/runtime/include/hash.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include "hashmap.h" -#include "lock.h" -#include "xmalloc.h" - -typedef struct -{ - struct hashmap* map; - lock_t lock; -}lockhashmap; - -static inline lockhashmap -*hashmap_lock_new( - size_t elsize, size_t cap, uint64_t seed0, - uint64_t seed1, - uint64_t (*hash)(const void *item, uint64_t seed0, uint64_t seed1), - int (*compare)(const void *a, const void *b, void *udata), - void (*elfree)(void *item), - void *udata -) -{ - lockhashmap* node = (lockhashmap *)xmalloc(sizeof(lockhashmap)); - node->map = hashmap_new(elsize, cap, seed0, seed1, hash, compare, elfree, udata); - LOCK_INIT(&node->lock); - return node; -} - -/*void threadsafe_hashmap_free(ThreadSafeHashmap *thm) { - if (thm) { - spinlock_acquire(&thm->lock); - hashmap_free(thm->map); - spinlock_release(&thm->lock); - spinlock_destroy(&thm->lock); - free(thm); - } -} - -bool threadsafe_hashmap_set(ThreadSafeHashmap *thm, const void *item) { - spinlock_acquire(&thm->lock); - const void *result = hashmap_set(thm->map, item); - spinlock_release(&thm->lock); - return result != NULL; -} - -const void *threadsafe_hashmap_get(ThreadSafeHashmap *thm, const void *item) { - spinlock_acquire(&thm->lock); - const void *result = hashmap_get(thm->map, item); - spinlock_release(&thm->lock); - return result; -} -*/ diff --git a/runtime/include/map.h b/runtime/include/map.h index e00d278..d71937e 100644 --- a/runtime/include/map.h +++ b/runtime/include/map.h @@ -155,11 +155,14 @@ map_delete(struct hashmap *map, char *key, uint32_t key_len) } else { prev->next = node->next; } - free(node->key); - free(node); + free(node->key); + node->key = NULL; if (node->manage_mvalue) { free(node->value); - } + node->value = NULL; + } + free(node); + node = NULL; did_delete = true; break; } diff --git a/runtime/include/scheduler.h b/runtime/include/scheduler.h index bb3ace2..fbc9e4b 100644 --- a/runtime/include/scheduler.h +++ b/runtime/include/scheduler.h @@ -69,6 +69,7 @@ err_allocate: client_socket_send(request->socket_descriptor, 503); client_socket_close(request->socket_descriptor, &request->socket_address); free(request); + request = NULL; goto done; } @@ -108,6 +109,7 @@ err_allocate: client_socket_send(request->socket_descriptor, 503); client_socket_close(request->socket_descriptor, &request->socket_address); free(request); + request = NULL; goto done; } static inline struct sandbox * @@ -138,6 +140,7 @@ err_allocate: client_socket_send(sandbox_request->socket_descriptor, 503); client_socket_close(sandbox_request->socket_descriptor, &sandbox->client_address); free(sandbox_request); + sandbox_request = NULL; err: sandbox = NULL; goto done; diff --git a/runtime/src/current_sandbox.c b/runtime/src/current_sandbox.c index 39fba5c..82fd579 100644 --- a/runtime/src/current_sandbox.c +++ b/runtime/src/current_sandbox.c @@ -9,10 +9,9 @@ #include "module.h" #include "software_interrupt.h" #include "map.h" -#include "hashmap.h" extern uint64_t system_start_timestamp; -pthread_mutex_t lock; +lock_t lock; __thread struct sandbox *worker_thread_current_sandbox = NULL; @@ -156,7 +155,7 @@ current_sandbox_start(void) }; memcpy(pre_func_output, sandbox->request_response_data + sandbox->request_length, output_length); - uint64_t enqueue_timestamp = __getcycles(); + //printf("这是图一分多 the ID %lu %s pre_func_output is %s\n", sandbox->id, sandbox->module->name, pre_func_output); //uint64_t current_rs = enqueue_timestamp - system_start_timestamp; //mem_log("time %lu request id:%d executing, name:%s remaining slack %lu\n", current_rs, // sandbox->id, sandbox->module->name, sandbox->remaining_slack); @@ -164,13 +163,21 @@ current_sandbox_start(void) for (size_t i = 0; i < next_module_idx; i++) { struct module * next_module_node = next_module[i]; - assert(next_module_node); + assert(next_module_node); + char * individual_pre_func_output = (char *)malloc(output_length); + if (!individual_pre_func_output) { + fprintf(stderr, "Failed to allocate memory for the individual previous output: %s\n", strerror(errno)); + free(pre_func_output); + goto err; + } + memcpy(individual_pre_func_output, pre_func_output, output_length); + uint64_t enqueue_timestamp = __getcycles(); struct sandbox_request *sandbox_request = sandbox_request_allocate(next_module_node, false, sandbox->request_length, next_module_node->name, sandbox->client_socket_descriptor, (const struct sockaddr *)&sandbox->client_address, sandbox->request_arrival_timestamp, enqueue_timestamp, - sandbox->remaining_slack, true, pre_func_output, output_length); + sandbox->remaining_slack, true, individual_pre_func_output, output_length); /* TODO: All sandboxs in the chain share the same request id, but sandbox_request_allocate() * will busy-wait to generate an unique id, should we optimize it here? */ @@ -203,8 +210,13 @@ current_sandbox_start(void) sandbox_set_as_returned(sandbox, SANDBOX_RUNNING); }else if (next_module_idx == 1 && next_module_pre_count > 1) { - pthread_mutex_init(&lock, NULL); - pthread_mutex_lock(&lock); + static bool lock_flag = true; + if (lock_flag) + { + LOCK_INIT(&lock); + lock_flag = false; + } + bool hash_flag = false; /*Before each id is put into the hash table, the key needs to add a "module handle"*/ struct module * next_module_node = next_module[0]; assert(next_module_node); @@ -214,9 +226,11 @@ current_sandbox_start(void) assert(cur_request_id); snprintf(cur_request_id, key_len, "%s%lu", next_module_node->name, sandbox->id); uint32_t ret_value_len; - + LOCK_LOCK(&lock); + //printf("锁住了\n"); uint64_t *requet_id = (uint64_t *)map_get(sandbox_request_id, cur_request_id, strlen(cur_request_id), &ret_value_len); - if (!requet_id) { + if(!requet_id) hash_flag = true; + if (hash_flag) { //it means that the first sandbox is calculated, and it needs to wait for the return value of other sandboxes. ssize_t output_length = sandbox->request_response_data_length - sandbox->request_length; char * pre_func_output = (char *)malloc(output_length); @@ -225,6 +239,7 @@ current_sandbox_start(void) goto err; }; memcpy(pre_func_output, sandbox->request_response_data + sandbox->request_length, output_length); + //printf("创建sandbox_request 模块工作结果 the ID %lu %s pre_func_output is %s\n", sandbox->id, sandbox->module->name, pre_func_output); uint64_t enqueue_timestamp = __getcycles(); //uint64_t current_rs = enqueue_timestamp - system_start_timestamp; //mem_log("time %lu request id:%d executing, name:%s remaining slack %lu\n", current_rs, @@ -247,7 +262,9 @@ current_sandbox_start(void) map_set(sandbox_request_id, cur_request_id, strlen(cur_request_id), &module_pre_count, sizeof(uint32_t), true); map_set(sandbox_req_map, cur_request_id, strlen(cur_request_id), sandbox_request, sizeof(struct sandbox_request *), false); free(cur_request_id); - }else + cur_request_id = NULL; + } + else { uint32_t rest_pre_count = *requet_id; assert(rest_pre_count >= 1); @@ -257,25 +274,22 @@ current_sandbox_start(void) // Copy data into pre_func_output ssize_t output_length = sandbox->request_response_data_length - sandbox->request_length; - char *pre_func_outputi = (char *)malloc(output_length); - if (!pre_func_outputi) { + char *pre_func_output = (char *)malloc(output_length); + if (!pre_func_output) { fprintf(stderr, "Failed to allocate memory for the previous output: %s\n", strerror(errno)); + free(pre_func_output); goto err; } - memcpy(pre_func_outputi, sandbox->request_response_data + sandbox->request_length, output_length); - - uint64_t enqueue_timestamp = __getcycles(); - - const char *previous_output = sandbox_request->previous_function_output ? sandbox_request->previous_function_output : ""; + memcpy(pre_func_output, sandbox->request_response_data + sandbox->request_length, output_length); + //printf("这是合并sandbox_request模块工作结果 the ID %lu %s pre_func_output is %s\n", sandbox->id, sandbox->module->name, pre_func_output); ssize_t new_output_length = sandbox_request->output_length + output_length + 2; char *new_output = (char *)malloc(new_output_length); if (!new_output) { fprintf(stderr, "Failed to allocate memory for the new output: %s\n", strerror(errno)); - free(pre_func_outputi); goto err; } memset(new_output, 0, new_output_length); - snprintf(new_output, new_output_length, "%s&%s", previous_output, pre_func_outputi); + snprintf(new_output, new_output_length, "%s&%s", sandbox_request->previous_function_output, pre_func_output); if(sandbox_request->previous_function_output != NULL) { free(sandbox_request->previous_function_output); @@ -283,11 +297,12 @@ current_sandbox_start(void) } assert(new_output); sandbox_request->previous_function_output = new_output; - free(pre_func_outputi); - pre_func_outputi = NULL; + //printf("这是合并sandbox_request 模块工作结果 the ID %lu %s new_output is %s\n", sandbox->id, sandbox->module->name, new_output); + free(pre_func_output); + pre_func_output = NULL; sandbox_request->output_length = new_output_length; - rest_pre_count --; + rest_pre_count--; if (rest_pre_count != 0) { map_upsert(sandbox_request_id, cur_request_id, strlen(cur_request_id), &rest_pre_count, sizeof(uint32_t)); @@ -299,18 +314,22 @@ current_sandbox_start(void) map_delete(sandbox_req_map, cur_request_id, strlen(cur_request_id)); map_delete(sandbox_request_id, cur_request_id, strlen(cur_request_id)); } - free(cur_request_id); + free(cur_request_id); + cur_request_id = NULL; } + //printf("解锁"); + LOCK_UNLOCK(&lock); + //printf("没有死索\n"); if (sandbox->request_from_outside) { sandbox_remove_from_epoll(sandbox); } sandbox_set_as_returned(sandbox, SANDBOX_RUNNING); + goto done; }else { error_message = "the strcuture of DAG is not supported\n"; goto err; - } - pthread_mutex_unlock(&lock); + } } else { /* Retrieve the result, construct the HTTP response, and send to client */ if (sandbox_send_response(sandbox) < 0) { diff --git a/runtime/src/module.c b/runtime/src/module.c index 7862b9b..75803ee 100644 --- a/runtime/src/module.c +++ b/runtime/src/module.c @@ -419,7 +419,7 @@ module_new_from_json(char *file_name) int ntoks = 2 * tokens[i].size; char request_content_type[HTTP_MAX_HEADER_VALUE_LENGTH] = { 0 }; char response_content_type[HTTP_MAX_HEADER_VALUE_LENGTH] = { 0 }; - char **next_module_names = NULL; + char **next_module_names = NULL; for (; j < ntoks;) { int ntks = 1; @@ -650,9 +650,8 @@ module_new_from_json(char *file_name) } nodes[i]->next_module[j] = nodes[m]; int preflag = 0; - while (nodes[m]->pre_module[preflag]) { - preflag++; - assert(preflag < precount); + for (; preflag < precount; preflag++) { + if(nodes[m]->pre_module[preflag] == NULL) break; } nodes[m]->pre_module[preflag] = nodes[i]; break; diff --git a/runtime/src/runtime.c b/runtime/src/runtime.c index cabf351..e4afa0f 100644 --- a/runtime/src/runtime.c +++ b/runtime/src/runtime.c @@ -41,7 +41,7 @@ uint64_t runtime_worker_threads_remaining_slack[RUNTIME_WORKER_THREAD_CORE_COUNT void runtime_cleanup() { - if (runtime_sandbox_perf_log != NULL) fflush(runtime_sandbox_perf_log); + //if (runtime_sandbox_perf_log != NULL) fflush(runtime_sandbox_perf_log); software_interrupt_deferred_sigalrm_max_print(); exit(EXIT_SUCCESS); diff --git a/runtime/src/sandbox.c b/runtime/src/sandbox.c index 70c6bff..9769d71 100644 --- a/runtime/src/sandbox.c +++ b/runtime/src/sandbox.c @@ -186,6 +186,7 @@ sandbox_free(struct sandbox *sandbox) assert(sandbox->state == SANDBOX_ERROR || sandbox->state == SANDBOX_COMPLETE); int rc; + //printf("ID %lu of sandbox %s removing sandbox from queue\n",sandbox->id, sandbox->module->name); if (sandbox->previous_function_output != NULL) { free(sandbox->previous_function_output); sandbox->previous_function_output = NULL; diff --git a/runtime/tests/fibonacciadd/main.c b/runtime/tests/fibonacciadd/main.c index 98f3ae2..8cc9973 100644 --- a/runtime/tests/fibonacciadd/main.c +++ b/runtime/tests/fibonacciadd/main.c @@ -23,7 +23,7 @@ int main() { unsigned long int num1, num2; char *line = strtok(buffer, "&"); - char *second_part = strtok(NULL, "\0"); // Assume the rest of the string is the second number + char *second_part = strtok(NULL, "&"); // Assume the rest of the string is the second number if (line && sscanf(line, "%lu", &num1) == 1 && second_part && sscanf(second_part, "%lu", &num2) == 1) { diff --git a/sledge.log b/sledge.log deleted file mode 100755 index 667d306..0000000 --- a/sledge.log +++ /dev/null @@ -1,29 +0,0 @@ -Runtime Environment: - CPU Speed: 2400 MHz - Processor Speed: 2400 MHz - RLIMIT_DATA: Infinite - RLIMIT_NOFILE: 1048576 (Increased from 8192) - Core Count: 8 - Listener core ID: 1 - First Worker core ID: 2 - Worker core count: 6 - Scheduler Policy: EDF - Sigalrm Policy: BROADCAST - Preemption: Enabled - Quantum: 5000 us - Sandbox Performance Log: /home/hai/sledge-old/runtime_sandbox_perf_log.log -Starting listener thread - Listener core thread: 7ffff7a006c0 -Starting 6 worker thread(s) -C: 01, T: 0x7ffff7bfdd80, F: runtime_start_runtime_worker_threads> - Sandboxing environment ready! - -C: 01, T: 0x7ffff7bfdd80, F: module_new> - Stack Size: 524288 -C: 01, T: 0x7ffff7bfdd80, F: module_new> - Stack Size: 524288 -C: 01, T: 0x7ffff7bfdd80, F: module_new> - Stack Size: 524288 -C: 01, T: 0x7ffff7bfdd80, F: module_new> - Stack Size: 524288 -double free or corruption (fasttop)