Committed by
Gerrit Code Review
Simple test application for load testing distributed consensus
Change-Id: Ifd99bfc6fc608c5719e21ea9699db63f1c42f2a0
Showing
4 changed files
with
231 additions
and
0 deletions
apps/test/loadtest/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2016 Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | + | ||
18 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
19 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
20 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
21 | + <modelVersion>4.0.0</modelVersion> | ||
22 | + | ||
23 | + <parent> | ||
24 | + <groupId>org.onosproject</groupId> | ||
25 | + <artifactId>onos-apps-test</artifactId> | ||
26 | + <version>1.5.0-SNAPSHOT</version> | ||
27 | + <relativePath>../pom.xml</relativePath> | ||
28 | + </parent> | ||
29 | + | ||
30 | + <artifactId>onos-app-loadtest</artifactId> | ||
31 | + <packaging>bundle</packaging> | ||
32 | + | ||
33 | + <description>Distributed consensus load test application</description> | ||
34 | + | ||
35 | + <properties> | ||
36 | + <onos.app.name>org.onosproject.loadtest</onos.app.name> | ||
37 | + <onos.app.category>test</onos.app.category> | ||
38 | + <onos.app.url>http://onosproject.org</onos.app.url> | ||
39 | + <onos.app.readme>Distributed consensus load test application.</onos.app.readme> | ||
40 | + </properties> | ||
41 | + | ||
42 | + <dependencies> | ||
43 | + <dependency> | ||
44 | + <groupId>org.onosproject</groupId> | ||
45 | + <artifactId>onos-api</artifactId> | ||
46 | + <version>${project.version}</version> | ||
47 | + <scope>test</scope> | ||
48 | + <classifier>tests</classifier> | ||
49 | + </dependency> | ||
50 | + | ||
51 | + <dependency> | ||
52 | + <groupId>org.osgi</groupId> | ||
53 | + <artifactId>org.osgi.compendium</artifactId> | ||
54 | + </dependency> | ||
55 | + | ||
56 | + <dependency> | ||
57 | + <groupId>org.osgi</groupId> | ||
58 | + <artifactId>org.osgi.core</artifactId> | ||
59 | + </dependency> | ||
60 | + | ||
61 | + </dependencies> | ||
62 | + | ||
63 | +</project> |
apps/test/loadtest/src/main/java/org/onosproject/loadtest/DistributedConsensusLoadTest.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.loadtest; | ||
17 | + | ||
18 | +import static com.google.common.base.Strings.isNullOrEmpty; | ||
19 | +import static org.onlab.util.Tools.get; | ||
20 | +import static org.slf4j.LoggerFactory.getLogger; | ||
21 | + | ||
22 | +import java.util.Dictionary; | ||
23 | +import java.util.concurrent.ExecutorService; | ||
24 | +import java.util.concurrent.Executors; | ||
25 | +import java.util.concurrent.Semaphore; | ||
26 | +import java.util.concurrent.atomic.AtomicBoolean; | ||
27 | +import java.util.concurrent.atomic.AtomicLong; | ||
28 | + | ||
29 | +import org.apache.felix.scr.annotations.Activate; | ||
30 | +import org.apache.felix.scr.annotations.Component; | ||
31 | +import org.apache.felix.scr.annotations.Deactivate; | ||
32 | +import org.apache.felix.scr.annotations.Modified; | ||
33 | +import org.apache.felix.scr.annotations.Property; | ||
34 | +import org.apache.felix.scr.annotations.Reference; | ||
35 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
36 | +import org.apache.felix.scr.annotations.Service; | ||
37 | +import org.onosproject.cfg.ComponentConfigService; | ||
38 | +import org.onosproject.core.ApplicationId; | ||
39 | +import org.onosproject.core.CoreService; | ||
40 | +import org.onosproject.store.service.AsyncAtomicCounter; | ||
41 | +import org.onosproject.store.service.StorageService; | ||
42 | +import org.osgi.service.component.ComponentContext; | ||
43 | +import org.slf4j.Logger; | ||
44 | + | ||
45 | +import com.google.common.util.concurrent.RateLimiter; | ||
46 | + | ||
47 | +/** | ||
48 | + * Simple application for load testing distributed consensus. | ||
49 | + * <p> | ||
50 | + * This application simply increments as {@link AsyncAtomicCounter} at a configurable rate. | ||
51 | + */ | ||
52 | +@Component(immediate = true) | ||
53 | +@Service(value = DistributedConsensusLoadTest.class) | ||
54 | +public class DistributedConsensusLoadTest { | ||
55 | + | ||
56 | + private final Logger log = getLogger(getClass()); | ||
57 | + | ||
58 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
59 | + protected ComponentConfigService configService; | ||
60 | + | ||
61 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
62 | + protected StorageService storageService; | ||
63 | + | ||
64 | + private ApplicationId appId; | ||
65 | + | ||
66 | + private AtomicBoolean stopped = new AtomicBoolean(false); | ||
67 | + | ||
68 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
69 | + protected CoreService coreService; | ||
70 | + | ||
71 | + private static final int DEFAULT_RATE = 100; | ||
72 | + | ||
73 | + @Property(name = "rate", intValue = DEFAULT_RATE, | ||
74 | + label = "Total number of increments per second to the atomic counter") | ||
75 | + protected int rate = 0; | ||
76 | + | ||
77 | + private AtomicLong lastValue = new AtomicLong(0); | ||
78 | + private AtomicLong lastLoggedTime = new AtomicLong(0); | ||
79 | + private AsyncAtomicCounter counter; | ||
80 | + private ExecutorService testExecutor = Executors.newSingleThreadExecutor(); | ||
81 | + | ||
82 | + @Activate | ||
83 | + public void activate(ComponentContext context) { | ||
84 | + configService.registerProperties(getClass()); | ||
85 | + appId = coreService.registerApplication("org.onosproject.loadtest"); | ||
86 | + log.info("Started with {}", appId); | ||
87 | + counter = storageService.atomicCounterBuilder() | ||
88 | + .withName("onos-app-loadtest-counter") | ||
89 | + .build(); | ||
90 | + modified(null); | ||
91 | + } | ||
92 | + | ||
93 | + private void startTest() { | ||
94 | + stopped.set(false); | ||
95 | + RateLimiter limiter = RateLimiter.create(rate); | ||
96 | + Semaphore s = new Semaphore(100); | ||
97 | + while (!stopped.get()) { | ||
98 | + limiter.acquire(); | ||
99 | + s.acquireUninterruptibly(); | ||
100 | + counter.incrementAndGet().whenComplete((r, e) -> { | ||
101 | + s.release(); | ||
102 | + long delta = System.currentTimeMillis() - lastLoggedTime.get(); | ||
103 | + if (e == null) { | ||
104 | + if (delta > 1000) { | ||
105 | + long tps = (long) ((r - lastValue.get()) * 1000.0) / delta; | ||
106 | + lastValue.set(r); | ||
107 | + lastLoggedTime.set(System.currentTimeMillis()); | ||
108 | + log.info("Rate: {}", tps); | ||
109 | + } | ||
110 | + } | ||
111 | + }); | ||
112 | + } | ||
113 | + } | ||
114 | + | ||
115 | + private void stopTest() { | ||
116 | + stopped.set(true); | ||
117 | + } | ||
118 | + | ||
119 | + @Deactivate | ||
120 | + public void deactivate(ComponentContext context) { | ||
121 | + configService.unregisterProperties(getClass(), false); | ||
122 | + stopTest(); | ||
123 | + testExecutor.shutdown(); | ||
124 | + log.info("Stopped"); | ||
125 | + } | ||
126 | + | ||
127 | + @Modified | ||
128 | + public void modified(ComponentContext context) { | ||
129 | + int newRate = DEFAULT_RATE; | ||
130 | + if (context != null) { | ||
131 | + Dictionary properties = context.getProperties(); | ||
132 | + try { | ||
133 | + String s = get(properties, "rate"); | ||
134 | + newRate = isNullOrEmpty(s) | ||
135 | + ? rate : Integer.parseInt(s.trim()); | ||
136 | + } catch (Exception e) { | ||
137 | + return; | ||
138 | + } | ||
139 | + } | ||
140 | + if (newRate != rate) { | ||
141 | + log.info("Rate changed to {}", newRate); | ||
142 | + rate = newRate; | ||
143 | + stopTest(); | ||
144 | + testExecutor.execute(this::startTest); | ||
145 | + } | ||
146 | + } | ||
147 | +} |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +/** | ||
18 | + * Simple application for load testing distributed consensus. | ||
19 | + */ | ||
20 | +package org.onosproject.loadtest; |
... | @@ -33,6 +33,7 @@ | ... | @@ -33,6 +33,7 @@ |
33 | 33 | ||
34 | <modules> | 34 | <modules> |
35 | <module>election</module> | 35 | <module>election</module> |
36 | + <module>loadtest</module> | ||
36 | <module>intent-perf</module> | 37 | <module>intent-perf</module> |
37 | <module>messaging-perf</module> | 38 | <module>messaging-perf</module> |
38 | <module>demo</module> | 39 | <module>demo</module> | ... | ... |
-
Please register or login to post a comment