From ce3eeef3c2a905167020f27c05c7640d249a8cb9 Mon Sep 17 00:00:00 2001 From: AndyGrant Date: Mon, 11 Jun 2018 01:24:26 -0400 Subject: [PATCH] Workload selection algorithm --- OpenBench/utils.py | 53 ++++++++++++++++++++++++++++++++++++++++++--- OpenBench/views.py | 6 +++-- db.sqlite3 | Bin 64512 -> 65536 bytes 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/OpenBench/utils.py b/OpenBench/utils.py index d0c93a1..4e1fbaf 100644 --- a/OpenBench/utils.py +++ b/OpenBench/utils.py @@ -1,6 +1,6 @@ -from OpenBench.models import Engine, Profile, Machine, Test +import math, requests, random -import math, requests +from OpenBench.models import Engine, Profile, Machine, Test def getSourceLocation(branch, repo): @@ -102,4 +102,51 @@ def newTest(request): return test def getWorkload(threads): - pass \ No newline at end of file + + # Get a list of all active tests + tests = Test.objects.filter(finished=False) + tests = tests.filter(deleted=False) + tests = list(tests.filter(approved=True)) + + # No tests, error out and let views handle it + if len(tests) == 0: raise Exception('ANone') + + options = [] # Highest priority with acceptable threads + + # Find our options for workloads + for test in tests: + + # Find Threads for the Dev Engine + tokens = test.devoptions.split(' ') + devthreads = tokens[0].split('=')[1] + + # Find Threads for the Base Engine + tokens = test.baseoptions.split(' ') + basethreads = tokens[0].split('=')[1] + + # Machines need at to support Dev & Base + threadcnt = max(devthreads, basethreads) + + # Empty list or higher priority found for workable test + if (options == [] or test.priority > highest) and threadcnt <= threads: + highest = test.priority + options = [test] + + # New workable test with the same priority + elif options != [] and test.priority == highest and threadcnt <= threads: + options.append(test) + + # Sum of throughputs, for weighted randomness + total = sum([test.throughput for test in options]) + target = random.randrange(0, total) + + # Finally, select our test with the weighted target + while True: + + # Found test within the target throughput + if target < options[0].throughput: + return options[0] + + # Drop the test from selection + target -= options[0].throughput + options = options[1:] \ No newline at end of file diff --git a/OpenBench/views.py b/OpenBench/views.py index 4527d5f..190078c 100644 --- a/OpenBench/views.py +++ b/OpenBench/views.py @@ -375,10 +375,12 @@ def getWorkload(request): try: # Find an active Test to work on test = OpenBench.utils.getWorkload(machine.threads) except: - import traceback - print (traceback.print_exc()) return HttpResponse('None') + print(user) + print(machine) + print(test) + @csrf_exempt def submitResults(request): pass diff --git a/db.sqlite3 b/db.sqlite3 index 663f087e65991060c9613b82691586eb0af09f13..06d898f1468b89e7f87fc95e5499518063cd654b 100644 GIT binary patch delta 861 zcmaizOKTHR6vyY@(}_t%I}=wT)U*^MLeo3XWFnG8d<066`Uy;?c}!ky^Dq;#XtcU0 zC??IaE=3UB#4BVgh$|r!DuN%tjdant5NSc2sZ>)5WO@JRoO}Q0cg}78gl2Q1b%EVx z7$)5IgwS^P-p(X)QQ`EnxwA@8l!HX{1q4aZ2<6P#+v_1_HBoZMoPtChk|anPKO!s!70st< zl0XPIGAwC6L6V4{Oj%)i_xc-_n}9v5IVKE;@B;?0*KUjSR`eyXmKfscVDa3ISstYs zd=m=L!yfz=e?d>sXNbZU&f;GvjSf+lPPZaxeGX!%P+d+)h9U$sHD@Y$BVJ0Z0&*r7gVyQS9LSV+excsGb5LZMIpIjZohib7$^&g!%dJoMt$ z*BQ=%KQYjU=a7W}SO+@ee1|b{b#{8Q+{pnD=dt()yKG}8r;f!T*u?Qqv=NIoV!~RY zmwxDl!kmLyVqn91ZxbyteP*fMzUFQ4Z0rFW8Hb|N-H$4kv7ym7xTDH(eC$fqsvI)< z@ahyBd&EYDsf~h07Y0sb@3$EIyE1h1poS*TSZje`!|I0eo;r9N?jtYbrfz%r@4x&8 DgMswF delta 263 zcmZo@U}^ZlJVBbZkAZ=~exiasW8cPv3tWt>n+>`9RrpM-OpUFKEcA>F3`|WeHlNcs z6Hw!2@@HT^%)ErTl{t;somqpKlj#-HX{I$yy-ayPDJa;i<*<@*@`4`a$yvRsZ1M5= zIVnPuC-mxV_IKLK%E!$75v0zZ`8V@7=8qF6nrwD^vzmGHM{i*lIbO!!3{0-fxy;*{ z6qvR!-DLJ)p2U>J^pEj3vocfvW<`#hj4Ue5zKoM6{8HE~Kk2C=7ZdXw2Ih0jbC|O> z3o67gGZ`>XzOY@D*U-wyQqRQ5($K)dfE6gBzWL~Odj~FNrcMUtW@a{~PM}%UOq)A@ Hl`{eWbB;|l