private static InternalScriptContext getGrinderInstance() { InternalScriptContext grinder = Grinder.grinder; if (grinder == null || grinder.getThreadNumber() == -1) { throw new RuntimeException("This method should be called in the worker thread context."); } return grinder; }
@Override public void awaitStart() { int waitingTime = doRampUp(); int threadNumber = 0; if (Grinder.grinder != null) { threadNumber = Math.max(Grinder.grinder.getThreadNumber(), 0); } synchronized (m_threadEventCondition) { m_numberAwaitingStart++; m_numberRunning++; m_threadEventCondition.notifyAll(); } if (Grinder.grinder != null) { Grinder.grinder.getLogger().info("thread-{} is invoked after {} ms sleep", threadNumber, waitingTime); } // m_started.await(true); }
private int doRampUp(int rampUpInterval, int rampUpStep, int rampUpInitialThread, int rampUpInitialSleep) { int threadNumber = 0; int waitingTime; if (Grinder.grinder != null) { threadNumber = Math.max(Grinder.grinder.getThreadNumber(), 0); } try { waitingTime = getWaitingTime(rampUpInterval, rampUpStep, rampUpInitialThread, rampUpInitialSleep, threadNumber); if (waitingTime != 0) { if (Grinder.grinder != null) { Grinder.grinder.getLogger().info("thread-{} is sleeping {} ms for ramp-up", threadNumber, waitingTime); } sleeper.sleepNormal(waitingTime, 0); } return waitingTime; } catch (Sleeper.ShutdownException e) { throw new RuntimeException(e); } }
/** * Get this thread unique id among all threads in the all agents. * * @return unique id b/w from 0 to total thread count. * @since 3.2.3 */ public static int getThreadUniqId() { InternalScriptContext grinder = getGrinderInstance(); GrinderProperties properties = grinder.getProperties(); if (properties != null) { int totalProcessCount = properties.getInt("grinder.processes", 1); int totalThreadCount = properties.getInt("grinder.threads", 1); int agentNumber = grinder.getAgentNumber(); int processNumber = grinder.getProcessNumber(); int threadNumber = grinder.getThreadNumber(); // Calc the current thread's unique id return (agentNumber * totalProcessCount * totalThreadCount) + (processNumber * totalThreadCount) + threadNumber; } return 0; }