Changeset - 9ed6d091a817
[Not reviewed]
0 6 17
Christopher Esterhuyse - 5 years ago 2020-10-01 17:47:10
christopher.esterhuyse@gmail.com
more benchmarks and some more error cases
23 files changed with 359 insertions and 17 deletions:
0 comments (0 inline, 0 general)
examples/bench_11/main.c
Show inline comments
 
@@ -5,9 +5,8 @@ int main(int argc, char** argv) {
 
	int i, j, forwards, num_options, correct_index;
 
	forwards = atoi(argv[1]);
 
	num_options = atoi(argv[2]);
 
	correct_index = atoi(argv[3]);
 
	printf("forwards %d, num_options %d, correct_index %d\n",
 
		forwards, num_options, correct_index);
 
	printf("forwards %d, num_options %d\n",
 
		forwards, num_options);
 
	unsigned char pdl[] = 
 
	"primitive recv_zero(in a) {  "
 
	"    while(true) synchronous {"
 
@@ -43,7 +42,8 @@ int main(int argc, char** argv) {
 
	
 
	clock_t begin = clock();
 
	char msg = 0;
 
	for (i=0; i<10000; i++) {
 
	for (i=0; i<1000; i++) {
 
		correct_index = i%num_options;
 
		for(j=0; j<num_options; j++) {
 
			msg = j==correct_index ? 0 : 1;
 
			connector_put_bytes(c, native_putter, &msg, 1);
examples/bench_12/main.c
Show inline comments
 
new file 100644
 
#include <time.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 
int main(int argc, char** argv) {
 
	int i, j, batches;
 
	batches = atoi(argv[1]);
 
	printf("batches %d\n", batches);
 
	unsigned char pdl[] = "";
 
	Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1);
 
	printf("Error str `%s`\n", reowolf_error_peek(NULL));
 
	char logpath[] = "./bench_12.txt";
 
	Connector * c = connector_new_logging(pd, logpath, sizeof(logpath)-1);
 
	
 
	connector_connect(c, -1);
 
	printf("Error str `%s`\n", reowolf_error_peek(NULL));
 
	
 
	clock_t begin = clock();
 
	char msg = 0;
 
	for (i=0; i<1000000; i++) {
 
		for(j=1; j<batches; j++) {
 
			connector_next_batch(c);
 
		}
 
		connector_sync(c, -1);
 
	}
 
	clock_t end = clock();
 
	double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
 
	printf("Time taken: %f\n", time_spent);
 
	return 0;
 
}
 
\ No newline at end of file
examples/bench_13/main.c
Show inline comments
 
new file 100644
 
#include <time.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 
int main(int argc, char** argv) {
 
	int i, msglen, inside, total;
 
	char * transport;
 
	transport = argv[1];
 
	msglen = atoi(argv[2]);
 
	inside = atoi(argv[3]);
 
	total = atoi(argv[4]);
 
	printf("transport `%s`, msglen %d, inside %d, total %d\n",
 
		transport, msglen, inside, total);
 
	unsigned char pdl[] = ""; 
 
	Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1);
 
	printf("Error str `%s`\n", reowolf_error_peek(NULL));
 
	char logpath[] = "./bench_13.txt";
 
	Connector * c = connector_new_logging(pd, logpath, sizeof(logpath)-1);
 

	
 
	PortId native_putter, native_getter;
 
	char ident[] = "sync"; // defined in reowolf's stdlib 
 
	connector_add_port_pair(c, &native_putter, &native_getter);
 
	for (i=0; i<inside; i++) {
 
		// create a forward linked in the ring
 
		PortId putter, getter;
 
		if(0 == strcmp(transport, "mem")) {
 
			connector_add_port_pair(c, &putter, &getter);
 
		} else if(0 == strcmp(transport, "localhost")) {
 
			FfiSocketAddr addr = {{127, 0, 0, 1}, i+7000};
 
			connector_add_net_port(c, &putter, addr, Polarity_Putter, EndpointPolarity_Active);
 
			connector_add_net_port(c, &getter, addr, Polarity_Getter, EndpointPolarity_Passive);
 
		} else {
 
			printf("BAD TRANSPORT!\n");
 
			exit(1);
 
		}
 
		
 
		// native ports: {native_putter, native_getter, putter, getter}
 
		// thread a forward component onto native_tail
 
		connector_add_component(c, ident, sizeof(ident)-1, (PortId[]){native_getter, putter}, 2);
 
		// native ports: {native_putter, getter}
 
		printf("Error str `%s`\n", reowolf_error_peek(NULL));
 
		native_getter = getter;
 
	}
 
	for (i=inside; i<total; i++) {
 
		// create a forward linked to itself
 
		PortId putter, getter;
 
		connector_add_port_pair(c, &putter, &getter);
 
		connector_add_component(c, ident, sizeof(ident)-1, (PortId[]){getter, putter}, 2);
 
		printf("Error str `%s`\n", reowolf_error_peek(NULL));
 
	}
 
	connector_connect(c, -1);
 
	printf("Error str `%s`\n", reowolf_error_peek(NULL));
 
	
 
	char * msg = malloc(msglen);
 
	memset(msg, msglen, 42);
 
	
 
	clock_t begin = clock();
 
	for (i=0; i<100000; i++) {
 
		connector_put_bytes(c, native_putter, msg, msglen);
 
		connector_get(c, native_getter);
 
		connector_sync(c, -1);
 
	}
 
	clock_t end = clock();
 
	double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
 
	printf("Time taken: %f\n", time_spent);
 
	free(msg);
 
	return 0;
 
}
 
\ No newline at end of file
examples/bench_14/amy.c
Show inline comments
 
new file 100644
 
#include <time.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 
int main(int argc, char** argv) {
 
	int i, msglen;
 
	msglen = atoi(argv[1]);
 
	printf("msglen %d\n", msglen);
 
	printf("Error str `%s`\n", reowolf_error_peek(NULL));
 
	char * msg = malloc(msglen);
 
	memset(msg, msglen, 42);
 

	
 
	unsigned char pdl[] = "";
 
	Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1);
 
	printf("Error str `%s`\n", reowolf_error_peek(NULL));
 
	char logpath[] = "./bench_14_amy.txt";
 
	Connector * c = connector_new_logging_with_id(pd, logpath, sizeof(logpath)-1, 0);
 
	
 
	PortId putter, getter;
 
	connector_add_net_port(
 
		c,
 
		&putter, 
 
		(FfiSocketAddr) {{127, 0, 0, 1}, 7000},
 
		Polarity_Putter,
 
		EndpointPolarity_Active);
 
	connector_add_net_port(
 
		c,
 
		&getter, 
 
		(FfiSocketAddr) {{127, 0, 0, 1}, 7001},
 
		Polarity_Getter,
 
		EndpointPolarity_Passive);
 
	connector_connect(c, -1);
 
	
 
	clock_t begin = clock();
 
	for (i=0; i<10000; i++) {
 
		connector_put_bytes(c, putter, msg, msglen);
 
		connector_get(c, getter);
 
		connector_sync(c, -1);
 
	}
 
	clock_t end = clock();
 
	double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
 
	printf("Time taken: %f\n", time_spent);
 

	
 
	free(msg);
 
	return 0;
 
}
 
\ No newline at end of file
examples/bench_14/bob.c
Show inline comments
 
new file 100644
 
#include <time.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 
int main(int argc, char** argv) {
 
	int i;
 
	unsigned char pdl[] = "";
 
	Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1);
 
	printf("Error str `%s`\n", reowolf_error_peek(NULL));
 
	char logpath[] = "./bench_14_bob.txt";
 
	Connector * c = connector_new_logging_with_id(pd, logpath, sizeof(logpath)-1, 1);
 
	
 
	PortId putter, getter;
 
	connector_add_net_port(
 
		c,
 
		&putter, 
 
		(FfiSocketAddr) {{127, 0, 0, 1}, 7001},
 
		Polarity_Putter,
 
		EndpointPolarity_Active);
 
	connector_add_net_port(
 
		c,
 
		&getter, 
 
		(FfiSocketAddr) {{127, 0, 0, 1}, 7000},
 
		Polarity_Getter,
 
		EndpointPolarity_Passive);
 
	connector_add_component(c, "forward", 7, (PortId[]){getter, putter}, 2);
 
	printf("Error str `%s`\n", reowolf_error_peek(NULL));
 
	connector_connect(c, -1);
 
	printf("Error str `%s`\n", reowolf_error_peek(NULL));
 
	
 
	clock_t begin = clock();
 
	for (i=0; i<10000; i++) {
 
		connector_sync(c, -1);
 
	}
 
	clock_t end = clock();
 

	
 
	double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
 
	printf("Time taken: %f\n", time_spent);
 
	return 0;
 
}
 
\ No newline at end of file
examples/bench_15/main.c
Show inline comments
 
new file 100644
 
#include <time.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 
int main(int argc, char** argv) {
 
	int i, cid;
 
	cid = atoi(argv[1]);
 
	printf("cid %d\n", cid);
 
	printf("Error str `%s`\n", reowolf_error_peek(NULL));
 

	
 
	unsigned char pdl[] = "";
 
	Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1);
 
	Connector * c = connector_new_with_id(pd, cid);
 

	
 
	bool seen_delim = false;
 
	for(i=2; i<argc; i++) {
 
		EndpointPolarity ep;
 
		Polarity p;
 
		if(argv[i][0] == '.') {
 
			seen_delim = true;
 
			continue;
 
		} else if(seen_delim) {
 
			printf("putter");
 
			p = Polarity_Getter;
 
			ep = EndpointPolarity_Passive;
 
		} else {
 
			printf("getter");
 
			p = Polarity_Putter;
 
			ep = EndpointPolarity_Active;
 
		}
 
		FfiSocketAddr addr = {{127, 0, 0, 1}, atoi(argv[i])};
 
		printf("@%d\n", addr.port);
 
		connector_add_net_port(c, NULL, addr, p, ep);
 
	}
 
	printf("Added all ports!\n");
 
	connector_connect(c, -1);
 
	
 
	clock_t begin = clock();
 
	for (i=0; i<10000; i++) {
 
		connector_sync(c, -1);
 
	}
 
	clock_t end = clock();
 
	double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
 
	printf("Time taken: %f\n", time_spent);
 
	return 0;
 
}
 
