forked from openmessaging/benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added payload and key interfaces (openmessaging#21)
* added payload reader * added keydistributor (round robin & random) * refactoring * added payload file for 3 producers
- Loading branch information
Showing
32 changed files
with
490 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...-framework/src/main/java/io/openmessaging/benchmark/utils/distributor/KeyDistributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.openmessaging.benchmark.utils.distributor; | ||
|
||
import com.google.common.io.BaseEncoding; | ||
|
||
import java.util.Random; | ||
|
||
public abstract class KeyDistributor { | ||
|
||
private static final int UNIQUE_COUNT = 10_000; | ||
private static final int KEY_BYTE_SIZE = 7; | ||
|
||
private static final String[] randomKeys = new String[UNIQUE_COUNT]; | ||
private static final Random random = new Random(); | ||
|
||
static { | ||
// Generate a number of random keys to be used when publishing | ||
byte[] buffer = new byte[KEY_BYTE_SIZE]; | ||
for (int i = 0; i < randomKeys.length; i++) { | ||
random.nextBytes(buffer); | ||
randomKeys[i] = BaseEncoding.base64Url().omitPadding().encode(buffer); | ||
} | ||
} | ||
|
||
protected String get(int index) { | ||
return randomKeys[index]; | ||
} | ||
|
||
protected int getLength() { | ||
return UNIQUE_COUNT; | ||
} | ||
|
||
public abstract String next(); | ||
|
||
public static KeyDistributor build(KeyDistributorType keyType) { | ||
KeyDistributor keyDistributor = null; | ||
switch (keyType) { | ||
case ROUND_ROBIN: | ||
keyDistributor = new RoundRobin(); | ||
break; | ||
case RANDOM_NANO: | ||
keyDistributor = new RandomNano(); | ||
break; | ||
} | ||
return keyDistributor; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...mework/src/main/java/io/openmessaging/benchmark/utils/distributor/KeyDistributorType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.openmessaging.benchmark.utils.distributor; | ||
|
||
import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; | ||
|
||
public enum KeyDistributorType { | ||
@JsonEnumDefaultValue | ||
ROUND_ROBIN, | ||
RANDOM_NANO, | ||
} |
30 changes: 30 additions & 0 deletions
30
...mark-framework/src/main/java/io/openmessaging/benchmark/utils/distributor/RandomNano.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.openmessaging.benchmark.utils.distributor; | ||
|
||
import javax.annotation.concurrent.ThreadSafe; | ||
|
||
@ThreadSafe | ||
public class RandomNano extends KeyDistributor { | ||
|
||
public String next() { | ||
int randomIndex = Math.abs((int) System.nanoTime() % getLength()); | ||
return get(randomIndex); | ||
} | ||
} |
Oops, something went wrong.