Skip to content

Commit

Permalink
Error function fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
esmaeilmirvakili committed Aug 9, 2020
1 parent 9468a1d commit c7d3d34
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 17 deletions.
14 changes: 13 additions & 1 deletion scripts/optimization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,20 @@
"\n",
"$OsdQueueLenError = \\frac{48}{osdQueueLen}$\n",
"\n",
"$ThroughputError = 10^{ThroughputChange - 10}$\n"
"$ThroughputError = 10^{ThroughputChange - 10}$"
]
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
}
],
"metadata": {
Expand Down
54 changes: 38 additions & 16 deletions scripts/radossim.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from latency_model import StatisticLatencyModel
from workload import OsdClientBench4K, RandomOSDClient, OsdClientBenchConstantSize
import pickle
import matplotlib.pyplot as plt

# Create requests with a fixed priority and certain inter-arrival and size distributions
def osdClient(env, workloadGenerator, dstQ):
Expand Down Expand Up @@ -36,8 +37,7 @@ def osdThread(env, srcQ, dstQ):
yield put


def kvAndAioThread(env, srcQ, latencyModel, targetLat=5000, measInterval=100000, data=None, useCoDel=True):
bm = BatchManagement(srcQ, targetLat, measInterval)
def kvAndAioThread(env, srcQ, latencyModel, batchManagement, data=None, useCoDel=True):
while True:
batchReqSize = 0
batch = []
Expand All @@ -47,10 +47,10 @@ def kvAndAioThread(env, srcQ, latencyModel, targetLat=5000, measInterval=100000,
batchReqSize += reqSize
batch.append(req)
if useCoDel:
if bm.batchSize == float("inf"):
if batchManagement.batchSize == float("inf"):
batchSize = len(srcQ.items)
else:
batchSize = int(min(bm.batchSize - 1, len(srcQ.items)))
batchSize = int(min(batchManagement.batchSize - 1, len(srcQ.items)))
else:
batchSize = int(min(1023, len(srcQ.items)))
for i in range(batchSize):
Expand Down Expand Up @@ -78,7 +78,7 @@ def kvAndAioThread(env, srcQ, latencyModel, targetLat=5000, measInterval=100000,
req = (req, kvQDispatch, kvCommit)
data.append(req)
if useCoDel:
bm.manageBatch(kvBatch, batchReqSize, kvQDispatch, kvCommit)
batchManagement.manageBatch(kvBatch, batchReqSize, kvQDispatch, kvCommit)


# Batch incoming requests and process
Expand Down Expand Up @@ -139,9 +139,13 @@ def __init__(self, queue, minLatTarget=5000, initInterval=100000):
self.batchSize = self.queue.capacity
self.batchSizeInit = 100
self.batchDownSize = lambda x: int(x / 2)
self.batchUpSize = lambda x: int(x + 10)
self.batchUpSize = lambda x: int(x + 1)
# written data state
self.bytesWritten = 0
self.batchSizeLog = []
self.timeLog = []
self.batchSizeLog.append(self.batchSize)
self.timeLog.append(0)

def manageBatch(self, batch, batchSize, dispatchTime, commitTime):
for txn in batch:
Expand All @@ -159,7 +163,7 @@ def manageBatch(self, batch, batchSize, dispatchTime, commitTime):
self.latMap[priority] = osdQLat + kvQLat
self.cntMap[priority] = 1
self.fightBufferbloat(kvQLat, dispatchTime)
self.printLats()
# self.printLats()

# Implement CoDel algorithm and call batchSizing
def fightBufferbloat(self, currQLat, currentTime):
Expand Down Expand Up @@ -198,6 +202,8 @@ def batchSizing(self, isTooLarge):
# print('batch size', self.batchSize, 'gets larger')
self.batchSize = self.batchUpSize(self.batchSize)
# print('new batch size is', self.batchSize)
self.batchSizeLog.append(self.batchSize)
self.timeLog.append(self.queue._env.now)

def printLats(self, freq=1000):
if self.count % freq == 0:
Expand Down Expand Up @@ -241,13 +247,13 @@ def wrapper(*args, **kwargs):

def monitor(data, resource):
"""Monitor queue len"""
data.sum += len(resource.items)
data.size += 1
data.queueLenList.append(len(resource.items))
data.logTimeList.append(resource._env.now)

class QueueLenMonitor:
def __init__(self):
self.sum = 0
self.size = 0
self.queueLenList = []
self.logTimeList = []

env = simpy.Environment()

Expand Down Expand Up @@ -300,7 +306,8 @@ def __init__(self):
if output:
data = []
# env.process(kvThread(env, kvQ, latencyModel, targetLat, measInterval, data))
env.process(kvAndAioThread(env, aioQ, latencyModel, targetLat, measInterval, data, useCoDel))
bm = BatchManagement(aioQ, targetLat, measInterval)
env.process(kvAndAioThread(env, aioQ, latencyModel, bm, data, useCoDel))

# if outputFile:
# env.process(outputResults(env, outputQ, outputFile))
Expand All @@ -314,7 +321,22 @@ def __init__(self):
bytesWritten = latencyModel.bytesWritten
avgThroughput = bytesWritten / duration

return avgThroughput, queuLenMonitor.sum / queuLenMonitor.size
# fig, ax = plt.subplots(figsize=(8, 4))
# ax.grid(True)
# ax.set_title('title')
# ax.set_xlabel('x_label')
# ax.set_ylabel('Likelihood of occurrence')
# ax.plot(queuLenMonitor.logTimeList, queuLenMonitor.queueLenList)
# plt.show()

fig, ax = plt.subplots(figsize=(8, 4))
ax.grid(True)
ax.set_xlabel('time')
ax.set_ylabel('Batch Size')
ax.plot(bm.timeLog, bm.batchSizeLog)
plt.show()

return avgThroughput, sum(queuLenMonitor.queueLenList) / len(queuLenMonitor.queueLenList)


if __name__ == "__main__":
Expand All @@ -336,9 +358,9 @@ def __init__(self):
help='Use CoDel algorithm for batch sizing?'
)
args = parser.parse_args()
targetLat = 5000
measInterval = 100000
time = 5 * 60 * 1_000_000 # 5 mins
targetLat = 1000
measInterval = 2
time = 60 * 1_000_000 # 5 mins
if args.useCoDel:
print('Using CoDel algorithm ...')

Expand Down

0 comments on commit c7d3d34

Please sign in to comment.