~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/pagespeed/kernel/cache/cache_spammer.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2010 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
 
// Author: jmarantz@google.com (Joshua Marantz)
17
 
 
18
 
// Helper class for sending concurrent traffic to a cache during unit tests.
19
 
 
20
 
#ifndef PAGESPEED_KERNEL_CACHE_CACHE_SPAMMER_H_
21
 
#define PAGESPEED_KERNEL_CACHE_CACHE_SPAMMER_H_
22
 
 
23
 
#include "pagespeed/kernel/base/basictypes.h"
24
 
#include "pagespeed/kernel/base/thread.h"
25
 
#include "pagespeed/kernel/base/thread_system.h"
26
 
 
27
 
namespace net_instaweb {
28
 
 
29
 
class CacheInterface;
30
 
 
31
 
// Helper class for blasting a cache with concurrent requests.  Refactored
32
 
// from threadsafe_cache_test.cc.
33
 
class CacheSpammer : public ThreadSystem::Thread {
34
 
 public:
35
 
  virtual ~CacheSpammer();
36
 
 
37
 
  // value_pattern will be used as a format string, and must have a single %d.
38
 
  // num_threads indicates how many threads will run in parallel.
39
 
  // num_iters indicates how many times each thread will run a big loop.
40
 
  // num_inserts sets the number of keys inserted and looked up in the loop.
41
 
  //
42
 
  // num_iters will be divided down by 100 when running on valgrind.
43
 
  static void RunTests(int num_threads, int num_iters, int num_inserts,
44
 
                       bool expecting_evictions, bool do_deletes,
45
 
                       const char* value_pattern,
46
 
                       CacheInterface* cache,
47
 
                       ThreadSystem* thread_runtime);
48
 
 
49
 
 protected:
50
 
  virtual void Run();
51
 
 
52
 
 private:
53
 
  CacheSpammer(ThreadSystem* runtime,
54
 
               ThreadSystem::ThreadFlags flags,
55
 
               CacheInterface* cache,
56
 
               bool expecting_evictions,
57
 
               bool do_deletes,
58
 
               const char* value_pattern,
59
 
               int index,
60
 
               int num_iters,
61
 
               int num_inserts);
62
 
 
63
 
  CacheInterface* cache_;
64
 
  bool expecting_evictions_;
65
 
  bool do_deletes_;
66
 
  const char* value_pattern_;
67
 
  int index_;
68
 
  int num_iters_;
69
 
  int num_inserts_;
70
 
 
71
 
  DISALLOW_COPY_AND_ASSIGN(CacheSpammer);
72
 
};
73
 
 
74
 
}  // namespace net_instaweb
75
 
 
76
 
#endif  // PAGESPEED_KERNEL_CACHE_CACHE_SPAMMER_H_