\ No newline at end of file
examples/bench_15_7000.png
Show inline comments
 
new file 100644
Show images
examples/bench_15_7993.png
Show inline comments
 
new file 100644
Show images
examples/bench_15_7994.png
Show inline comments
 
new file 100644
Show images
examples/bench_15_7995.png
Show inline comments
 
new file 100644
Show images
examples/bench_15_7996.png
Show inline comments
 
new file 100644
Show images
examples/bench_15_7997.png
Show inline comments
 
new file 100644
Show images
examples/bench_15_7998.png
Show inline comments
 
new file 100644
Show images
examples/bench_15_7999.png
Show inline comments
 
new file 100644
Show images
examples/bench_15_8000.png
Show inline comments
 
new file 100644
Show images
examples/bench_15_8001.png
Show inline comments
 
new file 100644
Show images
examples/bench_16/main.c
Show inline comments
 
new file 100644
 
#include <time.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 
int main(int argc, char** argv) {
 
	int i, cid;
 
	cid = atoi(argv[1]);
 
	printf("cid %d\n", cid);
 
	printf("Error str `%s`\n", reowolf_error_peek(NULL));
 

	
 
	unsigned char pdl[] = "";
 
	Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1);
 
	Connector * c = connector_new_with_id(pd, cid);
 

	
 
	bool seen_delim = false;
 
	for(i=2; i<argc; i++) {
 
		EndpointPolarity ep;
 
		Polarity p;
 
		if(argv[i][0] == '.') {
 
			seen_delim = true;
 
			continue;
 
		} else if(seen_delim) {
 
			printf("putter");
 
			p = Polarity_Getter;
 
			ep = EndpointPolarity_Passive;
 
		} else {
 
			printf("getter");
 
			p = Polarity_Putter;
 
			ep = EndpointPolarity_Active;
 
		}
 
		FfiSocketAddr addr = {{127, 0, 0, 1}, atoi(argv[i])};
 
		printf("@%d\n", addr.port);
 
		connector_add_net_port(c, NULL, addr, p, ep);
 
	}
 
	printf("Added all ports!\n");
 
	connector_connect(c, -1);
 
	
 
	clock_t begin = clock();
 
	for (i=0; i<10000; i++) {
 
		connector_sync(c, -1);
 
	}
 
	clock_t end = clock();
 
	double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
 
	printf("Time taken: %f\n", time_spent);
 
	return 0;
 
}
 
