| 1 | |
package kg.apc.jmeter.threads; |
| 2 | |
|
| 3 | |
import org.apache.log.Logger; |
| 4 | |
|
| 5 | |
import org.apache.jmeter.threads.JMeterThread; |
| 6 | |
import org.apache.jorphan.logging.LoggingManager; |
| 7 | |
|
| 8 | |
public class SteppingThreadGroup |
| 9 | |
extends AbstractSimpleThreadGroup { |
| 10 | |
|
| 11 | 1 | private static final Logger log = LoggingManager.getLoggerForClass(); |
| 12 | |
private static final String THREAD_GROUP_DELAY = "Threads initial delay"; |
| 13 | |
private static final String INC_USER_PERIOD = "Start users period"; |
| 14 | |
private static final String INC_USER_COUNT = "Start users count"; |
| 15 | |
private static final String INC_USER_COUNT_BURST = "Start users count burst"; |
| 16 | |
private static final String DEC_USER_PERIOD = "Stop users period"; |
| 17 | |
private static final String DEC_USER_COUNT = "Stop users count"; |
| 18 | |
private static final String FLIGHT_TIME = "flighttime"; |
| 19 | |
private static final String RAMPUP = "rampUp"; |
| 20 | |
|
| 21 | |
public SteppingThreadGroup() { |
| 22 | 36 | super(); |
| 23 | 36 | } |
| 24 | |
|
| 25 | |
@Override |
| 26 | |
protected void scheduleThread(JMeterThread thread, long tgStartTime) { |
| 27 | |
|
| 28 | 616 | int inUserCount = getInUserCountAsInt(); |
| 29 | 616 | int outUserCount = getOutUserCountAsInt(); |
| 30 | |
|
| 31 | 616 | if (inUserCount == 0) { |
| 32 | 0 | inUserCount = getNumThreads(); |
| 33 | |
} |
| 34 | 616 | if (outUserCount == 0) { |
| 35 | 16 | outUserCount = getNumThreads(); |
| 36 | |
} |
| 37 | |
|
| 38 | 616 | int inUserCountBurst = Math.min(getInUserCountBurstAsInt(), getNumThreads()); |
| 39 | 616 | if (inUserCountBurst <= 0) { |
| 40 | 601 | inUserCountBurst = inUserCount; |
| 41 | |
} |
| 42 | |
|
| 43 | 616 | int rampUpBucket = thread.getThreadNum() < inUserCountBurst ? 0 |
| 44 | 545 | : 1 + (thread.getThreadNum() - inUserCountBurst) / inUserCount; |
| 45 | 616 | int rampUpBucketThreadCount = thread.getThreadNum() < inUserCountBurst ? inUserCountBurst : inUserCount; |
| 46 | |
|
| 47 | 616 | long threadGroupDelay = 1000L * getThreadGroupDelayAsInt(); |
| 48 | 616 | long ascentPoint = tgStartTime + threadGroupDelay; |
| 49 | 616 | long inUserPeriod = 1000L * getInUserPeriodAsInt(); |
| 50 | 616 | long additionalRampUp = 1000L * getRampUpAsInt() / rampUpBucketThreadCount; |
| 51 | 616 | long flightTime = 1000L * getFlightTimeAsInt(); |
| 52 | 616 | long outUserPeriod = 1000L * getOutUserPeriodAsInt(); |
| 53 | |
|
| 54 | 616 | long rampUpDuration = 1000L * getRampUpAsInt(); |
| 55 | 616 | long iterationDuration = inUserPeriod + rampUpDuration; |
| 56 | |
|
| 57 | 616 | int iterationCountTotal = getNumThreads() < inUserCountBurst ? 1 |
| 58 | 616 | : (int) Math.ceil((double) (getNumThreads() - inUserCountBurst) / inUserCount); |
| 59 | |
|
| 60 | 616 | int lastIterationUserCount = (getNumThreads() - inUserCountBurst) % inUserCount; |
| 61 | 616 | if (lastIterationUserCount == 0) { |
| 62 | 616 | lastIterationUserCount = inUserCount; |
| 63 | |
} |
| 64 | 616 | long descentPoint = ascentPoint + iterationCountTotal * iterationDuration + (1000L * getRampUpAsInt() / inUserCount) * lastIterationUserCount + flightTime; |
| 65 | |
|
| 66 | 616 | long rampUpBucketStartTime = ascentPoint + rampUpBucket * iterationDuration; |
| 67 | 616 | int rampUpBucketThreadPosition = thread.getThreadNum() < inUserCountBurst ? thread.getThreadNum() |
| 68 | 545 | : (thread.getThreadNum() - inUserCountBurst) % inUserCount; |
| 69 | |
|
| 70 | 616 | long startTime = rampUpBucketStartTime + rampUpBucketThreadPosition * additionalRampUp; |
| 71 | 616 | long endTime = descentPoint + outUserPeriod * (int) Math.floor((double) thread.getThreadNum() / outUserCount); |
| 72 | |
|
| 73 | 1232 | log.debug(String.format("threadNum=%d, rampUpBucket=%d, rampUpBucketThreadCount=%d, rampUpBucketStartTime=%d, rampUpBucketThreadPosition=%d, rampUpDuration=%d, iterationDuration=%d, iterationCountTotal=%d, ascentPoint=%d, descentPoint=%d, startTime=%d, endTime=%d", |
| 74 | 616 | thread.getThreadNum(), rampUpBucket, rampUpBucketThreadCount, rampUpBucketStartTime, rampUpBucketThreadPosition, rampUpDuration, iterationDuration, iterationCountTotal, ascentPoint, descentPoint, startTime, endTime)); |
| 75 | |
|
| 76 | 616 | thread.setStartTime(startTime); |
| 77 | 616 | thread.setEndTime(endTime); |
| 78 | 616 | thread.setScheduled(true); |
| 79 | 616 | } |
| 80 | |
|
| 81 | |
public String getThreadGroupDelay() { |
| 82 | 2 | return getPropertyAsString(THREAD_GROUP_DELAY); |
| 83 | |
} |
| 84 | |
|
| 85 | |
public void setThreadGroupDelay(String delay) { |
| 86 | 9 | setProperty(THREAD_GROUP_DELAY, delay); |
| 87 | 9 | } |
| 88 | |
|
| 89 | |
public String getInUserPeriod() { |
| 90 | 2 | return getPropertyAsString(INC_USER_PERIOD); |
| 91 | |
} |
| 92 | |
|
| 93 | |
public void setInUserPeriod(String value) { |
| 94 | 9 | setProperty(INC_USER_PERIOD, value); |
| 95 | 9 | } |
| 96 | |
|
| 97 | |
public String getInUserCount() { |
| 98 | 2 | return getPropertyAsString(INC_USER_COUNT); |
| 99 | |
} |
| 100 | |
|
| 101 | |
public void setInUserCount(String delay) { |
| 102 | 9 | setProperty(INC_USER_COUNT, delay); |
| 103 | 9 | } |
| 104 | |
|
| 105 | |
public String getInUserCountBurst() { |
| 106 | 2 | return getPropertyAsString(INC_USER_COUNT_BURST); |
| 107 | |
} |
| 108 | |
|
| 109 | |
public void setInUserCountBurst(String text) { |
| 110 | 9 | setProperty(INC_USER_COUNT_BURST, text); |
| 111 | 9 | } |
| 112 | |
|
| 113 | |
public String getFlightTime() { |
| 114 | 2 | return getPropertyAsString(FLIGHT_TIME); |
| 115 | |
} |
| 116 | |
|
| 117 | |
public void setFlightTime(String delay) { |
| 118 | 9 | setProperty(FLIGHT_TIME, delay); |
| 119 | 9 | } |
| 120 | |
|
| 121 | |
public String getOutUserPeriod() { |
| 122 | 2 | return getPropertyAsString(DEC_USER_PERIOD); |
| 123 | |
} |
| 124 | |
|
| 125 | |
public void setOutUserPeriod(String delay) { |
| 126 | 7 | setProperty(DEC_USER_PERIOD, delay); |
| 127 | 7 | } |
| 128 | |
|
| 129 | |
public String getOutUserCount() { |
| 130 | 2 | return getPropertyAsString(DEC_USER_COUNT); |
| 131 | |
} |
| 132 | |
|
| 133 | |
public void setOutUserCount(String delay) { |
| 134 | 7 | setProperty(DEC_USER_COUNT, delay); |
| 135 | 7 | } |
| 136 | |
|
| 137 | |
public String getRampUp() { |
| 138 | 2 | return getPropertyAsString(RAMPUP); |
| 139 | |
} |
| 140 | |
|
| 141 | |
public void setRampUp(String delay) { |
| 142 | 9 | setProperty(RAMPUP, delay); |
| 143 | 9 | } |
| 144 | |
|
| 145 | |
public int getThreadGroupDelayAsInt() { |
| 146 | 620 | return getPropertyAsInt(THREAD_GROUP_DELAY); |
| 147 | |
} |
| 148 | |
|
| 149 | |
public int getInUserPeriodAsInt() { |
| 150 | 617 | return getPropertyAsInt(INC_USER_PERIOD); |
| 151 | |
} |
| 152 | |
|
| 153 | |
public int getInUserCountAsInt() { |
| 154 | 620 | return getPropertyAsInt(INC_USER_COUNT); |
| 155 | |
} |
| 156 | |
|
| 157 | |
public int getInUserCountBurstAsInt() { |
| 158 | 617 | return getPropertyAsInt(INC_USER_COUNT_BURST); |
| 159 | |
} |
| 160 | |
|
| 161 | |
public int getRampUpAsInt() { |
| 162 | 1849 | return getPropertyAsInt(RAMPUP); |
| 163 | |
} |
| 164 | |
|
| 165 | |
public int getFlightTimeAsInt() { |
| 166 | 617 | return getPropertyAsInt(FLIGHT_TIME); |
| 167 | |
} |
| 168 | |
|
| 169 | |
public int getOutUserPeriodAsInt() { |
| 170 | 617 | return getPropertyAsInt(DEC_USER_PERIOD); |
| 171 | |
} |
| 172 | |
|
| 173 | |
public int getOutUserCountAsInt() { |
| 174 | 620 | return getPropertyAsInt(DEC_USER_COUNT); |
| 175 | |
} |
| 176 | |
|
| 177 | |
public void setNumThreads(String execute) { |
| 178 | 4 | setProperty(NUM_THREADS, execute); |
| 179 | 4 | } |
| 180 | |
|
| 181 | |
public String getNumThreadsAsString() { |
| 182 | 2 | return getPropertyAsString(NUM_THREADS); |
| 183 | |
} |
| 184 | |
} |