Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi-universe throughput example #1801

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7c7ca32
add multi throughput example
DaAwesomeP Oct 14, 2022
2140930
add advanced api to multi throughput example
DaAwesomeP Oct 15, 2022
a5acd85
multi throughput example add sendDmx timings
DaAwesomeP Nov 4, 2022
9455b6e
Remove EPoll 1ms delay
DaAwesomeP Dec 3, 2022
d200e86
multi throughput example NOLINT category for std::chrono
DaAwesomeP Dec 3, 2022
d0260ae
add comment about epoller delay reduction
DaAwesomeP Dec 5, 2022
ddbeacd
fix attribution for ola-throughput-multi
DaAwesomeP Dec 5, 2022
873c169
Add Perry Naseck to AUTHORS for EPoll delay fix
DaAwesomeP Dec 6, 2022
845342f
AUTHORS add attribution for ola_throughput_multi
DaAwesomeP Dec 6, 2022
f0457b8
Merge remote-tracking branch 'upstream/master' into DaAwesomeP-Stream…
DaAwesomeP Dec 6, 2022
8f280b7
Merge branch 'master' into DaAwesomeP-StreamingClientThroughput
DaAwesomeP Jan 4, 2023
b7df650
Merge branch 'master' into DaAwesomeP-StreamingClientThroughput
DaAwesomeP May 17, 2023
844bf6b
Merge branch 'master' into DaAwesomeP-StreamingClientThroughput
DaAwesomeP Jun 18, 2023
774a8a4
Merge branch 'master' into DaAwesomeP-StreamingClientThroughput
DaAwesomeP Jun 21, 2023
48976ae
ola_throughput_multi single copyright
DaAwesomeP Jun 22, 2023
8316511
Merge branch 'master' into DaAwesomeP-StreamingClientThroughput
DaAwesomeP Jun 22, 2023
b219aed
Merge branch 'master' into DaAwesomeP-StreamingClientThroughput
DaAwesomeP Jul 13, 2023
4f60297
Merge remote-tracking branch 'upstream/master' into DaAwesomeP-Stream…
DaAwesomeP Oct 10, 2023
54f753e
Merge remote-tracking branch 'upstream/master' into DaAwesomeP-Stream…
DaAwesomeP Dec 13, 2023
e51db46
Merge branch 'master' into DaAwesomeP-StreamingClientThroughput
DaAwesomeP Feb 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ examples/ola_streaming_client
examples/ola_streaming_client.exe
examples/ola_throughput
examples/ola_throughput.exe
examples/ola_throughput_multi
examples/ola_throughput_multi.exe
examples/ola_timecode
examples/ola_timecode.exe
examples/ola_uni_info
Expand Down
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Contributors:
Nicolas, for the win32 port of libartnet
Nicolas Bertrand, added ShowJockey DMX-U1 support
Nils Van Zuijlen, typos and python lib small update
Perry Naseck, EPoll delay fix, GitHub Actions CI workflows, Debian pkg fixes
Perry Naseck, EPoll delay fix, GitHub Actions CI workflows, Debian pkg fixes, ola_throughput_multi example
Peter Newman, MilInst Plugin, Scanlime Fadecandy support and numerous fixes
Ravindra Nath Kakarla, RDM Test Server (Google Summer of Code 2012)
Rowan Maclachlan (hippy) for various changes
Expand Down
4 changes: 3 additions & 1 deletion examples/Makefile.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Note: gcc 4.6.1 is pretty strict about library ordering. Libraries need to be

Check warning on line 1 in examples/Makefile.mk

View workflow job for this annotation

GitHub Actions / spellintian

endif endif (duplicate word) -> endif
# specified in the order they are used. i.e. a library should depend on things
# to the right, not the left.
# See http://www.network-theory.co.uk/docs/gccintro/gccintro_18.html
Expand Down Expand Up @@ -102,9 +102,11 @@
endif
endif

noinst_PROGRAMS += examples/ola_throughput examples/ola_latency
noinst_PROGRAMS += examples/ola_throughput examples/ola_throughput_multi examples/ola_latency
examples_ola_throughput_SOURCES = examples/ola-throughput.cpp
examples_ola_throughput_LDADD = $(EXAMPLE_COMMON_LIBS)
examples_ola_throughput_multi_SOURCES = examples/ola-throughput-multi.cpp
examples_ola_throughput_multi_LDADD = $(EXAMPLE_COMMON_LIBS)
examples_ola_latency_SOURCES = examples/ola-latency.cpp
examples_ola_latency_LDADD = $(EXAMPLE_COMMON_LIBS)

Expand Down
178 changes: 178 additions & 0 deletions examples/ola-throughput-multi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* ola-throughput-multi.cpp
* Send a bunch of frames quickly on multiple universes to load test the server.
* Copyright (C) 2022 Perry Naseck ([email protected])
* Copyright (C) 2005 Simon Newton (this file based on ola-throughput.cpp)
peternewman marked this conversation as resolved.
Show resolved Hide resolved
*/

#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <ola/base/Flags.h>
#include <ola/base/Init.h>
#include <ola/client/ClientWrapper.h>
#include <ola/io/SelectServer.h>
#include <ola/DmxBuffer.h>
#include <ola/Logging.h>
#include <ola/StreamingClient.h>
#include <ola/StringUtils.h>