\ No newline at end of file
examples/bench_17/main.c
Show inline comments
 
new file 100644
 
#include <time.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 
#define N 5
 
int main(int argc, char** argv) {
 
	int i, cid, min_pid, msgs;
 
	cid = atoi(argv[1]);
 
	min_pid = atoi(argv[2]);
 
	char role = argv[3][0]; // 'h' for head, 'i' for inner, 't' for tail, 's' for singleton
 
	msgs = atoi(argv[4]);
 
	printf("cid %d, min_pid %d, role='%c', msgs %d\n",
 
		cid, min_pid, role, msgs);
 
	printf("Error str `%s`\n", reowolf_error_peek(NULL));
 

	
 
	unsigned char pdl[] = "";
 
	Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1);
 
	Connector * c = connector_new_with_id(pd, cid);
 
	PortId putters[N], getters[N];
 
	FfiSocketAddr addr = {{127, 0, 0, 1}, 0};
 
	if(role=='i' || role=='t') {
 
		// I have N getter ports!
 
		for(i=0; i<N; i++) {
 
			addr.port = min_pid+i;
 
			connector_add_net_port(c, &getters[i], addr, Polarity_Getter, EndpointPolarity_Passive);
 
		}
 
	}
 
	if(role=='h' || role=='i') {
 
		// I have N putter ports!
 
		for(i=0; i<N; i++) {
 
			addr.port = min_pid+i+N;
 
			connector_add_net_port(c, &putters[i], addr, Polarity_Putter, EndpointPolarity_Active);
 
		}
 
	}
 
	printf("Added all ports!\n");
 
	if(role=='i') {
 
		// Inner has a forwarder component to forward messages
 
		for(i=0; i<N; i++) {	
 
			connector_add_component(c, "forward", 7, (PortId[]){putters[i], getters[i]}, 2);
 
		}
 
	}
 
	connector_connect(c, -1);
 
	
 
	clock_t begin = clock();
 
	char msg[] = "Hello, world!";
 
	for (i=0; i<10000; i++) {
 
		if(role=='h' || role=='s') {
 
			// singleton and head send N messages
 
			for(i=0; i<N; i++) { 
 
				connector_put_bytes(c, putters[i], msg, sizeof(msg)-1);
 
			}
 
		}
 
		if(role=='t' || role=='s') {
 
			// singleton and tail recv N messages
 
			for(i=0; i<N; i++) { 
 
				connector_get(c, getters[i]);
 
			}
 
		}
 
		// inner doesn't send nor receive
 
		connector_sync(c, -1);
 
	}
 
	clock_t end = clock();
 
	double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
 
	printf("Time taken: %f\n", time_spent);
 
	return 0;
 
}
 
