diff options
author | Matt Strapp <strap012@umn.edu> | 2020-11-21 20:00:57 -0600 |
---|---|---|
committer | Matt Strapp <strap012@umn.edu> | 2020-11-21 20:00:57 -0600 |
commit | d92369c96ac797cc0ce86f474ec7e1ea46ab1fcb (patch) | |
tree | c699f48e91403bfb8907ba266430f6499b5734e0 | |
parent | aaaaaaaaaaaaa (diff) | |
download | csci4061-d92369c96ac797cc0ce86f474ec7e1ea46ab1fcb.tar csci4061-d92369c96ac797cc0ce86f474ec7e1ea46ab1fcb.tar.gz csci4061-d92369c96ac797cc0ce86f474ec7e1ea46ab1fcb.tar.bz2 csci4061-d92369c96ac797cc0ce86f474ec7e1ea46ab1fcb.tar.lz csci4061-d92369c96ac797cc0ce86f474ec7e1ea46ab1fcb.tar.xz csci4061-d92369c96ac797cc0ce86f474ec7e1ea46ab1fcb.tar.zst csci4061-d92369c96ac797cc0ce86f474ec7e1ea46ab1fcb.zip |
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-rw-r--r-- | P3/.vscode/launch.json | 2 | ||||
-rw-r--r-- | P3/server.c | 15 |
2 files changed, 8 insertions, 9 deletions
diff --git a/P3/.vscode/launch.json b/P3/.vscode/launch.json index 5fab37f..f529d06 100644 --- a/P3/.vscode/launch.json +++ b/P3/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/web_server", - "args": ["9000", "testing", "2", "2", "0", "10", "3"], + "args": ["9000", "testing", "100", "100", "1", "100", "100"], "stopAtEntry": false, "cwd": "${workspaceFolder}", diff --git a/P3/server.c b/P3/server.c index 7946457..5164a91 100644 --- a/P3/server.c +++ b/P3/server.c @@ -26,7 +26,7 @@ int tempNodeCounter = 0, counter2 = 0; pthread_t *wID; char *path; pthread_mutex_t Qlock, logLock, cacheLock; -clock_t start_t, end_t, total_t; +clock_t start_t, end_t, total_t = 600; void *worker(void *arg); /* @@ -64,10 +64,10 @@ void *dynamic_pool_size_update(void *arg) // Policy: Have clock tracking how long the whole process takes // If above maxProcessTime -> spawn X workers // Else if below mostEfficientTime kill all unnecessary threads leaving 1(or 2) of each - if (total_t > 30) + if (total_t > 3000) { // Threads must be detachable - wID = realloc(wID, (++wIndex) * sizeof(pthread_t)); + wID = (pthread_t *) realloc(wID, (++wIndex * sizeof(pthread_t))); pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); @@ -78,10 +78,10 @@ void *dynamic_pool_size_update(void *arg) sprintf(threadName, "Worker %d", wIndex); pthread_setname_np(wID[wIndex - 1], threadName); } - else if (total_t < 6) + else if (total_t < 500) { //TODO: Make sure thread isn't doing anything before killing it - pthread_cancel(wID[--wIndex]); + pthread_cancel(wID[wIndex--]); // Need dynamically allocated array of thread ID's so we can cancel the necessary threads wID = realloc(wID, wIndex * sizeof(pthread_t)); } @@ -438,7 +438,7 @@ void *worker(void *arg) free(request); free(workerBuf); end_t = clock(); - total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC; + total_t = (double)(end_t - start_t); printf("Total time taken by CPU: %ld\n", total_t); } return NULL; @@ -506,8 +506,7 @@ int main(int argc, char **argv) struct sigaction act; act.sa_handler = eggs; act.sa_flags = 0; - if (sigemptyset(&act.sa_mask) == -1 || - sigaction(SIGINT, &act, NULL) == -1) + if (sigemptyset(&act.sa_mask) == -1 || sigaction(SIGINT, &act, NULL) == -1) { perror("SIGINT Handler Error"); return -2; |