Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rate_controller.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef NET_INSTAWEB_HTTP_PUBLIC_RATE_CONTROLLER_H_
20 #define NET_INSTAWEB_HTTP_PUBLIC_RATE_CONTROLLER_H_
21 
22 #include <map>
23 
29 #include "pagespeed/kernel/base/thread_annotations.h"
30 
31 namespace net_instaweb {
32 
33 class AbstractMutex;
34 class AsyncFetch;
35 class MessageHandler;
36 class Statistics;
37 class ThreadSystem;
38 class TimedVariable;
39 class UpDownCounter;
40 class UrlAsyncFetcher;
41 
55  public:
56  static const char kQueuedFetchCount[];
57  static const char kDroppedFetchCount[];
58  static const char kCurrentGlobalFetchQueueSize[];
59 
60  RateController(int max_global_queue_size,
61  int per_host_outgoing_request_threshold,
62  int per_host_queued_request_threshold,
63  ThreadSystem* thread_system,
64  Statistics* statistics);
65 
66  virtual ~RateController();
67 
69  void ShutDown() { shutdown_.set_value(true); }
70  bool is_shut_down() const { return shutdown_.value(); }
71 
74  void Fetch(UrlAsyncFetcher* fetcher,
75  const GoogleString& url,
76  MessageHandler* message_handler,
77  AsyncFetch* fetch);
78 
80  static void InitStats(Statistics* statistics);
81 
82  private:
83  class HostFetchInfo;
84  class CustomFetch;
85  friend class CustomFetch;
86 
87  typedef RefCountedPtr<HostFetchInfo> HostFetchInfoPtr;
88 
89  typedef std::map<GoogleString, HostFetchInfoPtr*> HostFetchInfoMap;
90 
92  void DeleteFetchInfoIfPossible(const HostFetchInfoPtr& fetch_info);
93 
95  const int max_global_queue_size_;
97  const int per_host_outgoing_request_threshold_;
99  const int per_host_queued_request_threshold_;
100  ThreadSystem* thread_system_;
101 
103  HostFetchInfoMap fetch_info_map_ GUARDED_BY(mutex_);
104  scoped_ptr<AbstractMutex> mutex_;
105 
106  TimedVariable* queued_fetch_count_;
107  TimedVariable* dropped_fetch_count_;
110  UpDownCounter* current_global_fetch_queue_size_;
111 
112  AtomicBool shutdown_;
113 
114 
115 };
116 
117 }
118 
119 #endif
void ShutDown()
Makes any further fetches quick-fail.
Definition: rate_controller.h:69
Definition: rate_controller.h:54
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
static void InitStats(Statistics *statistics)
Initializes statistics variables associated with this class.
Definition: thread_system.h:40
void Fetch(UrlAsyncFetcher *fetcher, const GoogleString &url, MessageHandler *message_handler, AsyncFetch *fetch)