Created
November 27, 2018 05:19
-
-
Save Warchant/588227f0418c4e4519c299826e046b88 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package jp.co.soramitsu.iroha.testcontainers; | |
| import iroha.protocol.TransactionOuterClass; | |
| import java.io.FileNotFoundException; | |
| import java.io.PrintWriter; | |
| import java.util.Collections; | |
| import java.util.LinkedList; | |
| import java.util.List; | |
| import java.util.stream.Collectors; | |
| import java.util.stream.IntStream; | |
| import java.util.stream.Stream; | |
| import jp.co.soramitsu.crypto.ed25519.Ed25519Sha3; | |
| import jp.co.soramitsu.iroha.java.IrohaAPI; | |
| import jp.co.soramitsu.iroha.java.Transaction; | |
| import jp.co.soramitsu.iroha.testcontainers.detail.GenesisBlockBuilder; | |
| import jp.co.soramitsu.iroha.testcontainers.detail.IrohaConfig; | |
| import jp.co.soramitsu.iroha.testcontainers.network.IrohaNetwork; | |
| import lombok.Data; | |
| import lombok.ToString; | |
| import lombok.val; | |
| import org.junit.Test; | |
| public class Example { | |
| @Data | |
| @ToString | |
| private static class Measurement { | |
| int proposalDelay; | |
| int transactionNumber; | |
| long elapsedTime; | |
| int peerN; | |
| String status; | |
| } | |
| private List<Measurement> measurements = Collections.synchronizedList(new LinkedList<>()); | |
| private TransactionOuterClass.Transaction createAccount(String name) { | |
| val keypair = new Ed25519Sha3().generateKeypair(); | |
| return Transaction.builder(GenesisBlockBuilder.defaultAccountId) | |
| .createAccount(name, GenesisBlockBuilder.defaultDomainName, keypair.getPublic()) | |
| .sign(GenesisBlockBuilder.defaultKeyPair) | |
| .build(); | |
| } | |
| @Test | |
| public void test() throws FileNotFoundException { | |
| PrintWriter pw = new PrintWriter("/tmp/experiment.csv"); | |
| pw.write( | |
| String.join(",", "proposal_delay", "txn", "elapsed_time", "total_peers") + "\n" | |
| ); | |
| IntStream.of(100) /* proposal_delay */ | |
| .boxed() | |
| .forEach(proposalDelay -> { | |
| IntStream.range(1, 7) | |
| .boxed() | |
| .map(IrohaNetwork::new) | |
| .forEach(nw -> { | |
| IrohaConfig ic = IrohaConfig.builder() | |
| .proposal_delay(proposalDelay /* ms */) | |
| .build(); | |
| nw.withLogger(null /* disable logging */) | |
| .withIrohaConfig(ic) | |
| .addDefaultTransaction() | |
| .start(); /* blocking */ | |
| List<IrohaAPI> apis = nw.getApis(); | |
| IrohaAPI first = apis.get(0); | |
| int totalPeers = nw.getPeers().size(); | |
| IntStream.range(0, 1000) | |
| .boxed() | |
| .parallel() | |
| .forEach(n -> { | |
| String name = Integer.toString(n); | |
| val tx = createAccount(name); | |
| val m = new Measurement(); | |
| m.setProposalDelay(proposalDelay); | |
| m.setTransactionNumber(n); | |
| m.setPeerN(totalPeers); | |
| try { | |
| long startTime = System.currentTimeMillis(); | |
| first.transaction(tx).blockingSubscribe(); | |
| long stopTime = System.currentTimeMillis(); | |
| long elapsedTime = stopTime - startTime; | |
| m.setElapsedTime(elapsedTime); | |
| m.setStatus("SUCCESS"); | |
| } catch (Exception e) { | |
| m.setElapsedTime(0); | |
| m.setStatus("\"" + e.toString() + "\""); | |
| } | |
| measurements.add(m); | |
| System.out.println(m); | |
| pw.write( | |
| Stream.of(m.proposalDelay, m.transactionNumber, m.elapsedTime, m.peerN) | |
| .map(String::valueOf) | |
| .collect(Collectors.joining(",")) + "\n" | |
| ); | |
| pw.flush(); | |
| }); | |
| nw.stop(); | |
| }); | |
| }); | |
| pw.close(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment