Skip to content

Commit c2490e3

Browse files
committed
Services script now outputs full viz url to a file in the var dir
Pserver simulation can now optionally send data to a remote viz instance Simulator example3 now optionally allows send to viz and also sleeps between io steps to simulate a real run
1 parent d87d2ea commit c2490e3

6 files changed

Lines changed: 34 additions & 6 deletions

File tree

scripts/launch/run_services.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ fi
159159
#Visualization
160160
if (( ${use_viz} == 1 )); then
161161
if (( ${use_pserver} != 1 )); then
162-
echo "Chimbuko Services: Error - cannot use viz without the pserver"
163-
exit 1
162+
echo "Chimbuko Services: Error - cannot use viz without the pserver"
163+
exit 1
164164
fi
165165
if (( ${use_provdb} == 0 )); then
166166
echo "Chimbuko Services: Error - cannot use viz without the provDB"
@@ -230,6 +230,7 @@ if (( ${use_viz} == 1 )); then
230230

231231
echo $HOST > ${var_dir}/chimbuko_webserver.host
232232
echo $viz_port > ${var_dir}/chimbuko_webserver.port
233+
echo $ws_addr > ${var_dir}/chimbuko_webserver.url
233234
echo "Chimbuko Services: Webserver is running on ${HOST}:${viz_port} and is ready for the user to connect"
234235
fi
235236

sim/include/sim/pserver.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22
#include <chimbuko_config.h>
33
#include<chimbuko/param.hpp>
4+
#include<chimbuko/util/curlJsonSender.hpp>
45
#include<chimbuko/pserver/GlobalAnomalyStats.hpp>
56
#include<chimbuko/pserver/GlobalCounterStats.hpp>
67
#include<chimbuko/pserver/GlobalAnomalyMetrics.hpp>
@@ -20,6 +21,7 @@ namespace chimbuko_sim{
2021
PSstatSenderGlobalAnomalyMetricsPayload anomaly_metrics_payload;
2122
LocalNet m_net; /**< The net server */
2223
ParamInterface* m_ad_params; /**< If using an AD algorithm to analyze the trace, these are the global parameters*/
24+
curlJsonSender* m_viz; /**< Curl connection to visualization (optional, default disabled)*/
2325
public:
2426

2527
/**
@@ -50,6 +52,11 @@ namespace chimbuko_sim{
5052
global_anomaly_metrics.add(loc);
5153
}
5254

55+
/**
56+
* @brief Enable streaming output to be written to the viz on the given url
57+
*/
58+
void enableVizOutput(const std::string &url);
59+
5360
/**
5461
* @brief Mirror write functionality of PSstatSender
5562
*/

sim/main/example3.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ int main(int argc, char **argv){
1414
MPI_Init(&argc, &argv);
1515
#endif
1616

17+
int sim_step_freq_ms = 1000; //frequency with which we iterate over io step (independent of actual function timings)
1718
provDBsetup pdb_setup;
1819
int i=1;
1920
while(i<argc){
@@ -25,6 +26,14 @@ int main(int argc, char **argv){
2526
pdb_setup.remote_server_instances = std::stoi(argv[i+3]);
2627
pdb_setup.use_local = false;
2728
i+=4;
29+
}else if(sarg == "-enable_viz"){
30+
if(i+1 >= argc) fatal_error("Not enough arguments provided");
31+
getPserver().enableVizOutput(argv[i+1]);
32+
i+=2;
33+
}else if(sarg == "-sim_step_freq"){
34+
if(i+1 >= argc) fatal_error("Not enough arguments provided");
35+
sim_step_freq_ms = std::stoi(argv[i+1]);
36+
i+=2;
2837
}else{
2938
fatal_error(stringize("Unknown argument: %s",argv[i]));
3039
}
@@ -101,6 +110,7 @@ int main(int argc, char **argv){
101110
}
102111
//PServer dump its output
103112
getPserver().writeStreamingOutput();
113+
std::this_thread::sleep_for(std::chrono::milliseconds(sim_step_freq_ms));
104114
}
105115

106116
#ifdef USE_MPI

sim/main/run_example3_pdb_ext/chimbuko_config.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ service_node_iface=eth0 #network interface upon which communication to the servi
88
####################################
99
#Options for visualization module
1010
####################################
11-
use_viz=0 #enable or disable the visualization
11+
use_viz=1 #enable or disable the visualization
1212
viz_root=/opt/chimbuko/viz #the root directory of the visualization module <------------ ***SET ME (if using viz)***
1313
viz_worker_port=6379 #the port on which to run the redis server for the visualization backend
1414
viz_port=5002 #the port on which to run the webserver
@@ -42,7 +42,7 @@ export FI_OFI_RXM_USE_SRX=1 # use shared recv context in RXM; should improve sca
4242
####################################
4343
#Options for the parameter server
4444
####################################
45-
use_pserver=0 #enable or disable the pserver
45+
use_pserver=1 #enable or disable the pserver
4646
pserver_extra_args="" #any extra command line arguments to pass
4747
pserver_port=5559 #port for parameter server
4848
pserver_nt=2 #number of worker threads

sim/main/run_example3_pdb_ext/run.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ if (( 1 )); then
1313
ad_cmd=$(cat chimbuko/vars/chimbuko_ad_cmdline.var)
1414
fi
1515

16+
ws_addr=$(cat chimbuko/vars/chimbuko_webserver.url)
17+
1618
#Run the simulation
1719
if (( 1 )); then
1820
echo "Running sim"
19-
./example3 -remote_provdb chimbuko/provdb ${provdb_nshards} ${provdb_ninstances} 2>&1 | tee chimbuko/logs/sim.log
21+
./example3 -remote_provdb chimbuko/provdb ${provdb_nshards} ${provdb_ninstances} -enable_viz ${ws_addr} 2>&1 | tee chimbuko/logs/sim.log
2022
fi
2123

2224
wait

sim/src/pserver.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ void pserverSim::writeStreamingOutput() const{
1717

1818
if(json_packet.size() != 0){ //only write if there is anything to write! (it writes "null" to the file otherwise)
1919
std::ofstream out(fname.str()); out << json_packet.dump(4);
20+
if(m_viz) m_viz->send(json_packet);
2021
}
2122
}
2223

2324
pserverSim::pserverSim(): anomaly_stats_payload(&global_func_stats), counter_stats_payload(&global_counter_stats),
24-
anomaly_metrics_payload(&global_anomaly_metrics), m_ad_params(nullptr){
25+
anomaly_metrics_payload(&global_anomaly_metrics), m_ad_params(nullptr), m_viz(nullptr){
2526
if(adAlgorithmParams().algorithm != "none"){
2627
m_ad_params = ParamInterface::set_AdParam(adAlgorithmParams().algorithm);
2728
m_net.add_payload(new NetPayloadUpdateParams(m_ad_params, false));
@@ -30,4 +31,11 @@ pserverSim::pserverSim(): anomaly_stats_payload(&global_func_stats), counter_sta
3031

3132
pserverSim::~pserverSim(){
3233
if(m_ad_params) delete m_ad_params;
34+
if(m_viz) delete m_viz;
35+
}
36+
37+
void pserverSim::enableVizOutput(const std::string &url){
38+
std::cout << "pserverSim enabling viz output on url " << url << std::endl;
39+
if(m_viz) delete m_viz;
40+
m_viz = new curlJsonSender(url);
3341
}

0 commit comments

Comments
 (0)