Skip to content

Commit

Permalink
perf: load balance
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Oct 15, 2023
1 parent 3910d79 commit 768c60e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions free_one_api/impls/channel/eval.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import random
import math
import time

from ...models.channel import evaluation
Expand Down Expand Up @@ -26,24 +27,28 @@ async def evaluate(self) -> float:

lastUseTime = -1

last5Records: list[evaluation.Record] = []

if len(records_reverse) == 0:
lastUseTime = now_time - self.init_time

using_amount = 0

for record in records_reverse:
if lastUseTime == -1:
if record.end_time < 0: # querying
lastUseTime = 0
using_amount += 1
else: # last query committed
lastUseTime = now_time - record.end_time
else:
if record.end_time < 0:
using_amount += 1

if len(last5Records) >= 5:
break
if record.end_time > 0: # committed
if record.success and record.stream:
last5Records.append(record)
# if len(last5Records) >= 5:
# break
# if record.end_time > 0: # committed
# if record.success and record.stream:
# last5Records.append(record)

last5StreamRecordsAverageLatency = sum([record.latency for record in last5Records]) / len(last5Records) if len(last5Records) > 0 else 0
# last5StreamRecordsAverageLatency = sum([record.latency for record in last5Records]) / len(last5Records) if len(last5Records) > 0 else 0

return (0 - last5StreamRecordsAverageLatency) + lastUseTime
return round(lastUseTime / 5) * 5 - using_amount * 5

0 comments on commit 768c60e

Please sign in to comment.