Page Speed Optimization Libraries
1.8.31.3
|
00001 /* 00002 * Copyright 2012 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00018 00019 #ifndef NET_INSTAWEB_HTTP_PUBLIC_RATE_CONTROLLER_H_ 00020 #define NET_INSTAWEB_HTTP_PUBLIC_RATE_CONTROLLER_H_ 00021 00022 #include <map> 00023 00024 #include "net/instaweb/util/public/atomic_bool.h" 00025 #include "net/instaweb/util/public/basictypes.h" 00026 #include "net/instaweb/util/public/ref_counted_ptr.h" 00027 #include "net/instaweb/util/public/scoped_ptr.h" 00028 #include "net/instaweb/util/public/string.h" 00029 00030 namespace net_instaweb { 00031 00032 class AbstractMutex; 00033 class AsyncFetch; 00034 class MessageHandler; 00035 class Statistics; 00036 class ThreadSystem; 00037 class TimedVariable; 00038 class UpDownCounter; 00039 class UrlAsyncFetcher; 00040 00053 class RateController { 00054 public: 00055 static const char kQueuedFetchCount[]; 00056 static const char kDroppedFetchCount[]; 00057 static const char kCurrentGlobalFetchQueueSize[]; 00058 00059 RateController(int max_global_queue_size, 00060 int per_host_outgoing_request_threshold, 00061 int per_host_queued_request_threshold, 00062 ThreadSystem* thread_system, 00063 Statistics* statistics); 00064 00065 virtual ~RateController(); 00066 00068 void ShutDown() { shutdown_.set_value(true); } 00069 bool is_shut_down() const { return shutdown_.value(); } 00070 00073 void Fetch(UrlAsyncFetcher* fetcher, 00074 const GoogleString& url, 00075 MessageHandler* message_handler, 00076 AsyncFetch* fetch); 00077 00079 static void InitStats(Statistics* statistics); 00080 00081 private: 00082 class HostFetchInfo; 00083 class CustomFetch; 00084 friend class CustomFetch; 00085 00086 typedef RefCountedPtr<HostFetchInfo> HostFetchInfoPtr; 00087 00088 typedef std::map<GoogleString, HostFetchInfoPtr*> HostFetchInfoMap; 00089 00091 void DeleteFetchInfoIfPossible(const HostFetchInfoPtr& fetch_info); 00092 00094 const int max_global_queue_size_; 00096 const int per_host_outgoing_request_threshold_; 00098 const int per_host_queued_request_threshold_; 00099 ThreadSystem* thread_system_; 00100 00102 HostFetchInfoMap fetch_info_map_; 00103 scoped_ptr<AbstractMutex> mutex_; 00104 00105 TimedVariable* queued_fetch_count_; 00106 TimedVariable* dropped_fetch_count_; 00109 UpDownCounter* current_global_fetch_queue_size_; 00110 00111 AtomicBool shutdown_; 00112 00113 DISALLOW_COPY_AND_ASSIGN(RateController); 00114 }; 00115 00116 } 00117 00118 #endif ///< NET_INSTAWEB_HTTP_PUBLIC_RATE_CONTROLLER_H_