Skip to content

Commit ad47973

Browse files
authored
architecture revamp: improved performance, nonblocking queue... (#94)
* [sender] use concurrent linked queue - non-blocking - to message enqueueing * [tests] fix integration testing * comment * [sender] sleep less * [sender] decrement when taking message from queue * [test] add max throughput performance test * [travis] actually do run tests * [test] fix test teardown * sender: we should only need to get the address once * parametrize test workers * Adding buffer pool and multi-worker sender * [buffer] fixes * [test] max_perf: default q-size 1024 * improve interruption handling behavior + collateral * [client] adding more constructors for woker configurability * [test] make max perf test parametric * [maven] add surefire plugin + heap args * [test] make max performance test less memory intensive + remove unbounded queue test * [maven] bump surefire * abstract class and blocking+nonblocking processor * better construction + class abstractions * [test] fix them - less is more * [processor] multi-worker support * blocking processor: remove unused imports * [test] we can reuse port, support more scenarios * [maven] add checkstyle * [maven] add checkstyle * [checkstyle] fix all checkstyle offenses * [javadoc] fix issues with javadoc * [mvn] silence illegal access warning; not real. * [travis] attempt to checkstyle with a different version on Java7 * removing unused imports. * [mvn] support up to Java 13.0.2. * [circleci] add openjdk13 to test matrix * [circleci] no checkstyle on java7 + remove travis (#100) * [circleci] no checkstyle on java7 * [travis] get off travis
1 parent 4e00413 commit ad47973

24 files changed

+1884
-913
lines changed

.circleci/config.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,30 @@ default_steps: &default_steps
1818
- ~/.m2
1919
key: v1-dependencies-{{ checksum "pom.xml" }}
2020
- run: |
21-
mvn clean install -Dgpg.skip
21+
mvn clean install -Dgpg.skip $MVN_EXTRA_OPTS
2222
2323
jobs:
2424
openjdk7:
2525
docker:
26-
- image: jfullaondo/openjdk:7
26+
- image: jfullaondo/openjdk:7
27+
environment:
28+
MVN_EXTRA_OPTS: -Dcheckstyle.version=2.15 -Dcheckstyle.skip
2729
<<: *default_steps
2830
openjdk8:
2931
docker:
30-
- image: circleci/openjdk:8u242
32+
- image: circleci/openjdk:8u242
3133
<<: *default_steps
3234
openjdk9:
3335
docker:
34-
- image: circleci/openjdk:9.0.4-12
36+
- image: circleci/openjdk:9.0.4-12
3537
<<: *default_steps
3638
openjdk11:
3739
docker:
38-
- image: circleci/openjdk:11.0.2
40+
- image: circleci/openjdk:11.0.2
41+
<<: *default_steps
42+
openjdk13:
43+
docker:
44+
- image: circleci/openjdk:13.0.2-buster
3945
<<: *default_steps
4046

4147
workflows:
@@ -46,3 +52,4 @@ workflows:
4652
- openjdk8
4753
- openjdk9
4854
- openjdk11
55+
- openjdk13

.travis.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

pom.xml

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
<java.version>1.6</java.version>
15+
<!-- Note: using project checkstyle with AOSP style
16+
find the default google java checkstyle config here -
17+
<checkstyle.config.location>google_checks.xml</checkstyle.config.location>
18+
-->
19+
<checkstyle.config.location>style.xml</checkstyle.config.location>
20+
<checkstyle.consoleOutput>true</checkstyle.consoleOutput>
21+
<jdk.module.illegalAccess>deny</jdk.module.illegalAccess>
22+
<checkstyle.version>3.1.0</checkstyle.version>
1523
</properties>
1624

1725
<licenses>
@@ -92,6 +100,11 @@
92100

93101
<build>
94102
<plugins>
103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-surefire-plugin</artifactId>
106+
<version>2.19</version>
107+
</plugin>
95108
<plugin>
96109
<groupId>org.apache.maven.plugins</groupId>
97110
<artifactId>maven-enforcer-plugin</artifactId>
@@ -105,7 +118,7 @@
105118
<configuration>
106119
<rules>
107120
<requireJavaVersion>
108-
<version>[1.7.0-0,1.9.0-0),[9.0.0,11.0.5]</version>
121+
<version>[1.7.0-0,1.9.0-0),[9.0.0,13.0.2]</version>
109122
</requireJavaVersion>
110123
</rules>
111124
</configuration>
@@ -186,7 +199,50 @@
186199
<autoReleaseAfterClose>true</autoReleaseAfterClose>
187200
</configuration>
188201
</plugin>
202+
<plugin>
203+
<groupId>org.apache.maven.plugins</groupId>
204+
<artifactId>maven-checkstyle-plugin</artifactId>
205+
<version>${checkstyle.version}</version>
206+
<executions>
207+
<execution>
208+
<id>checkstyle</id>
209+
<phase>verify</phase>
210+
<configuration>
211+
<encoding>UTF-8</encoding>
212+
<consoleOutput>true</consoleOutput>
213+
<failsOnError>true</failsOnError>
214+
<failOnViolation>true</failOnViolation>
215+
<violationSeverity>warning</violationSeverity>
216+
<linkXRef>false</linkXRef>
217+
</configuration>
218+
<goals>
219+
<goal>check</goal>
220+
</goals>
221+
</execution>
222+
</executions>
223+
</plugin>
189224
</plugins>
190225
</build>
191226

227+
<reporting>
228+
<plugins>
229+
<plugin>
230+
<groupId>org.apache.maven.plugins</groupId>
231+
<artifactId>maven-checkstyle-plugin</artifactId>
232+
<version>${checkstyle.version}</version>
233+
<reportSets>
234+
<reportSet>
235+
<reports>
236+
<report>checkstyle</report>
237+
</reports>
238+
</reportSet>
239+
</reportSets>
240+
</plugin>
241+
<plugin>
242+
<groupId>org.apache.maven.plugins</groupId>
243+
<artifactId>maven-jxr-plugin</artifactId>
244+
<version>3.0.0</version>
245+
</plugin>
246+
</plugins>
247+
</reporting>
192248
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.timgroup.statsd;
2+
3+
import java.nio.ByteBuffer;
4+
5+
import java.util.concurrent.ArrayBlockingQueue;
6+
import java.util.concurrent.BlockingQueue;
7+
8+
public class BufferPool {
9+
private final BlockingQueue<ByteBuffer> pool;
10+
private final int size;
11+
12+
13+
BufferPool(final int poolSize, int bufferSize, final boolean direct) throws InterruptedException {
14+
15+
size = poolSize;
16+
pool = new ArrayBlockingQueue<ByteBuffer>(poolSize);
17+
for (int i = 0; i < size ; i++) {
18+
if (direct) {
19+
pool.put(ByteBuffer.allocateDirect(bufferSize));
20+
} else {
21+
pool.put(ByteBuffer.allocate(bufferSize));
22+
}
23+
}
24+
}
25+
26+
ByteBuffer borrow() throws InterruptedException {
27+
return pool.take();
28+
}
29+
30+
void put(ByteBuffer buffer) throws InterruptedException {
31+
pool.put(buffer);
32+
}
33+
34+
int available() {
35+
return pool.size();
36+
}
37+
}

src/main/java/com/timgroup/statsd/Event.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.Date;
44

55
/**
6-
* An event to send
6+
* An event to send.
77
* @see <a href="http://docs.datadoghq.com/guides/dogstatsd/#events">http://docs.datadoghq.com/guides/dogstatsd/#events</a>
88
*/
99
public class Event {
@@ -25,6 +25,7 @@ public String getText() {
2525
}
2626

2727
/**
28+
* Get number of milliseconds since epoch started.
2829
* @return -1 if not set
2930
*/
3031
public long getMillisSinceEpoch() {
@@ -65,11 +66,17 @@ public enum AlertType {
6566
ERROR, WARNING, INFO, SUCCESS
6667
}
6768

68-
@SuppressWarnings({"AccessingNonPublicFieldOfAnotherObject", "PrivateMemberAccessBetweenOuterAndInnerClass", "ParameterHidesMemberVariable"})
69+
@SuppressWarnings({"AccessingNonPublicFieldOfAnotherObject",
70+
"PrivateMemberAccessBetweenOuterAndInnerClass", "ParameterHidesMemberVariable"})
6971
public static class Builder {
7072
private final Event event = new Event();
73+
7174
private Builder() {}
7275

76+
/**
77+
* Build factory method for the event.
78+
* @return Event built following specified options.
79+
*/
7380
public Event build() {
7481
if ((event.title == null) || event.title.isEmpty()) {
7582
throw new IllegalStateException("event title must be set");
@@ -81,62 +88,76 @@ public Event build() {
8188
}
8289

8390
/**
91+
* Title for the event.
8492
* @param title
8593
* Event title ; mandatory
94+
* @return Builder object being used.
8695
*/
8796
public Builder withTitle(final String title) {
8897
event.title = title;
8998
return this;
9099
}
91100

92101
/**
102+
* Text for the event.
93103
* @param text
94104
* Event text ; supports line breaks ; mandatory
105+
* @return Builder object being used.
95106
*/
96107
public Builder withText(final String text) {
97108
event.text = text;
98109
return this;
99110
}
100111

101112
/**
113+
* Date for the event.
102114
* @param date
103115
* Assign a timestamp to the event ; Default: none (Default is the current Unix epoch timestamp when not sent)
116+
* @return Builder object being used.
104117
*/
105118
public Builder withDate(final Date date) {
106119
event.millisSinceEpoch = date.getTime();
107120
return this;
108121
}
109122

110123
/**
124+
* Date for the event.
111125
* @param millisSinceEpoch
112126
* Assign a timestamp to the event ; Default: none (Default is the current Unix epoch timestamp when not sent)
127+
* @return Builder object being used.
113128
*/
114129
public Builder withDate(final long millisSinceEpoch) {
115130
event.millisSinceEpoch = millisSinceEpoch;
116131
return this;
117132
}
118133

119134
/**
135+
* Source hostname for the event.
120136
* @param hostname
121137
* Assign a hostname to the event ; Default: none
138+
* @return Builder object being used.
122139
*/
123140
public Builder withHostname(final String hostname) {
124141
event.hostname = hostname;
125142
return this;
126143
}
127144

128145
/**
146+
* Aggregation key for the event.
129147
* @param aggregationKey
130148
* Assign an aggregation key to the event, to group it with some others ; Default: none
149+
* @return Builder object being used.
131150
*/
132151
public Builder withAggregationKey(final String aggregationKey) {
133152
event.aggregationKey = aggregationKey;
134153
return this;
135154
}
136155

137156
/**
157+
* Priority for the event.
138158
* @param priority
139159
* Can be "normal" or "low" ; Default: "normal"
160+
* @return Builder object being used.
140161
*/
141162
public Builder withPriority(final Priority priority) {
142163
//noinspection StringToUpperCaseOrToLowerCaseWithoutLocale
@@ -145,17 +166,21 @@ public Builder withPriority(final Priority priority) {
145166
}
146167

147168
/**
169+
* Source Type name for the event.
148170
* @param sourceTypeName
149171
* Assign a source type to the event ; Default: none
172+
* @return Builder object being used.
150173
*/
151174
public Builder withSourceTypeName(final String sourceTypeName) {
152175
event.sourceTypeName = sourceTypeName;
153176
return this;
154177
}
155178

156179
/**
180+
* Alert type for the event.
157181
* @param alertType
158182
* Can be "error", "warning", "info" or "success" ; Default: "info"
183+
* @return Builder object being used.
159184
*/
160185
public Builder withAlertType(final AlertType alertType) {
161186
//noinspection StringToUpperCaseOrToLowerCaseWithoutLocale

src/main/java/com/timgroup/statsd/InvalidMessageException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.timgroup.statsd;
22

33
/**
4-
* Signals that we've been passed a message that's invalid and won't be sent
4+
* Signals that we've been passed a message that's invalid and won't be sent.
55
*
66
* @author Taylor Schilling
77
*/
@@ -11,7 +11,7 @@ public class InvalidMessageException extends RuntimeException {
1111
private final String invalidMessage;
1212

1313
/**
14-
* Creates an InvalidMessageException with a specified detail message and the invalid message itself
14+
* Creates an InvalidMessageException with a specified detail message and the invalid message itself.
1515
*
1616
* @param detailMessage a message that details why the invalid message is considered so
1717
* @param invalidMessage the message deemed invalid

0 commit comments

Comments
 (0)