OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """ This module implements the Stale-While-Revalidate performance improvement | 5 """ This module implements the Stale-While-Revalidate performance improvement |
6 experiment on third parties' resources. | 6 experiment on third parties' resources. |
7 | 7 |
8 The top level operations of the experiment are: | 8 The top level operations of the experiment are: |
9 1. Record WPR archive; | 9 1. Record WPR archive; |
10 2. Create a patched WPR archive so that all resource are getting cached; | 10 2. Create a patched WPR archive so that all resource are getting cached; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 chrome_cache.UnzipDirectoryContent(original_cache_archive_path, cache_path) | 89 chrome_cache.UnzipDirectoryContent(original_cache_archive_path, cache_path) |
90 cache_backend = chrome_cache.CacheBackend(cache_path, 'simple') | 90 cache_backend = chrome_cache.CacheBackend(cache_path, 'simple') |
91 cache_keys = set(cache_backend.ListKeys()) | 91 cache_keys = set(cache_backend.ListKeys()) |
92 for request in trace.request_track.GetEvents(): | 92 for request in trace.request_track.GetEvents(): |
93 if request.url not in cache_keys: | 93 if request.url not in cache_keys: |
94 continue | 94 continue |
95 if request.url in urls_should_not_be_cached: | 95 if request.url in urls_should_not_be_cached: |
96 cache_backend.DeleteKey(request.url) | 96 cache_backend.DeleteKey(request.url) |
97 delete_count += 1 | 97 delete_count += 1 |
98 continue | 98 continue |
| 99 if not request.HasReceivedResponse(): |
| 100 continue |
99 if request.url in urls_to_enable_swr: | 101 if request.url in urls_to_enable_swr: |
100 request.SetHTTPResponseHeader( | 102 request.SetHTTPResponseHeader( |
101 'cache-control', 'max-age=0,stale-while-revalidate=315360000') | 103 'cache-control', 'max-age=0,stale-while-revalidate=315360000') |
102 request.SetHTTPResponseHeader( | 104 request.SetHTTPResponseHeader( |
103 'last-modified', 'Thu, 23 Jun 2016 11:30:00 GMT') | 105 'last-modified', 'Thu, 23 Jun 2016 11:30:00 GMT') |
104 swr_patch_count += 1 | 106 swr_patch_count += 1 |
105 elif request.url in urls_already_with_swr: | 107 elif request.url in urls_already_with_swr: |
106 # Force to use SWR on resources that originally attempted to use it. | 108 # Force to use SWR on resources that originally attempted to use it. |
107 request.SetHTTPResponseHeader( | 109 request.SetHTTPResponseHeader( |
108 'cache-control', 'max-age=0,stale-while-revalidate=315360000') | 110 'cache-control', 'max-age=0,stale-while-revalidate=315360000') |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 | 314 |
313 run_metrics_list.sort(key=lambda e: e['repeat_id']) | 315 run_metrics_list.sort(key=lambda e: e['repeat_id']) |
314 with open(ExtractMetrics.path, 'w') as csv_file: | 316 with open(ExtractMetrics.path, 'w') as csv_file: |
315 writer = csv.DictWriter(csv_file, fieldnames=(additional_column_names + | 317 writer = csv.DictWriter(csv_file, fieldnames=(additional_column_names + |
316 sandwich_metrics.COMMON_CSV_COLUMN_NAMES)) | 318 sandwich_metrics.COMMON_CSV_COLUMN_NAMES)) |
317 writer.writeheader() | 319 writer.writeheader() |
318 for run_metrics in run_metrics_list: | 320 for run_metrics in run_metrics_list: |
319 writer.writerow(run_metrics) | 321 writer.writerow(run_metrics) |
320 | 322 |
321 self._common_builder.default_final_tasks.append(ExtractMetrics) | 323 self._common_builder.default_final_tasks.append(ExtractMetrics) |
OLD | NEW |