-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cloud class defined and test function for the cloud started.
- Loading branch information
Showing
2 changed files
with
76 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,53 @@ | ||
import Queue | ||
|
||
# these delays can be seen as the time response time of the server for each game | ||
# being played | ||
|
||
HI_P_CLOUD_DELAY = 10 | ||
MED_P_CLOUD_DELAY = 5 | ||
LOW_P_CLOUD_DELAY = 3 | ||
NUM_PLAYERS = 10 | ||
ks | ||
class Cloud(object): | ||
|
||
def __init__(self, processor, gpu): | ||
self.processor = processor | ||
self.gpu = gpu | ||
def __init__(self, gameTraffic, location, timeout): | ||
|
||
self.requestList = Queue.Queue() | ||
|
||
if gameTraffic == 0: | ||
self.timeToProcess = LOW_P_CLOUD_DELAY | ||
elif gameTraffic == 1: | ||
self.timeToProcess = MED_P_CLOUD_DELAY | ||
else: | ||
self.timeToProcess = HIGH_P_CLOUD_DELAY | ||
|
||
self.location = location | ||
self.timeMS = 0 | ||
self.timeout = timeout | ||
|
||
def updateTime(self, time): # is this how it works? | ||
self.timeMS = time | ||
return processResponse(self) | ||
|
||
def processResponse(self): | ||
|
||
if self.timeMS % timeToProcess == 0 and not self.requestList.empty() : | ||
headPacket = self.requestList.get(); | ||
if (time - headPacket.timestamp) > timeout: | ||
return None | ||
else: | ||
responsePackets[] | ||
for i in range(1,NUM_PLAYERS): | ||
newPacket = headPacket | ||
|
||
def processData(self, data): | ||
# Determine how much time it takes to process | ||
time = data / gpu | ||
# update packet | ||
newPacket.sendAddress = 0 | ||
newPacket.receiveAddress = i | ||
responsePackets[i].append(newPacket) | ||
return responsePackets | ||
else: | ||
return None | ||
|
||
class AmazonWebService(Cloud): | ||
def __init__(self): | ||
super(AmazonWebService, self).__init__(3.5, 780) | ||
def receiveRequest(self, packet): # can this access | ||
self.requestList.put(packet) | ||
|
||
clouds = { | ||
"aws" : AmazonWebService() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import cloud | ||
|
||
|
||
if __name__ == "__main__": | ||
packet1.id = 0 | ||
packet1.sendAddress = 1 | ||
packet1.receiveAddress = 0 | ||
packet1.timestamp = 100 | ||
packet2.id = 1 | ||
packet2.sendAddress = 2 | ||
packet2.receiveAddress = 0 | ||
packet2.timestamp = 0 | ||
|
||
cloud = Cloud(0, 0, 10) | ||
|
||
cloud.receiveRequest(packet1) | ||
cloud.receiveRequest(packet2) | ||
|
||
time = 90 | ||
|
||
for i in range(0,10): | ||
time = time + 1 | ||
packetList = cloud.updateTime(time) | ||
if packetList != None: | ||
print packetList[0].id | ||
|
||
|
||
|