├── LICENSE ├── README.md ├── cache.py ├── client.py ├── config_example.yaml ├── master.py └── prefetch.py /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker Registry Trace Player 2 | 3 | The Docker registry trace player is used to replay anonimized production level traces for a registry, available in the traces directory. 4 | The traces are from the IBM docker registry, separated by availability zones. 5 | The trace player can send traces to an actual registry or be used to simulate different caching or prefetching. The registry must be confiugred as a test registry in the current version, however. 6 | 7 | The traces are available at http://research.cs.vt.edu/dssl/drtp-head.html. The size of the traces is 22 GB when unzipped. 8 | 9 | The trace player has two applications: the master and the client. The master is reponsible for reading a trace, generating layers, and distributing the layer requests amoung client applications to forward to a registry. The client application is only needed for the run mode. 10 | 11 | The trace player has 3 modes: 12 | 13 | * warmup 14 | * run 15 | * simulate 16 | 17 | The warmup mode connects to a registry and pushes all the layers in the traces specified by the configuration file. Layers are generated as a string of 0's equal to the size of the request reported in the trace. Because the traces are anonimized, manifests are are treated as layers for the warmup and run modes. During warmup, layers will be pushed to the first registry in the configuration file. 18 | 19 | The Run mode replays the anonymized traces to the registry or registries specified in the configuration file. One or more clients need to be up before the master node is started. 20 | 21 | The simulate mode takes a python file from the configuration file and attempts to call an init function from it. If arguments are specified in the configuration file, then init will be called with two arguments: a sorted list of the requests, and a dictionary of the arguments. If arguments are not specified, then init will be called with just the list of requests. 22 | 23 | # Usage 24 | 25 | To Run the master: 26 | 27 | python master.py -c -i 28 | 29 | Possible commands: warmup, run, and simulate 30 | 31 | To run client: 32 | 33 | python client.py -i 0.0.0.0 -p 34 | 35 | ## Configuration file Options 36 | 37 | The configuration should be a yaml file, refer to config-example.yaml as an example. The following are all the supported options for the configuration file. Options not needed for a given mode will be ignored. 38 | 39 | ### Options: 40 | 41 | #### Cient_info 42 | 43 | * required for run mode 44 | 45 | client_info options: 46 | 47 | * client_list: list of hostname:port for all client nodes. Required option 48 | * port: int, the master port the clients will connect to to forward their results. 49 | * threads: int, Specifies how many processes a single client should spawn to forward requests. The number of possible concurrent connections is limited by the number of threads per client times the number of clients 50 | * wait: boolean, if true, the client threads will wait the relative time between requests as recorded in the traces. If false or absent, the clients will send requests as fast as possible. 51 | * route: optional boolean which instructs the master to route requests to clients based on the remote address of the traces rather than round robin routing. 52 | 53 | #### verbose 54 | * Optional Booblean, if true prints more information to standard out 55 | 56 | #### trace 57 | * Required for all modes 58 | 59 | trace options: 60 | 61 | * location, optional path to the anonymized traces, current directory assumed if absent. Absolute path should be used. 62 | * traces, mandatory list of trace files to be read as input 63 | * limit, optional structure to specify how to limit the number of requests 64 | ..* type: string that can be either "seconds" or "requests" 65 | ..* amount: specifies the limit of the specified type. For example, if type is seconds and amount is 100, only the first 100 seconds of requests will be used 66 | * output: optional filename of where to store output trace of run mode. Default is output.json 67 | 68 | ### registry 69 | 70 | * list of registries to send requests to in warmup and run mode. Only first entry is used in warmup mode, however 71 | 72 | ### warmup 73 | 74 | * required for run and warmup modes 75 | 76 | Options: 77 | 78 | * output: required filename, is populated by warmup and needed by run for mapping the trace uri to a blob 79 | * threads: optional int, specifies how many threads should be used to send requests to registry in warmup mode 80 | * random: optional boolean, instructs the master to create random files for layers rather than creating files of 0's 81 | 82 | ### simulate 83 | 84 | * Required for simulate mode 85 | 86 | Options: 87 | 88 | * name: required string, should be the name of the python file containing the simulation. File should contain an init(requests) or init(requests, args) function to start the simulation 89 | * args: optional dictionary that can contain any arguments the simulation needs 90 | 91 | ### Example 92 | 93 | 94 | client_info: 95 | 96 | client_list: 97 | - localhost:8081 98 | - localhost:8082 99 | port: 8080 100 | threads: 100 101 | wait: true 102 | 103 | verbose: true 104 | 105 | trace: 106 | 107 | location: /data/data_centers/dal09 108 | traces: 109 | - prod-dal09-logstash-2017.08.01-0.json 110 | limit: 111 | type: requests 112 | amount: 20 113 | 114 | output: results.json 115 | 116 | registry: 117 | 118 | - localhost:5000 119 | 120 | warmup: 121 | 122 | output: interm.json 123 | 124 | threads: 100 125 | 126 | simulate: 127 | 128 | name: cache.py 129 | args: 130 | cache_size: 8 131 | 132 | 133 | # Instalation 134 | 135 | sudo apt-get install python-pip 136 | 137 | sudo pip install python-dxf 138 | 139 | sudo pip install requests 140 | 141 | sudo pip install bottle 142 | 143 | sudo pip install pyyaml 144 | 145 | sudo pip install hash_ring 146 | 147 | # Data format for simulation 148 | * sorted by delay (timestamp of request) 149 | 150 | [ 151 | 152 | { 153 | 'delay': timestamp (int), 154 | 'uri': 'v2/user/repo//layer', 155 | 'size', size (int), 156 | 'method': <'GET' or 'PUT'>, 157 | 'duration': duration (int), 158 | 'client': remote address (string) 159 | }, 160 | ] 161 | 162 | # Support Channel 163 | 164 | Michael Littley: milit93@vt.edu 165 | Ali Anwar: ali@vt.edu 166 | 167 | Support is also available through the github repository 168 | -------------------------------------------------------------------------------- /cache.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | class complex_cache: 4 | def __init__(self, size=1., restrict=100, fssize=10): 5 | self.lmu = [] 6 | self.mem = {} 7 | self.capacity = int(size * (2**30)) 8 | self.size = 0 9 | self.hits = 0 10 | self.misses = 0 11 | self.restrict = restrict*(2**20) 12 | self.firstmemhits = 0 13 | self.firstfsmemhits = 0 14 | self.firstfshits = 0 15 | if self.restrict > self.capacity: 16 | self.restrict = self.capacity 17 | self.evictions = 0 18 | self.first = True 19 | self.firstMiss = 0 20 | self.fslmu = [] 21 | self.fs = {} 22 | self.fscap = self.capacity*fssize 23 | self.fssize = 0 24 | self.fsmiss = 0 25 | self.fsfirstMiss = 0 26 | self.fsfirst = True 27 | self.fshits = 0 28 | self.fsevicts = 0 29 | 30 | def fsCheck(self, request): 31 | if request[-1] in self.fs: 32 | self.fssize -= self.fs[request[-1]][0] 33 | self.fs.pop(request[-1], None) 34 | self.fshits += 1 35 | if self.fsfirst == True: 36 | self.firstfshits += 1 37 | else: 38 | self.fsmiss += 1 39 | if self.fsfirst == True: 40 | self.fsfirstMiss += 1 41 | 42 | def fsPlace(self, layer, layerSize, ejected=False): 43 | if layer in self.fs: 44 | self.fslmu.append(layer) 45 | self.fshits += 1 46 | self.fs[layer][1] += 1 47 | if self.fsfirst == True: 48 | self.firstfshits += 1 49 | else: 50 | if ejected is False: 51 | self.fsmiss += 1 52 | if self.fsfirst == True: 53 | self.fsfirstMiss += 1 54 | 55 | if layerSize + self.fssize <= self.fscap: 56 | self.fs[layer] = [layerSize, 1] 57 | self.fssize += layerSize 58 | self.fslmu.append(layer) 59 | else: 60 | if self.fscap < layerSize: 61 | return 62 | self.fsfirst = False 63 | while layerSize + self.fssize > self.fscap: 64 | eject = self.fslmu.pop(0) 65 | if eject not in self.fs: 66 | continue 67 | self.fs[eject][1] -= 1 68 | if self.fs[eject][1] > 0: 69 | continue 70 | self.fssize -= self.fs[eject][0] 71 | self.fs.pop(eject, None) 72 | self.fsevicts += 1 73 | self.fs[layer] = [layerSize, 1] 74 | self.fslmu.append(layer) 75 | self.fssize += layerSize 76 | 77 | def place(self, request): 78 | if request[-1] in self.mem: 79 | self.lmu.append(request[-1]) 80 | self.mem[request[-1]][1] += 1 81 | self.hits += 1 82 | if self.first == True: 83 | self.firstmemhits += 1 84 | if self.fsfirst == True: 85 | self.firstfsmemhits += 1 86 | 87 | else: 88 | self.misses += 1 89 | if self.first == True: 90 | self.firstMiss += 1 91 | 92 | if request[1] >= self.restrict: 93 | self.fsPlace(request[-1], request[1]) 94 | return 95 | 96 | self.fsCheck(request) 97 | 98 | if request[1] + self.size <= self.capacity: 99 | self.mem[request[-1]] = [request[1], 1] 100 | self.lmu.append(request[-1]) 101 | self.size += request[1] 102 | else: 103 | self.first = False 104 | while request[1] + self.size > self.capacity: 105 | eject = self.lmu.pop(0) 106 | self.mem[eject][1] -= 1 107 | if self.mem[eject][1] > 0: 108 | continue 109 | self.fsPlace(eject, self.mem[eject][0], ejected=True) 110 | self.size -= self.mem[eject][0] 111 | self.mem.pop(eject, None) 112 | self.evictions += 1 113 | 114 | self.mem[request[-1]] = [request[1], 1] 115 | self.lmu.append(request[-1]) 116 | self.size += request[1] 117 | 118 | def get_lmu_hits(self): 119 | return self.hits - self.firstmemhits 120 | 121 | def get_h_hits(self): 122 | return self.hits + self.fshits - self.firstfsmemhits - self.firstfshits 123 | 124 | def get_lmu_misses(self): 125 | return self.misses - self.firstMiss 126 | 127 | def get_h_misses(self): 128 | return self.fsmiss - self.fsfirstMiss 129 | 130 | def get_all(self): 131 | info = { 132 | 'memory hits': self.hits, 133 | 'memory misses': self.misses, 134 | 'initial memory misses': self.firstMiss, 135 | 'memory evictions': self.evictions, 136 | 'file system hits': self.fshits, 137 | 'file system misses': self.fsmiss, 138 | 'initial file system misses': self.fsfirstMiss, 139 | 'file system evictions': self.fsevicts, 140 | 'initial memory hits': self.firstmemhits, 141 | 'initial memory-file-system hits': self.firstfsmemhits, 142 | 'initial file system hits': self.firstfshits} 143 | return info 144 | 145 | 146 | def reformat(indata): 147 | ret = [] 148 | for item in indata: 149 | if 'manifest' in item['uri']: 150 | continue 151 | 152 | layer = item['uri'].split('/')[-1] 153 | ret.append((item['delay'], item['size'], layer)) 154 | 155 | return ret 156 | 157 | def run_sim(requests, size): 158 | t = time.time() 159 | caches = [] 160 | caches.append(complex_cache(size=size, fssize = 10)) 161 | caches.append(complex_cache(size=size, fssize = 15)) 162 | caches.append(complex_cache(size=size, fssize = 20)) 163 | i = 0 164 | count = 10 165 | for request in requests: 166 | if 1.*i / len(requests) > 0.1: 167 | i = 0 168 | print str(count) + '% done' 169 | count += 10 170 | for c in caches: 171 | c.place(request) 172 | i += 1 173 | hit_ratios = {} 174 | i = 0 175 | hit_ratios[str(i) + ' 10 lmu hits'] = caches[i].get_lmu_hits() 176 | hit_ratios[str(i) + ' 10 lmu misses'] = caches[i].get_lmu_misses() 177 | hit_ratios[str(i) + ' 10 h hits'] = caches[i].get_h_hits() 178 | hit_ratios[str(i) + ' 10 h misses'] = caches[i].get_h_misses() 179 | hit_ratios[str(i) + ' 15 lmu hits'] = caches[i + 1].get_lmu_hits() 180 | hit_ratios[str(i) + ' 15 lmu misses'] = caches[i + 1].get_lmu_misses() 181 | hit_ratios[str(i) + ' 15 h hits'] = caches[i + 1].get_h_hits() 182 | hit_ratios[str(i) + ' 15 h misses'] = caches[i + 1].get_h_misses() 183 | hit_ratios[str(i) + ' 20 lmu hits'] = caches[i + 2].get_lmu_hits() 184 | hit_ratios[str(i) + ' 20 lmu misses'] = caches[i + 2].get_lmu_misses() 185 | hit_ratios[str(i) + ' 20 h hits'] = caches[i + 2].get_h_hits() 186 | hit_ratios[str(i) + ' 20 h misses'] = caches[i + 2].get_h_misses() 187 | 188 | return hit_ratios 189 | 190 | def init(data, args): 191 | cache_size = args['cache_size'] 192 | 193 | print 'running cache simulation' 194 | 195 | parsed_data = reformat(data) 196 | 197 | info = run_sim(parsed_data, cache_size) 198 | 199 | for thing in info: 200 | print thing + ': ' + str(info[thing]) 201 | 202 | -------------------------------------------------------------------------------- /client.py: -------------------------------------------------------------------------------- 1 | from bottle import route, run, request, static_file, Bottle 2 | import sys, getopt 3 | import os 4 | import requests 5 | import json 6 | from optparse import OptionParser 7 | import time 8 | import socket 9 | import random 10 | from multiprocessing import Process, Queue 11 | from dxf import * 12 | 13 | app = Bottle() 14 | 15 | def send_requests(registry, wait, push_rand, requests, startTime, q): 16 | dxf = [] 17 | for reg in registry: 18 | dxf.append(DXF(reg, 'test_repo', insecure=True)) 19 | results = [] 20 | fname = str(os.getpid()) 21 | f = open(fname, 'wb') 22 | f.close() 23 | for r in requests: 24 | size = 0 25 | t = 0 26 | start = startTime + r['delay'] 27 | onTime = 'no' 28 | if r['method'] == 'GET': 29 | # print fname + ' ' + r['blob'] 30 | now = time.time() 31 | if start > now and wait is True: 32 | onTime = 'yes' 33 | time.sleep(start - now) 34 | t = time.time() 35 | reg = random.randrange(0, len(registry)) 36 | try: 37 | for chunk in dxf[reg].pull_blob(r['blob'], chunk_size=1024*1024): 38 | size += len(chunk) 39 | except: 40 | onTime = 'failed' 41 | t = time.time() - t 42 | else: 43 | # print fname + ' push' 44 | size = r['size'] 45 | if size > 0: 46 | with open(fname, 'wb') as f: 47 | if push_rand is True: 48 | f.seek(size - 9) 49 | f.write(str(random.getrandbits(64))) 50 | else: 51 | f.seek(size - 1) 52 | f.write('\0') 53 | now = time.time() 54 | if start > now and wait is True: 55 | time.sleep(start - now) 56 | now = time.time() 57 | reg = random.randrange(0, len(registry)) 58 | try: 59 | dgst = dxf[reg].push_blob(fname) 60 | except: 61 | onTime = 'failed' 62 | 63 | t = time.time() - now 64 | 65 | reg = (reg + 1) % len(registry) 66 | results.append({'time': now, 'duration': t, 'onTime': onTime, 'size': size}) 67 | os.remove(fname) 68 | q.put(results) 69 | 70 | def get_messages(q): 71 | while True: 72 | msg = q.get() 73 | masterip = msg[0] 74 | 75 | requests = json.loads(msg[1]) 76 | put_rand = requests[0]['random'] 77 | threads = requests[0]['threads'] 78 | ID = requests[0]['id'] 79 | master = (masterip, requests[0]['port']) 80 | registry = requests[0]['registry'] 81 | wait = requests[0]['wait'] 82 | print master, ID, threads 83 | processes = [] 84 | process_requests = [] 85 | delayed = [] 86 | for i in range(threads): 87 | process_requests.append([]) 88 | delayed.append(0) 89 | 90 | for r in requests[1:]: 91 | i = 0 92 | for j in range(len(delayed)): 93 | if delayed[j] < delayed[i]: 94 | i = j 95 | if delayed[i] < r['delay']: 96 | delayed[i] = r['delay'] + r['duration'] 97 | else: 98 | delayed[i] += r['duration'] 99 | 100 | process_requests[i].append(r) 101 | 102 | requests = [{'id': ID}] 103 | 104 | startTime = time.time() 105 | rq = Queue() 106 | for i in range(threads): 107 | first = registry.pop(0) 108 | registry.append(first) 109 | p = Process(target=send_requests, args=(registry, wait, put_rand, process_requests[i], startTime, rq)) 110 | p.start() 111 | processes.append(p) 112 | 113 | for i in range(threads): 114 | requests.extend(rq.get()) 115 | 116 | for p in processes: 117 | p.join() 118 | print 'processes joined, sending response' 119 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 120 | err = False 121 | try: 122 | sock.connect(master) 123 | sock.sendall(json.dumps(requests)) 124 | except Exception as inst: 125 | print inst 126 | print "Error sending info, writing to file" 127 | err = True 128 | if err is True: 129 | with open('error_output', 'w') as f: 130 | f.write(json.dumps(requests)) 131 | sock.close() 132 | print 'finished' 133 | 134 | 135 | @app.route('/up', method="POST") 136 | def sen(): 137 | if 'application/json' in request.headers['Content-Type']: 138 | app.queue.put((request.environ.get('REMOTE_ADDR'), request.body.read())) 139 | return 'gotcha :D' 140 | 141 | def main(argv): 142 | ip = '' 143 | port = 0 144 | try: 145 | opts, args = getopt.getopt(argv,"hi:p:",["ip=","port=","registry="]) 146 | except getopt.GetoptError: 147 | print 'test.py -i -p ' 148 | sys.exit(2) 149 | for opt, arg in opts: 150 | if opt == '-h': 151 | print 'test.py -i -p ' 152 | sys.exit() 153 | elif opt in ("-i", "--ip"): 154 | ip = arg 155 | elif opt in ("-p", "--port"): 156 | port = arg 157 | 158 | 159 | if ip == '' and port == 0: 160 | ip = str(args).split(',')[0] 161 | port = int(str(args).split(',')[1]) 162 | 163 | if ip == '' and port == 0: 164 | print "No ip or port specified..." 165 | 166 | global app 167 | app.queue = Queue() 168 | backend = Process(target=get_messages, args=[app.queue]) 169 | backend.start() 170 | run(app, host=ip, port=port, quiet=True, numthreads=1) 171 | 172 | if __name__ == "__main__": 173 | main(sys.argv[1:]) 174 | 175 | -------------------------------------------------------------------------------- /config_example.yaml: -------------------------------------------------------------------------------- 1 | # excample configuration file for trace player 2 | client_info: # Required for run command 3 | client_list: 4 | - localhost:8081 5 | - localhost:8082 6 | # - client instance and port 7 | port: 8080 # master's server port needed for clients to send inforamtion back 8 | threads: 100 # number of threads per client node, each thread is a process that sends requests 9 | wait: true # Determines if clients should wait the relative amount of time in trace before sending request 10 | route: true # Tells the master to forward based on hashing on client urls rather than round robin 11 | 12 | verbose: true # optional input 13 | 14 | trace: # mandatory field 15 | location: /home/michaellittley/data_centers/dal09 # current directory assumed if field not present 16 | traces: 17 | - prod-dal09-logstash-2017.08.01-0.json # at least one trace required 18 | # entire trace used if limit not speciiied 19 | limit: 20 | type: requests # seconds and requests are supported 21 | amount: 100 22 | 23 | output: results.json # only used in run mode, produced output trace with latencies 24 | 25 | registry: 26 | - localhost:5005 # at least one registry required for run and warmup mode 27 | 28 | warmup: # required for run and warmup mode 29 | output: interm.json # name of file that holds mapping between trace uri's and hashes 30 | 31 | threads: 100 # how many processes used to push blobs to registry 32 | 33 | random: true # instructs the master to create a random file of the layer size rather than a string of 0's equal to the layer size in the trace 34 | 35 | simulate: # required for simulate mode 36 | name: cache.py #name of plugin file, should contain init function 37 | args: # argument dictionary to be passed into 38 | cache_size: 8 # cache size in GB 39 | -------------------------------------------------------------------------------- /master.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import socket 3 | import os 4 | from argparse import ArgumentParser 5 | import requests 6 | import time 7 | import datetime 8 | import random 9 | import threading 10 | import multiprocessing 11 | import json 12 | import yaml 13 | from dxf import * 14 | from multiprocessing import Process, Queue 15 | import importlib 16 | import hash_ring 17 | 18 | ## get requests 19 | def send_request_get(client, payload): 20 | ## Read from the queue 21 | s = requests.session() 22 | headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} 23 | s.post("http://" + str(client) + "/up", data=json.dumps(payload), headers=headers, timeout=100) 24 | 25 | def send_warmup_thread(requests, q, registry, generate_random): 26 | trace = {} 27 | dxf = DXF(registry, 'test_repo', insecure=True) 28 | f = open(str(os.getpid()), 'wb') 29 | f.write('\0') 30 | f.close() 31 | for request in requests: 32 | if request['size'] < 0: 33 | trace[request['uri']] = 'bad' 34 | elif not (request['uri'] in trace): 35 | with open(str(os.getpid()), 'wb') as f: 36 | if generate_random is True: 37 | f.seek(request['size'] - 9) 38 | f.write(str(random.getrandbits(64))) 39 | f.write('\0') 40 | else: 41 | f.seek(request['size'] - 1) 42 | f.write('\0') 43 | 44 | try: 45 | dgst = dxf.push_blob(str(os.getpid())) 46 | except: 47 | dgst = 'bad' 48 | print request['uri'], dgst 49 | trace[request['uri']] = dgst 50 | os.remove(str(os.getpid())) 51 | q.put(trace) 52 | 53 | def warmup(data, out_trace, registry, threads, generate_random): 54 | trace = {} 55 | processes = [] 56 | q = Queue() 57 | process_data = [] 58 | for i in range(threads): 59 | process_data.append([]) 60 | i = 0 61 | for request in data: 62 | if request['method'] == 'GET': 63 | process_data[i % threads].append(request) 64 | i += 1 65 | for i in range(threads): 66 | p = Process(target=send_warmup_thread, args=(process_data[i], q, registry, generate_random)) 67 | processes.append(p) 68 | 69 | for p in processes: 70 | p.start() 71 | 72 | for i in range(threads): 73 | d = q.get() 74 | for thing in d: 75 | if thing in trace: 76 | if trace[thing] == 'bad' and d[thing] != 'bad': 77 | trace[thing] = d[thing] 78 | else: 79 | trace[thing] = d[thing] 80 | 81 | for p in processes: 82 | p.join() 83 | 84 | with open(out_trace, 'w') as f: 85 | json.dump(trace, f) 86 | 87 | def stats(responses): 88 | responses.sort(key = lambda x: x['time']) 89 | 90 | endtime = 0 91 | data = 0 92 | latency = 0 93 | total = len(responses) 94 | onTimes = 0 95 | failed = 0 96 | startTime = responses[0]['time'] 97 | for r in responses: 98 | if r['onTime'] == 'failed': 99 | total -= 1 100 | failed += 1 101 | continue 102 | if r['time'] + r['duration'] > endtime: 103 | endtime = r['time'] + r['duration'] 104 | latency += r['duration'] 105 | data += r['size'] 106 | if r['onTime'] == 'yes': 107 | onTimes += 1 108 | duration = endtime - startTime 109 | print 'Statistics' 110 | print 'Successful Requests: ' + str(total) 111 | print 'Failed Requests: ' + str(failed) 112 | print 'Duration: ' + str(duration) 113 | print 'Data Transfered: ' + str(data) + ' bytes' 114 | print 'Average Latency: ' + str(latency / total) 115 | print '% requests on time: ' + str(1.*onTimes / total) 116 | print 'Throughput: ' + str(1.*total / duration) + ' requests/second' 117 | 118 | 119 | def serve(port, ids, q, out_file): 120 | server_address = ("0.0.0.0", port) 121 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 122 | try: 123 | sock.bind(server_address) 124 | sock.listen(len(ids)) 125 | except: 126 | print "Port already in use: " + str(port) 127 | q.put('fail') 128 | quit() 129 | q.put('success') 130 | 131 | i = 0 132 | response = [] 133 | print "server waiting" 134 | while i < len(ids): 135 | connection, client_address = sock.accept() 136 | resp = '' 137 | while True: 138 | r = connection.recv(1024) 139 | if not r: 140 | break 141 | resp += r 142 | connection.close() 143 | try: 144 | info = json.loads(resp) 145 | if info[0]['id'] in ids: 146 | info = info[1:] 147 | response.extend(info) 148 | i += 1 149 | except: 150 | print 'exception occured in server' 151 | pass 152 | 153 | with open(out_file, 'w') as f: 154 | json.dump(response, f) 155 | print 'results written to ' + out_file 156 | stats(response) 157 | 158 | 159 | ## Get blobs 160 | def get_blobs(data, clients_list, port, out_file): 161 | processess = [] 162 | 163 | ids = [] 164 | for d in data: 165 | ids.append(d[0]['id']) 166 | 167 | serveq = Queue() 168 | server = Process(target=serve, args=(port, ids, serveq, out_file)) 169 | server.start() 170 | status = serveq.get() 171 | if status == 'fail': 172 | quit() 173 | ## Lets start processes 174 | i = 0 175 | for client in clients_list: 176 | p1 = Process(target = send_request_get, args=(client, data[i], )) 177 | processess.append(p1) 178 | i += 1 179 | print "starting client ..." 180 | for p in processess: 181 | p.start() 182 | for p in processess: 183 | p.join() 184 | 185 | server.join() 186 | 187 | def get_requests(files, t, limit): 188 | ret = [] 189 | for filename in files: 190 | with open(filename, 'r') as f: 191 | requests = json.load(f) 192 | 193 | for request in requests: 194 | method = request['http.request.method'] 195 | uri = request['http.request.uri'] 196 | if (('GET' == method) or ('PUT' == method)) and (('manifest' in uri) or ('blobs' in uri)): 197 | size = request['http.response.written'] 198 | if size > 0: 199 | timestamp = datetime.datetime.strptime(request['timestamp'], '%Y-%m-%dT%H:%M:%S.%fZ') 200 | duration = request['http.request.duration'] 201 | client = request['http.request.remoteaddr'] 202 | r = { 203 | 'delay': timestamp, 204 | 'uri': uri, 205 | 'size': size, 206 | 'method': method, 207 | 'duration': duration, 208 | 'client': client 209 | } 210 | ret.append(r) 211 | ret.sort(key= lambda x: x['delay']) 212 | begin = ret[0]['delay'] 213 | 214 | for r in ret: 215 | r['delay'] = (r['delay'] - begin).total_seconds() 216 | 217 | if t == 'seconds': 218 | begin = ret[0]['delay'] 219 | i = 0 220 | for r in ret: 221 | if r['delay'] > limit: 222 | break 223 | i += 1 224 | print i 225 | return ret[:i] 226 | elif t == 'requests': 227 | return ret[:limit] 228 | else: 229 | return ret 230 | 231 | def organize(requests, out_trace, numclients, client_threads, port, wait, registries, round_robin, push_rand): 232 | organized = [] 233 | 234 | if round_robin is False: 235 | ring = hash_ring.HashRing(range(numclients)) 236 | with open(out_trace, 'r') as f: 237 | blob = json.load(f) 238 | 239 | for i in range(numclients): 240 | organized.append([{'port': port, 'id': random.getrandbits(32), 'threads': client_threads, 'wait': wait, 'registry': registries, 'random': push_rand}]) 241 | print organized[-1][0]['id'] 242 | i = 0 243 | 244 | for r in requests: 245 | request = { 246 | 'delay': r['delay'], 247 | 'duration': r['duration'], 248 | } 249 | if r['uri'] in blob: 250 | b = blob[r['uri']] 251 | if b != 'bad': 252 | request['blob'] = b 253 | request['method'] = 'GET' 254 | if round_robin is True: 255 | organized[i % numclients].append(request) 256 | i += 1 257 | else: 258 | organized[ring.get_node(r['client'])].append(request) 259 | else: 260 | request['size'] = r['size'] 261 | request['method'] = 'PUT' 262 | if round_robin is True: 263 | organized[i % numclients].append(request) 264 | i += 1 265 | else: 266 | organized[ring.get_node(r['client'])].append(request) 267 | 268 | return organized 269 | 270 | 271 | def main(): 272 | 273 | parser = ArgumentParser(description='Trace Player, allows for anonymized traces to be replayed to a registry, or for caching and prefecting simulations.') 274 | parser.add_argument('-i', '--input', dest='input', type=str, required=True, help = 'Input YAML configuration file, should contain all the inputs requried for processing') 275 | parser.add_argument('-c', '--command', dest='command', type=str, required=True, help= 'Trace player command. Possible commands: warmup, run, simulate, warmup is used to populate the registry with the layers of the trace, run replays the trace, and simulate is used to test different caching and prefecting policies.') 276 | 277 | args = parser.parse_args() 278 | 279 | config = file(args.input, 'r') 280 | 281 | try: 282 | inputs = yaml.load(config) 283 | except Exception as inst: 284 | print 'error reading config file' 285 | print inst 286 | exit(-1) 287 | 288 | verbose = False 289 | 290 | if 'verbose' in inputs: 291 | if inputs['verbose'] is True: 292 | verbose = True 293 | print 'Verbose Mode' 294 | 295 | if 'trace' not in inputs: 296 | print 'trace field required in config file' 297 | exit(1) 298 | 299 | trace_files = [] 300 | 301 | if 'location' in inputs['trace']: 302 | location = inputs['trace']['location'] 303 | if '/' != location[-1]: 304 | location += '/' 305 | for fname in inputs['trace']['traces']: 306 | trace_files.append(location + fname) 307 | else: 308 | trace_files.extend(inputs['trace']['traces']) 309 | 310 | if verbose: 311 | print 'Input traces' 312 | for f in trace_files: 313 | print f 314 | 315 | limit_type = None 316 | limit = 0 317 | 318 | if 'limit' in inputs['trace']: 319 | limit_type = inputs['trace']['limit']['type'] 320 | if limit_type in ['seconds', 'requests']: 321 | limit = inputs['trace']['limit']['amount'] 322 | else: 323 | print 'Invalid trace limit_type: limit_type must be either seconds or requests' 324 | print exit(1) 325 | elif verbose: 326 | print 'limit_type not specified, entirety of trace files will be used will be used.' 327 | 328 | if 'output' in inputs['trace']: 329 | out_file = inputs['trace']['output'] 330 | else: 331 | out_file = 'output.json' 332 | if verbose: 333 | print 'Output trace not specified, ./output.json will be used' 334 | 335 | generate_random = False 336 | if args.command != 'simulate': 337 | if "warmup" not in inputs or 'output' not in inputs['warmup']: 338 | print 'warmup not specified in config, warmup output required. Exiting' 339 | exit(1) 340 | else: 341 | interm = inputs['warmup']['output'] 342 | if 'random' in inputs['warmup']: 343 | if inputs['warmup']['random'] is True: 344 | generate_random = True 345 | 346 | registries = [] 347 | if 'registry' in inputs: 348 | registries.extend(inputs['registry']) 349 | 350 | json_data = get_requests(trace_files, limit_type, limit) 351 | 352 | if args.command == 'warmup': 353 | if verbose: 354 | print 'warmup mode' 355 | if 'threads' in inputs['warmup']: 356 | threads = inputs['warmup']['threads'] 357 | else: 358 | threads = 1 359 | if verbose: 360 | print 'warmup threads: ' + str(threads) 361 | warmup(json_data, interm, registries[0], threads, generate_random) 362 | 363 | elif args.command == 'run': 364 | if verbose: 365 | print 'run mode' 366 | 367 | if 'client_info' not in inputs or inputs['client_info'] is None: 368 | print 'client_info required for run mode in config file' 369 | print 'exiting' 370 | exit(1) 371 | 372 | if 'port' not in inputs['client_info']: 373 | if verbose: 374 | print 'master server port not specified, assuming 8080' 375 | port = 8080 376 | else: 377 | port = inputs['client_info']['port'] 378 | if verbose: 379 | print 'master port: ' + str(port) 380 | 381 | if 'threads' not in inputs['client_info']: 382 | if verbose: 383 | print 'client threads not specified, 1 thread will be used' 384 | client_threads = 1 385 | else: 386 | client_threads = inputs['client_info']['threads'] 387 | if verbose: 388 | print str(client_threads) + ' client threads' 389 | 390 | if 'client_list' not in inputs['client_info']: 391 | print 'client_list entries are required in config file' 392 | exit(1) 393 | else: 394 | client_list = inputs['client_info']['client_list'] 395 | 396 | if 'wait' not in inputs['client_info']: 397 | if verbose: 398 | print 'Wait not specified, clients will not wait' 399 | wait = False 400 | elif inputs['client_info']['wait'] is True: 401 | wait = True 402 | else: 403 | wait = False 404 | 405 | round_robin = True 406 | if 'route' in inputs['client_info']: 407 | if inputs['client_info']['route'] is True: 408 | round_robin = False 409 | 410 | data = organize(json_data, interm, len(client_list), client_threads, port, wait, registries, round_robin, generate_random) 411 | ## Perform GET 412 | get_blobs(data, client_list, port, out_file) 413 | 414 | 415 | elif args.command == 'simulate': 416 | if verbose: 417 | print 'simulate mode' 418 | if 'simulate' not in inputs: 419 | print 'simulate file required in config' 420 | exit(1) 421 | pi = inputs['simulate']['name'] 422 | if '.py' in pi: 423 | pi = pi[:-3] 424 | try: 425 | plugin = importlib.import_module(pi) 426 | except Exception as inst: 427 | print 'Plugin did not work!' 428 | print inst 429 | exit(1) 430 | try: 431 | if 'args' in inputs['simulate']: 432 | plugin.init(json_data, inputs['simulate']['args']) 433 | else: 434 | plugin.init(json_data) 435 | except Exception as inst: 436 | print 'Error running plugin init!' 437 | print inst 438 | 439 | 440 | if __name__ == "__main__": 441 | main() 442 | -------------------------------------------------------------------------------- /prefetch.py: -------------------------------------------------------------------------------- 1 | class prefetch_cache: 2 | 3 | def __init__(self, rtimeout=600, mtimeout=600): 4 | self.repos = {} 5 | self.manifest = {} 6 | self.rtimeout = rtimeout 7 | self.mtimeout = mtimeout 8 | self.hit = 0 9 | self.miss = 0 10 | self.size = 0 11 | self.size_list = [] 12 | self.goodprefetch = 0 13 | self.badprefetch = 0 14 | self.putcount = 0 15 | self.getlayercount = 0 16 | self.getmanifestcount = 0 17 | 18 | def flush(self): 19 | for repo in self.manifest: 20 | for layer in self.manifest[repo]: 21 | count = layer[1] 22 | self.size -= layer[2] 23 | self.size_list.append(self.size) 24 | if count > 0: 25 | self.goodprefetch += 1 26 | else: 27 | self.badprefetch += 1 28 | self.manifest = {} 29 | 30 | def update_manifests(self, repo, client, timestamp): 31 | if repo in self.repos: 32 | for layer in self.repos[repo]: 33 | if client not in layer[1]: 34 | layer[1].append(client) 35 | if repo not in self.manifest: 36 | self.manifest[repo] = [[timestamp, 0, layer[2]]] 37 | self.size += layer[2] 38 | self.size_list.append(self.size) 39 | else: 40 | present = False 41 | for fetchedlayer in self.manifest[repo]: 42 | if fetchedlayer[2] == layer[2]: 43 | fetchedlayer[0] = timestamp 44 | present = True 45 | break 46 | if present == False: 47 | self.manifest[repo].append([timestamp, 0, layer[2]]) 48 | self.size += layer[2] 49 | self.size_list.append(self.size) 50 | 51 | 52 | 53 | def manifest_time_out(self, timestamp): 54 | remove = [] 55 | for repo in self.manifest: 56 | i = 0 57 | while i < len(self.manifest[repo]): 58 | t = self.manifest[repo][i][0] 59 | count = self.manifest[repo][i][1] 60 | delta = timestamp - t 61 | if abs(delta) > self.mtimeout: 62 | self.size -= self.manifest[repo][i][2] 63 | self.size_list.append(self.size) 64 | self.manifest[repo].pop(i) 65 | if count > 0: 66 | self.goodprefetch += 1 67 | else: 68 | self.badprefetch += 1 69 | else: 70 | i += 1 71 | if len(self.manifest[repo]) == 0: 72 | remove.append(repo) 73 | for repo in remove: 74 | self.manifest.pop(repo, None) 75 | 76 | def repo_time_out(self, timestamp): 77 | remove = [] 78 | for repo in self.repos: 79 | i = 0 80 | while i < len(self.repos[repo]): 81 | t = self.repos[repo][i][0] 82 | delta = timestamp - t 83 | if abs(delta) > self.rtimeout: 84 | self.repos[repo].pop(i) 85 | else: 86 | break 87 | if len(self.repos[repo]) == 0: 88 | remove.append(repo) 89 | for repo in remove: 90 | self.repos.pop(repo, None) 91 | 92 | def update_repos(self, repo, client, size, timestamp): 93 | if repo in self.repos: 94 | self.repos[repo].append([timestamp, [client], size]) 95 | else: 96 | self.repos[repo] = [[timestamp, [client], size]] 97 | 98 | def update_layers(self, repo, size, timestmap): 99 | if repo in self.manifest: 100 | for layer in self.manifest[repo]: 101 | if size - 1000 < layer[2] and size + 1000 > layer[2]: 102 | self.hit += 1 103 | layer[1] += 1 104 | else: 105 | self.miss += 1 106 | 107 | def put(self, request): 108 | repo = request['repo'] 109 | client = request['client'] 110 | timestamp = request['timestamp'] 111 | size = request['size'] 112 | #self.manifest_time_out(timestamp) 113 | #self.repo_time_out(timestamp) 114 | if request['method'] == 'PUT': 115 | self.putcount += 1 116 | self.update_repos(repo, client, size, timestamp) 117 | elif request['type'] == 'm': 118 | self.getmanifestcount += 1 119 | self.update_manifests(repo, client, timestamp) 120 | else: 121 | self.getlayercount += 1 122 | self.update_layers(repo, size, timestamp) 123 | 124 | def get_info(self): 125 | data = { 126 | 'hits': self.hit, 127 | 'misses': self.miss, 128 | 'good prefetch': self.goodprefetch, 129 | 'bad prefetch': self.badprefetch, 130 | 'max size': max(self.size_list)} 131 | return data 132 | 133 | def get_size_list(self): 134 | return self.size_list 135 | 136 | def extract(data): 137 | 138 | requests = [] 139 | 140 | for request in data: 141 | method = request['method'] 142 | 143 | if 'blobs' in request['uri']: 144 | t = 'l' 145 | elif 'manifests' in request['uri']: 146 | t = 'm' 147 | else: 148 | continue 149 | 150 | parts = request['uri'].split('/') 151 | repo = parts[1] + '/' + parts[2] 152 | requests.append({'timestamp': request['delay'], 153 | 'repo': repo, 154 | 'client': request['client'], 155 | 'method': request['method'], 156 | 'type': t, 157 | 'size': request['size']}) 158 | return requests 159 | 160 | 161 | def init(data, args): 162 | outfile = args['outfile'] 163 | 164 | requests = extract(data) 165 | 166 | print 'running simulation' 167 | 168 | prefetch1010 = prefetch_cache(rtimeout=600, mtimeout=600) 169 | prefetch10hour = prefetch_cache(rtimeout=600, mtimeout=3600) 170 | prefetch10half = prefetch_cache(rtimeout=600, mtimeout=43200) 171 | prefetch10day = prefetch_cache(rtimeout=600, mtimeout=86400) 172 | prefetchhour10 = prefetch_cache(rtimeout=3600, mtimeout=600) 173 | prefetchhourhour = prefetch_cache(rtimeout=3600, mtimeout=3600) 174 | prefetchhourhalf = prefetch_cache(rtimeout=3600, mtimeout=43200) 175 | prefetchhourday = prefetch_cache(rtimeout=3600, mtimeout=86400) 176 | prefetchhalf10 = prefetch_cache(rtimeout=43200, mtimeout=600) 177 | prefetchhalfhour = prefetch_cache(rtimeout=43200, mtimeout=3600) 178 | prefetchhalfhalf = prefetch_cache(rtimeout=43200, mtimeout=43200) 179 | prefetchhalfday = prefetch_cache(rtimeout=43200, mtimeout=86400) 180 | prefetchday10 = prefetch_cache(rtimeout=86400, mtimeout=600) 181 | prefetchdayhour = prefetch_cache(rtimeout=86400, mtimeout=3600) 182 | prefetchdayhalf = prefetch_cache(rtimeout=86400, mtimeout=43200) 183 | prefetchdayday = prefetch_cache(rtimeout=86400, mtimeout=86400) 184 | i = 0 185 | l = len(requests) 186 | count = 0 187 | for request in requests: 188 | if 1.*i / l > 0.1: 189 | count += 10 190 | i = 0 191 | print str(count) + '% done' 192 | i += 1 193 | prefetch1010.put(request) 194 | prefetch10hour.put(request) 195 | prefetch10half.put(request) 196 | prefetch10day.put(request) 197 | prefetchhour10.put(request) 198 | prefetchhourhour.put(request) 199 | prefetchhourhalf.put(request) 200 | prefetchhourday.put(request) 201 | prefetchhalf10.put(request) 202 | prefetchhalfhour.put(request) 203 | prefetchhalfhalf.put(request) 204 | prefetchhalfday.put(request) 205 | prefetchday10.put(request) 206 | prefetchdayhour.put(request) 207 | prefetchdayhalf.put(request) 208 | prefetchdayday.put(request) 209 | prefetch1010.flush() 210 | prefetch10hour.flush() 211 | prefetch10half.flush() 212 | prefetch10day.flush() 213 | prefetchhour10.flush() 214 | prefetchhourhour.flush() 215 | prefetchhourhalf.flush() 216 | prefetchhourday.flush() 217 | prefetchhalf10.flush() 218 | prefetchhalfhour.flush() 219 | prefetchhalfhalf.flush() 220 | prefetchhalfday.flush() 221 | prefetchday10.flush() 222 | prefetchdayhour.flush() 223 | prefetchdayhalf.flush() 224 | prefetchdayday.flush() 225 | 226 | 227 | data = [prefetch1010.get_info(), 228 | prefetch10hour.get_info(), 229 | prefetch10half.get_info(), 230 | prefetch10day.get_info(), 231 | prefetchhour10.get_info(), 232 | prefetchhourhour.get_info(), 233 | prefetchhourhalf.get_info(), 234 | prefetchhourday.get_info(), 235 | prefetchhalf10.get_info(), 236 | prefetchhalfhour.get_info(), 237 | prefetchhalfhalf.get_info(), 238 | prefetchhalfday.get_info(), 239 | prefetchday10.get_info(), 240 | prefetchdayhour.get_info(), 241 | prefetchdayhalf.get_info(), 242 | prefetchdayday.get_info()] 243 | 244 | f = open(outfile, 'w') 245 | for n in data: 246 | size = n['max size'] 247 | ratio = 1.*n['hits'] / (n['good prefetch'] + n['bad prefetch']) 248 | f.write(str(ratio) + ',' + str(size) + '\n') 249 | f.close() 250 | 251 | --------------------------------------------------------------------------------