1 /*
2  * Copyright (c) 2001 by Matt Welsh and The Regents of the University of
3  * California. All rights reserved.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation for any purpose, without fee, and without written agreement is
7  * hereby granted, provided that the above copyright notice and the following
8  * two paragraphs appear in all copies of this software.
9  *
10  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
11  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
12  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
13  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
16  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
18  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
19  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
20  *
21  * Author: Matt Welsh <mdw@cs.berkeley.edu>
22  *
23  */
24 
25 package seda.sandStorm.internal;
26 
27 import seda.sandStorm.api.*;
28 import seda.sandStorm.api.internal.*;
29 import seda.sandStorm.core.*;
30 import seda.sandStorm.main.*;
31 import java.util.*;
32 
33 /**
34  * The ResponseTimeController attempts to keep the response time of
35  * a given stage below a given target by adjusting admission control
36  * parameters for a stage.
37  *
38  * @author   Matt Welsh
39  */
40 public abstract class ResponseTimeController implements ResponseTimeControllerIF {
41 
42   protected final static int INIT_THRESHOLD = 1;
43   protected final static int MIN_THRESHOLD = 1;
44   protected final static int MAX_THRESHOLD = 1024;
45 
46   protected StageWrapperIF stage;
47   protected EnqueuePredicateIF pred;
48   protected double targetRT;
49 
ResponseTimeController(ManagerIF mgr, StageWrapperIF stage)50   protected ResponseTimeController(ManagerIF mgr, StageWrapperIF stage) throws IllegalArgumentException {
51     this.stage = stage;
52 
53     SandstormConfig config = mgr.getConfig();
54     this.targetRT = config.getDouble("stages."+stage.getStage().getName()+".rtController.targetResponseTime");
55     if (this.targetRT == -1) {
56       this.targetRT = config.getDouble("global.rtController.targetResponseTime");
57       if (this.targetRT == -1) {
58 	throw new IllegalArgumentException("ResponseTimeController: Must specify targetResponseTime");
59       }
60     }
61   }
62 
setTarget(double target)63   public void setTarget(double target) {
64     this.targetRT = target;
65   }
66 
getTarget()67   public double getTarget() {
68     return targetRT;
69   }
70 
adjustThreshold(QueueElementIF fetched[], long serviceTime)71   public abstract void adjustThreshold(QueueElementIF fetched[], long serviceTime);
enable()72   public abstract void enable();
disable()73   public abstract void disable();
74 
75 }
76