17 #ifndef PAGESPEED_CONTROLLER_POPULARITY_CONTEST_SCHEDULE_REWRITE_CONTROLLER_H_
18 #define PAGESPEED_CONTROLLER_POPULARITY_CONTEST_SCHEDULE_REWRITE_CONTROLLER_H_
21 #include <unordered_map>
32 #include "pagespeed/kernel/base/thread_annotations.h"
77 namespace net_instaweb {
82 static const char kNumRewritesRequested[];
83 static const char kNumRewritesSucceeded[];
84 static const char kNumRewritesFailed[];
85 static const char kNumRewritesRejectedQueueSize[];
86 static const char kNumRewritesRejectedInProgress[];
87 static const char kRewriteQueueSize[];
88 static const char kNumRewritesRunning[];
89 static const char kNumRewritesAwaitingRetry[];
97 int max_running_rewrites,
98 int max_queued_rewrites);
104 void NotifyRewriteFailed(
const GoogleString& key)
override;
118 : key(k), saved_priority(0), callback(
nullptr), state(STOPPED) {}
125 struct StringPtrHash {
127 return std::hash<GoogleString>()(*x);
133 return (a == b || *a == *b);
137 typedef std::unordered_map<
const GoogleString*, Rewrite*,
138 StringPtrHash, StringPtrEq>
145 EXCLUSIVE_LOCKS_REQUIRED(mutex_) WARN_UNUSED_RESULT;
150 Function* StartRewrite(Rewrite* rewrite)
151 EXCLUSIVE_LOCKS_REQUIRED(mutex_) WARN_UNUSED_RESULT;
154 void StopRewrite(Rewrite* rewrite) EXCLUSIVE_LOCKS_REQUIRED(mutex_);
158 void SaveRewriteForRetry(Rewrite* rewrite) EXCLUSIVE_LOCKS_REQUIRED(mutex_);
162 void ConsiderDroppingRetry() EXCLUSIVE_LOCKS_REQUIRED(mutex_);
167 Rewrite* GetRewrite(
const GoogleString& key) EXCLUSIVE_LOCKS_REQUIRED(mutex_);
170 void DeleteRewrite(
const Rewrite* rewrite) EXCLUSIVE_LOCKS_REQUIRED(mutex_);
173 void SetMaxQueueSizeForTesting(
int size) LOCKS_EXCLUDED(mutex_);
178 RewriteMap all_rewrites_ GUARDED_BY(mutex_);
188 int running_rewrites_ GUARDED_BY(mutex_);
189 const int max_running_rewrites_;
191 int max_queued_rewrites_ GUARDED_BY(mutex_);
202 friend class PopularityContestScheduleRewriteControllerTest;
Definition: priority_queue.h:37
Definition: popularity_contest_schedule_rewrite_controller.h:79
PopularityContestScheduleRewriteController(ThreadSystem *thread_system, Statistics *statistics, Timer *timer, int max_running_rewrites, int max_queued_rewrites)
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
void ScheduleRewrite(const GoogleString &key, Function *callback) override
ScheduleRewriteController interface.
void NotifyRewriteComplete(const GoogleString &key) override
Definition: scoped_ptr.h:30
Definition: function.h:47
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: thread_system.h:40
Definition: statistics.h:73
Definition: statistics.h:298
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
Definition: schedule_rewrite_controller.h:30