\ No newline at end of file
examples/zoop.sh
Show inline comments
 
#!/bin/bash
 
for options in {1..5}
 
for included in {0..13}
 
do
 
	for forwards in {0..15}
 
	do
 
		./bench_11/main.exe $forwards $options 0
 
	done
 
	./bench_13/main.exe 65535 $included 13
 
done
 
\ No newline at end of file
reowolf.h
Show inline comments
 
@@ -129,6 +129,8 @@ const uint8_t *connector_gotten_bytes(Connector *connector, PortId port, uintptr
 
 * The connector uses the given (internal) connector ID.
 
 */
 
Connector *connector_new(const Arc_ProtocolDescription *pd);
 
Connector *connector_new_with_id(const Arc_ProtocolDescription *pd,
 
                                 ConnectorId connector_id);
 

	
 
Connector *connector_new_logging(const Arc_ProtocolDescription *pd,
 
                                 const uint8_t *path_ptr,
src/ffi/mod.rs
Show inline comments
 
@@ -168,6 +168,14 @@ pub unsafe extern "C" fn connector_new_logging_with_id(
 
    }
 
}
 
#[no_mangle]
 
pub unsafe extern "C" fn connector_new_with_id(
 
    pd: &Arc<ProtocolDescription>,
 
    connector_id: ConnectorId,
 
) -> *mut Connector {
 
    let c = Connector::new(Box::new(DummyLogger), pd.clone(), connector_id);
 
    Box::into_raw(Box::new(c))
 
}
 
#[no_mangle]
 
pub unsafe extern "C" fn connector_new_logging(
 
    pd: &Arc<ProtocolDescription>,
 
    path_ptr: *const u8,
 
@@ -176,17 +184,11 @@ pub unsafe extern "C" fn connector_new_logging(
 
    connector_new_logging_with_id(pd, path_ptr, path_len, Connector::random_id())
 
}
 

	
 
#[no_mangle]
 
pub unsafe extern "C" fn connector_print_debug(connector: &mut Connector) {
 
    println!("Debug print dump {:#?}", connector);
 
}
 

	
 
/// Initializes `out` with a new connector using the given protocol description as its configuration.
 
/// The connector uses the given (internal) connector ID.
 
#[no_mangle]
 
pub unsafe extern "C" fn connector_new(pd: &Arc<ProtocolDescription>) -> *mut Connector {
 
    let c = Connector::new(Box::new(DummyLogger), pd.clone(), Connector::random_id());
 
    Box::into_raw(Box::new(c))
 
    connector_new_with_id(pd, Connector::random_id())
 
}
 

	
 
/// Destroys the given a pointer to the connector on the heap, freeing its resources.
 
@@ -196,6 +198,11 @@ pub unsafe extern "C" fn connector_destroy(connector: *mut Connector) {
 
    drop(Box::from_raw(connector))
 
}
 

	
 
#[no_mangle]
 
pub unsafe extern "C" fn connector_print_debug(connector: &mut Connector) {
 
    println!("Debug print dump {:#?}", connector);
 
}
 

	
 
/// Given an initialized connector in setup or connecting state,
 
/// - Creates a new directed port pair with logical channel putter->getter,
 
/// - adds the ports to the native component's interface,
src/runtime/error.rs
Show inline comments
 
@@ -4,6 +4,7 @@ use crate::common::*;
 
pub enum ConnectError {
 
    BindFailed(SocketAddr),
 
    UdpConnectFailed(SocketAddr),
 
    TcpInvalidConnect(SocketAddr),
 
    PollInitFailed,
 
    Timeout,
 
    PollFailed,
src/runtime/setup.rs
Show inline comments
 
@@ -327,7 +327,7 @@ fn setup_endpoints_and_pair_ports(
 
            log!(logger, "Net endpoint {} beginning setup with {:?}", index, &endpoint_setup);
 
            let todo_endpoint = if let EndpointPolarity::Active = endpoint_setup.endpoint_polarity {
 
                let mut stream = TcpStream::connect(endpoint_setup.sock_addr)
 
                    .expect("mio::TcpStream connect should not fail!");
 
                    .map_err(|_| Ce::TcpInvalidConnect(endpoint_setup.sock_addr))?;
 
                poll.registry().register(&mut stream, token, BOTH).unwrap();
 
                NetTodoEndpoint::PeerInfoRecving(NetEndpoint { stream, inbox: vec![] })
 
            } else {
0 comments (0 inline, 0 general)