#include <chrono> // NOLINT(build/c++11)
#include <iostream>
#include <string>
#include <vector>

using std::cout;
using std::endl;
using std::string;
using ola::client::OlaClientWrapper;
using ola::StreamingClient;
using std::chrono::high_resolution_clock;
using std::chrono::microseconds;
using std::chrono::nanoseconds;

const unsigned int MICROSECONDS_PER_MILLISECOND = 1000;

DEFINE_s_uint32(universes, u, 24, "The number of universes to send data on");
DEFINE_s_uint32(sleep, s, 40000, "Time between DMX updates in micro-seconds");
DEFINE_s_default_bool(oscillate_data, d, false,
"Flip all channels in each universe between 0 and 255 "
"for each frame. CAUTION: This will produce rapid "
"strobing on any connected outputs!");
DEFINE_s_default_bool(advanced, a, false, "Use the advanced ClientWrapper API "
"instead of the StreamingClient API");

void oscillateData(std::vector<ola::DmxBuffer> *buffers) {
static bool channelsOnNext = true;
for (size_t i = 0; i < FLAGS_universes; i++) {
if (channelsOnNext) {
for (size_t j = 0; j < 512; j++) {
(*buffers)[i].SetChannel(j, 255);
}
channelsOnNext = false;
} else {
(*buffers)[i].Blackout();
channelsOnNext = true;
}
}
}

void AdvancedConnectionClosed(ola::io::SelectServer *ss) {
std::cerr << "Connection to olad was closed" << endl;
ss->Terminate(); // terminate the program.
}

bool AdvancedSendData(ola::client::OlaClientWrapper *wrapper,
std::vector<ola::DmxBuffer> *buffers,
std::vector<nanoseconds> *sendDmxTimes) {
if (FLAGS_oscillate_data) {
oscillateData(buffers);
}

auto startTime = std::chrono::high_resolution_clock::now();
for (size_t i = 0; i < FLAGS_universes; i++) {
auto startTimeSendDmx = high_resolution_clock::now();
wrapper->GetClient()->SendDMX(
i + 1,
(*buffers)[i],
ola::client::SendDMXArgs());
(*sendDmxTimes)[i] = (high_resolution_clock::now() - startTimeSendDmx);
}
auto endTime = (std::chrono::high_resolution_clock::now() - startTime);

printf("sendDmx times (us):"); // fast write
for (size_t i = 0; i < FLAGS_universes; i++) {
auto endTimeSendDmxUs = (
std::chrono::duration_cast<microseconds>((*sendDmxTimes)[i]).count());
printf(" %04ld", endTimeSendDmxUs); // fast write
}
auto endTimeUs = (
std::chrono::duration_cast<microseconds>(endTime).count());
printf("\nframe time: %08ld us\n", endTimeUs); // fast write
return true;
}

/*
* Main
*/
int main(int argc, char *argv[]) {
ola::AppInit(&argc, argv, "[options]", "Send DMX512 data to OLA.");

OlaClientWrapper wrapper;
StreamingClient ola_client;
if (FLAGS_advanced) {
if (!wrapper.Setup()) {
OLA_FATAL << "Setup failed";
exit(1);
}
} else {
if (!ola_client.Setup()) {
OLA_FATAL << "Setup failed";
exit(1);
}
}

std::vector<ola::DmxBuffer> buffers;
for (size_t i = 0; i < FLAGS_universes; i++) {
buffers.push_back(ola::DmxBuffer());
buffers[i].Blackout();
}

std::vector<nanoseconds> sendDmxTimes(FLAGS_universes);

if (FLAGS_advanced) {
ola::io::SelectServer *ss = wrapper.GetSelectServer();
ss->RegisterRepeatingTimeout(
FLAGS_sleep / MICROSECONDS_PER_MILLISECOND,
ola::NewCallback(&AdvancedSendData, &wrapper, &buffers, &sendDmxTimes));

wrapper.GetClient()->SetCloseHandler(
ola::NewSingleCallback(AdvancedConnectionClosed, ss));

ss->Run();
} else {
while (1) {
usleep(FLAGS_sleep);

if (FLAGS_oscillate_data) {
oscillateData(&buffers);
}

auto startTime = high_resolution_clock::now();
for (size_t i = 0; i < FLAGS_universes; i++) {
auto startTimeSendDmx = high_resolution_clock::now();
if (!ola_client.SendDmx(i + 1, buffers[i])) {
cout << "Send DMX failed" << endl;
exit(1);
}
sendDmxTimes[i] = (high_resolution_clock::now() - startTimeSendDmx);
}
auto endTime = (high_resolution_clock::now() - startTime);

printf("sendDmx times (us):"); // fast write
for (size_t i = 0; i < FLAGS_universes; i++) {
auto endTimeSendDmxUs = (
std::chrono::duration_cast<microseconds>(sendDmxTimes[i]).count());
printf(" %04ld", endTimeSendDmxUs); // fast write
}
auto endTimeUs = (
std::chrono::duration_cast<microseconds>(endTime).count());
printf("\nframe time: %08ld us\n", endTimeUs); // fast write
}
}
return 0;
}
Loading