Page Speed Optimization Libraries
1.5.27.2
|
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/basictypes.h" 00025 #include "net/instaweb/util/public/ref_counted_ptr.h" 00026 #include "net/instaweb/util/public/scoped_ptr.h" 00027 #include "net/instaweb/util/public/string.h" 00028 00029 namespace net_instaweb { 00030 00031 class AbstractMutex; 00032 class AsyncFetch; 00033 class MessageHandler; 00034 class Statistics; 00035 class ThreadSystem; 00036 class TimedVariable; 00037 class UrlAsyncFetcher; 00038 class Variable; 00039 00052 class RateController { 00053 public: 00054 static const char kQueuedFetchCount[]; 00055 static const char kDroppedFetchCount[]; 00056 static const char kCurrentGlobalFetchQueueSize[]; 00057 00058 RateController(int max_global_queue_size, 00059 int per_host_outgoing_request_threshold, 00060 int per_host_queued_request_threshold, 00061 ThreadSystem* thread_system, 00062 Statistics* statistics); 00063 00064 virtual ~RateController(); 00065 00068 void Fetch(UrlAsyncFetcher* fetcher, 00069 const GoogleString& url, 00070 MessageHandler* message_handler, 00071 AsyncFetch* fetch); 00072 00074 static void InitStats(Statistics* statistics); 00075 00076 private: 00077 class HostFetchInfo; 00078 class CustomFetch; 00079 friend class CustomFetch; 00080 00081 typedef RefCountedPtr<HostFetchInfo> HostFetchInfoPtr; 00082 00083 typedef std::map<GoogleString, HostFetchInfoPtr*> HostFetchInfoMap; 00084 00086 void DeleteFetchInfoIfPossible(const HostFetchInfoPtr& fetch_info); 00087 00089 const int max_global_queue_size_; 00091 const int per_host_outgoing_request_threshold_; 00093 const int per_host_queued_request_threshold_; 00094 ThreadSystem* thread_system_; 00095 00097 HostFetchInfoMap fetch_info_map_; 00098 scoped_ptr<AbstractMutex> mutex_; 00099 00100 TimedVariable* queued_fetch_count_; 00101 TimedVariable* dropped_fetch_count_; 00104 Variable* current_global_fetch_queue_size_; 00105 00106 DISALLOW_COPY_AND_ASSIGN(RateController); 00107 }; 00108 00109 } 00110 00111 #endif ///< NET_INSTAWEB_HTTP_PUBLIC_RATE_CONTROLLER_H_