@@ -53,7 +53,7 @@ public class Engine {
5353 /** The run thread. */
5454// public static TestRunThread runThread;
5555 public static List <TestRunThread > testRunThreads = new ArrayList <>();
56-
56+ private static final int IDEAL_TUPLE_SIZE = 20 ;
5757
5858 static {
5959 SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd HHmmss" );
@@ -311,31 +311,29 @@ public static List<Future<List<Future<Object>>>> runRampUp(ExecutorService execu
311311 throw new KiteGridException ("Looks like the grid is not up, no hub IP or DNS was provided." );
312312 }
313313 testConfig .setNoOfThreads (paasList .size ());
314- HashMap <Client , Integer > incrementMap = getIncrementMap (clients , testConfig .getIncrement ());
315314 testRunThreads .clear ();
315+
316316 for (Client client : clients ) {
317- List <Paas > paasWithProfile = getPaasWithProfile (paasList , client );
318- int increment = incrementMap .get (client );
319- int numberOfHub = paasWithProfile .size ();
320- int incrementPerHub = (int ) Math .ceil (increment /numberOfHub );
321- int countPerHub = (int ) Math .ceil (client .getCount ()/numberOfHub );
322- int numberOfIterationPerHub = countPerHub /incrementPerHub ;
323- int leftoverPerHub = countPerHub %incrementPerHub ;
324- logger .info ("***********************************************************" );
317+ CircularLinkedList <Paas > paasWithProfile = getPaasWithProfile (paasList , client );
318+ int increment = testConfig .getIncrement ();
319+ int numberOfIteration = (int ) Math .floor (client .getCount ()/increment );
320+ int leftOver = client .getCount () - increment *numberOfIteration ;
325321 logger .info ("SUMMARY----------------------------------------------------" );
326322 logger .info ("Current client is: " + client .toString ());
327- logger .info ("Running " + numberOfHub + " threads on " + numberOfHub + " hubs, one per hub, with increment per hub: " + incrementPerHub );
328- logger .info ("Total number of iterations per hub: " + numberOfIterationPerHub );
323+ logger .info ("Increment: " + increment );
324+ logger .info ("The client will be distributed evenly into every grids in round-robin fashion" );
329325 logger .info ("END OF SUMMARY---------------------------------------------" );
330- int count = 0 ;
331- for (int iterationCount = 0 ; iterationCount < numberOfIterationPerHub ; iterationCount ++) {
326+ for (int iterationCount = 0 ; iterationCount < numberOfIteration ; iterationCount ++) {
332327 List <Tuple > tupleList = new ArrayList <>();
333-
334- for (Paas paas : paasWithProfile ) {
335- client .setPaas (paas );
336- Tuple tuple = new Tuple (client , incrementPerHub );
328+ if (increment > IDEAL_TUPLE_SIZE ) {
329+ tupleList = getSmallerTuple (paasWithProfile , client , increment , IDEAL_TUPLE_SIZE );
330+ } else {
331+ Tuple tuple = new Tuple ();
332+ for (int count = 0 ; count < increment ; count ++) {
333+ client .setPaas (paasWithProfile .get ());
334+ tuple .add (client );
335+ }
337336 tupleList .add (tuple );
338- count += incrementPerHub ;
339337 }
340338
341339 TestRunThread runThread = new TestRunThread (testConfig , tupleList );
@@ -344,18 +342,23 @@ public static List<Future<List<Future<Object>>>> runRampUp(ExecutorService execu
344342 testRunThreads .add (runThread );
345343 }
346344
347- if (leftoverPerHub > 0 ) {
348- for (Paas paas : paasWithProfile ) {
349- client .setPaas (paas );
350- List <Tuple > tupleList = new ArrayList <>();
351- Tuple tuple = new Tuple (client , leftoverPerHub );
345+ if (leftOver > 0 ) {
346+ List <Tuple > tupleList = new ArrayList <>();
347+ if (leftOver > IDEAL_TUPLE_SIZE ) {
348+ tupleList = getSmallerTuple (paasWithProfile , client , leftOver , IDEAL_TUPLE_SIZE );
349+ } else {
350+ Tuple tuple = new Tuple ();
351+ for (int count = 0 ; count < leftOver ; count ++) {
352+ client .setPaas (paasWithProfile .get ());
353+ tuple .add (client );
354+ }
352355 tupleList .add (tuple );
353- TestRunThread runThread = new TestRunThread (testConfig , tupleList );
354- runThread .setName (testSuiteName );
355- runThread .setCurrentIteration (count );
356- testRunThreads .add (runThread );
357- count += leftoverPerHub ;
358356 }
357+
358+ TestRunThread runThread = new TestRunThread (testConfig , tupleList );
359+ runThread .setName (testSuiteName );
360+ runThread .setCurrentIteration (increment *numberOfIteration );
361+ testRunThreads .add (runThread );
359362 }
360363 }
361364
@@ -365,7 +368,31 @@ public static List<Future<List<Future<Object>>>> runRampUp(ExecutorService execu
365368 return res ;
366369 }
367370
368- public static List <Paas > getPaasWithProfile (List <Paas > originalList , Client client ) {
371+ private static List <Tuple > getSmallerTuple (CircularLinkedList <Paas > paasList , Client client , int originalTupleSize , int idealTupleSize ) {
372+ List <Tuple > tupleList = new ArrayList <>();
373+ int tupleCount = originalTupleSize /idealTupleSize ;
374+ int leftOver = originalTupleSize - idealTupleSize *tupleCount ;
375+
376+ for (int i = 0 ; i < tupleCount ; i ++) {
377+ Tuple tuple = new Tuple ();
378+ for (int j = 0 ; j < idealTupleSize ; j ++) {
379+ client .setPaas (paasList .get ());
380+ tuple .add (client );
381+ }
382+ tupleList .add (tuple );
383+ }
384+ if (leftOver > 0 ) {
385+ Tuple tuple = new Tuple ();
386+ for (int j = 0 ; j < leftOver ; j ++) {
387+ client .setPaas (paasList .get ());
388+ tuple .add (client );
389+ }
390+ tupleList .add (tuple );
391+ }
392+ return tupleList ;
393+ }
394+
395+ public static CircularLinkedList <Paas > getPaasWithProfile (List <Paas > originalList , Client client ) {
369396
370397 List <Paas > res = new ArrayList <>();
371398 for (Paas paas : originalList ) {
@@ -379,7 +406,7 @@ public static List<Paas> getPaasWithProfile(List<Paas> originalList, Client clie
379406 }
380407// }
381408 }
382- return res ;
409+ return new CircularLinkedList < Paas >( res ) ;
383410 }
384411
385412 private static HashMap <Client , Integer > getIncrementMap (List <Client > clients , int totalIncrement ) {
@@ -389,8 +416,7 @@ private static HashMap<Client, Integer> getIncrementMap(List<Client> clients, in
389416 totalCount += client .getCount ();
390417 }
391418 for (Client client : clients ) {
392- int ratio = client .getCount ()/totalCount ;
393- map .put (client , ratio *totalIncrement );
419+ map .put (client , client .getCount ()*totalIncrement /totalCount );
394420 }
395421 return map ;
396422 }
0 commit comments