DomGarguilo commented on issue #2165:
URL: https://github.com/apache/accumulo/issues/2165#issuecomment-895476936
I set up some crude performance tests to see what the difference is between
the normal byte streams and the Unsynchronized variants. From what I can tell
the Unsynchronized byte streams are slower. I set up identical loops in which I
created a `UnsynchronizedByteArrayOutputStream`/`ByteArrayOutputStream` wraped
it in a `DataOutputStream` then wrote to it (String, int and double each tested
separately). Then created a
`ByteArrayInputStream`/`UnsynchronizedByteArrayInputStream` wraped in a
`DataInputStream` and read from it, asserting that the sent and received data
matched each time. From my data the Unsynchronized version ran on average ~60ms
where as the regular streams ran at an average of ~45ms. Below is the code I
used to test.
<details closed>
<summary>Code</summary>
```java
@Test
public void testUnsyncEncodeDecode() throws IOException {
long start = System.currentTimeMillis();
for (int i = 0; i < 10_000; i++) {
try (UnsynchronizedByteArrayOutputStream baos = new
UnsynchronizedByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos)) {
String out = getRandomString();
dos.writeUTF(out);
try (
UnsynchronizedByteArrayInputStream bais =
new UnsynchronizedByteArrayInputStream(baos.toByteArray());
DataInputStream dis = new DataInputStream(bais)) {
String in = dis.readUTF();
assertEquals(in, out);
}
}
try (UnsynchronizedByteArrayOutputStream baos = new
UnsynchronizedByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos)) {
int out = random.nextInt();
dos.writeInt(out);
try (
UnsynchronizedByteArrayInputStream bais =
new UnsynchronizedByteArrayInputStream(baos.toByteArray());
DataInputStream dis = new DataInputStream(bais)) {
int in = dis.readInt();
assertEquals(in, out);
}
}
try (UnsynchronizedByteArrayOutputStream baos = new
UnsynchronizedByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos)) {
double out = random.nextDouble();
dos.writeDouble(out);
try (
UnsynchronizedByteArrayInputStream bais =
new UnsynchronizedByteArrayInputStream(baos.toByteArray());
DataInputStream dis = new DataInputStream(bais)) {
double in = dis.readDouble();
assertEquals(in, out, 0.001);
}
}
}
long finish = System.currentTimeMillis();
System.out.println("time taken: " + (finish - start));
}
@Test
public void testClassicEncodeDecode() throws IOException {
long start = System.currentTimeMillis();
for (int i = 0; i < 10_000; i++) {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos)) {
String out = getRandomString();
dos.writeUTF(out);
try (ByteArrayInputStream bais = new
ByteArrayInputStream(baos.toByteArray());
DataInputStream dis = new DataInputStream(bais)) {
String in = dis.readUTF();
assertEquals(in, out);
}
}
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos)) {
int out = random.nextInt();
dos.writeInt(out);
try (ByteArrayInputStream bais = new
ByteArrayInputStream(baos.toByteArray());
DataInputStream dis = new DataInputStream(bais)) {
int in = dis.readInt();
assertEquals(in, out);
}
}
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos)) {
double out = random.nextDouble();
dos.writeDouble(out);
try (ByteArrayInputStream bais = new
ByteArrayInputStream(baos.toByteArray());
DataInputStream dis = new DataInputStream(bais)) {
double in = dis.readDouble();
assertEquals(in, out, 0.001);
}
}
}
long finish = System.currentTimeMillis();
System.out.println("time taken: " + (finish - start));
}
```
</details>
I'm not sure if this kind of testing is helpful, just thought I would pass
along my findings.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]