OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "net/disk_cache/simple/simple_backend_impl.h" | 5 #include "net/disk_cache/simple/simple_backend_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 #include <functional> | 9 #include <functional> |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 using base::Time; | 43 using base::Time; |
44 using base::DirectoryExists; | 44 using base::DirectoryExists; |
45 using base::CreateDirectory; | 45 using base::CreateDirectory; |
46 | 46 |
47 namespace disk_cache { | 47 namespace disk_cache { |
48 | 48 |
49 namespace { | 49 namespace { |
50 | 50 |
51 // Maximum number of concurrent worker pool threads, which also is the limit | 51 // Maximum number of concurrent worker pool threads, which also is the limit |
52 // on concurrent IO (as we use one thread per IO request). | 52 // on concurrent IO (as we use one thread per IO request). |
53 const int kDefaultMaxWorkerThreads = 50; | 53 const size_t kMaxWorkerThreads = 5U; |
54 | 54 |
55 const char kThreadNamePrefix[] = "SimpleCache"; | 55 const char kThreadNamePrefix[] = "SimpleCache"; |
56 | 56 |
57 // Maximum fraction of the cache that one entry can consume. | 57 // Maximum fraction of the cache that one entry can consume. |
58 const int kMaxFileRatio = 8; | 58 const int kMaxFileRatio = 8; |
59 | 59 |
60 // A global sequenced worker pool to use for launching all tasks. | 60 // A global sequenced worker pool to use for launching all tasks. |
61 SequencedWorkerPool* g_sequenced_worker_pool = NULL; | 61 SequencedWorkerPool* g_sequenced_worker_pool = NULL; |
62 | 62 |
63 void MaybeCreateSequencedWorkerPool() { | 63 void MaybeCreateSequencedWorkerPool() { |
64 if (!g_sequenced_worker_pool) { | 64 if (!g_sequenced_worker_pool) { |
65 int max_worker_threads = kDefaultMaxWorkerThreads; | 65 g_sequenced_worker_pool = |
66 | 66 new SequencedWorkerPool(kMaxWorkerThreads, kThreadNamePrefix); |
67 const std::string thread_count_field_trial = | |
68 base::FieldTrialList::FindFullName("SimpleCacheMaxThreads"); | |
69 if (!thread_count_field_trial.empty()) { | |
70 max_worker_threads = | |
71 std::max(1, std::atoi(thread_count_field_trial.c_str())); | |
72 } | |
73 | |
74 g_sequenced_worker_pool = new SequencedWorkerPool(max_worker_threads, | |
75 kThreadNamePrefix); | |
76 g_sequenced_worker_pool->AddRef(); // Leak it. | 67 g_sequenced_worker_pool->AddRef(); // Leak it. |
77 } | 68 } |
78 } | 69 } |
79 | 70 |
80 bool g_fd_limit_histogram_has_been_populated = false; | 71 bool g_fd_limit_histogram_has_been_populated = false; |
81 | 72 |
82 void MaybeHistogramFdLimit(net::CacheType cache_type) { | 73 void MaybeHistogramFdLimit(net::CacheType cache_type) { |
83 if (g_fd_limit_histogram_has_been_populated) | 74 if (g_fd_limit_histogram_has_been_populated) |
84 return; | 75 return; |
85 | 76 |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 this)); | 723 this)); |
733 callback.Run(result); | 724 callback.Run(result); |
734 } | 725 } |
735 | 726 |
736 void SimpleBackendImpl::FlushWorkerPoolForTesting() { | 727 void SimpleBackendImpl::FlushWorkerPoolForTesting() { |
737 if (g_sequenced_worker_pool) | 728 if (g_sequenced_worker_pool) |
738 g_sequenced_worker_pool->FlushForTesting(); | 729 g_sequenced_worker_pool->FlushForTesting(); |
739 } | 730 } |
740 | 731 |
741 } // namespace disk_cache | 732 } // namespace disk_cache |
OLD | NEW |