-
-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathTcpSyslogMessageSenderLoadTest.java
More file actions
85 lines (73 loc) · 3.22 KB
/
TcpSyslogMessageSenderLoadTest.java
File metadata and controls
85 lines (73 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright 2010-2014, CloudBees Inc.
*
* Licensed 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 com.cloudbees.syslog.sender;
import com.cloudbees.syslog.Facility;
import com.cloudbees.syslog.Severity;
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author <a href="mailto:cleclerc@cloudbees.com">Cyrille Le Clerc</a>
*/
public class TcpSyslogMessageSenderLoadTest {
public static void main(String[] args) throws Exception {
final int THREADS_COUNT = 5;
final int ITERATION_COUNT = 100;
ExecutorService executorService = Executors.newFixedThreadPool(THREADS_COUNT);
final TcpSyslogMessageSender messageSender = new TcpSyslogMessageSender();
messageSender.setDefaultMessageHostname("mysecretkey");
messageSender.setDefaultAppName("myapp");
messageSender.setDefaultFacility(Facility.USER);
messageSender.setDefaultSeverity(Severity.INFORMATIONAL);
messageSender.setSyslogServerHostname("logs2.papertrailapp.com");
// messageSender.setSyslogServerHostname("127.0.0.1");
messageSender.setSyslogServerPort(46022);
messageSender.setSsl(true);
messageSender.setSocketFlush(TcpSyslogMessageSender.SocketFlush.onSend);
final AtomicInteger count = new AtomicInteger();
final Random random = new Random();
for (int i = 0; i < THREADS_COUNT; i++) {
final String prefix = "thread-" + i + "msg-";
Runnable command = new Runnable() {
@Override
public void run() {
for (int j = 0; j < ITERATION_COUNT; j++) {
try {
messageSender.sendMessage(prefix + j);
Thread.sleep(random.nextInt(3));
} catch (IOException e) {
System.err.println("ERROR in " + prefix);
e.printStackTrace();
break;
} catch (InterruptedException e) {
System.err.println("ERROR in " + prefix);
e.printStackTrace();
break;
}
}
}
};
executorService.execute(command);
}
executorService.shutdown();
executorService.awaitTermination(1, TimeUnit.MINUTES);
System.out.println("sent " + messageSender.getSendCount() + " in " + messageSender.getSendDurationInMillis() + "ms");
System.out.println("bye");
}
}