Skip to content

Commit

Permalink
upload partial performance result
Browse files Browse the repository at this point in the history
  • Loading branch information
victoryang00 committed Jan 19, 2024
1 parent c966c82 commit 2ac2eee
Show file tree
Hide file tree
Showing 15 changed files with 1,199 additions and 285 deletions.
1,116 changes: 900 additions & 216 deletions artifact/analyze.ipynb

Large diffs are not rendered by default.

69 changes: 37 additions & 32 deletions artifact/bench_gapbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"bfs",
"bfs",
"bfs",
"bfs",
"bc",
"bc",
"bfs",
"cc",
Expand All @@ -22,34 +24,29 @@
"tc",
]
arg = [
["-g20", "-n30"],
["-u20", "-n30"],
# ["-f", "./4.gr", "-n1000"],
# ["-f", "./4.el", "-n1000"],
# ["-f", "./4.wel", "-n1000"],
# ["-f", "./4.graph", "-n1000"],
# ["-f", "./4w.graph", "-n1000"],
# ["-f", "./4.mtx", "-n1000"],
# ["-f", "./4w.mtx", "-n1000"],
["-g20", "-n30"],
["-g20", "-n30"],
["-g20", "-n30"],
["-g20", "-n30"],
["-g20", "-n30"],
["-g20", "-n30"],
["-g20", "-n30"],
["-g20", "-vn30"],
["-g20", "-vn30"],
["-g20", "-vn30"],
["-g20", "-vn30"],
["-g20", "-vn30"],
["-g20", "-vn30"],
["-g20", "-vn30"],
["-g20", "-n2"],
["-g15", "-n300"],
["-u15", "-n300"],
["-f", "./road.sg", "-n300"],
["-g15", "-n300"],
["-g15", "-n300"],
["-g15", "-n300"],
["-g15", "-n300"],
["-g15", "-n300"],
["-g15", "-n300"],
["-g15", "-n300"],
["-g15", "-vn300"],
["-g15", "-vn300"],
["-f", "./road.sg", "-n300"],
["-g15", "-vn300"],
["-g15", "-vn300"],
["-g15", "-vn300"],
["-g15", "-vn300"],
["-g15", "-vn300"],
["-g15", "-n300"],
]


pool = Pool(processes=40)
pool = Pool(processes=5)

# run the benchmarks
results = []
Expand All @@ -62,17 +59,25 @@
pool.join()

# print the results
results = [x.get() for x in results]
# serialize the results
results = [x.get() for x in results]

with open("bench_gapbs_results.pickle", "wb") as f:
pickle.dump(results, f)

for exec, output in results:
print(exec)
lines = output.split("\n")
for line in lines:
if line.startswith("Execution time:"):
print(line)
try:
lines = output.decode("ISO-8859-1").split("\n")
for line in lines:
if line.__contains__("Execution time:"):
print(line)
except:
lines = output.split("\n")
for line in lines:
if line.__contains__("Execution time:"):
print(line)

# read the results
# with open("bench_gapbs_results.pickle", "rb") as f:
# results = pickle.load(f)
with open("bench_gapbs_results.pickle", "rb") as f:
results = pickle.load(f)
11 changes: 5 additions & 6 deletions artifact/bench_hdastar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
import common_util
from multiprocessing import Pool

cmd = ["hdastar","hdastar","hdastar","hdastar"]
cmd = ["hdastar", "hdastar", "hdastar"]
arg = [
["maze-4821.txt", "1"],
["maze-4821.txt", "2"],
["maze-233.txt", "1"],
["maze-233.txt", "2"],
["maze-6404.txt", "2"],
["maze-6404.txt", "4"],
["maze-6404.txt", "8"],
]


pool = Pool(processes=40)
pool = Pool(processes=5)

# run the benchmarks
results = []
Expand Down
39 changes: 39 additions & 0 deletions artifact/bench_lammps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pickle
import common_util
from multiprocessing import Pool

cmd = [
"lammps",
]
arg = [
[],
]


pool = Pool(processes=40)

# run the benchmarks
results = []
for i in range(len(cmd)):
for j in range(len(common_util.aot_variant)):
for env in ["a=b"]:
aot = cmd[i] + common_util.aot_variant[j]
results.append(pool.apply_async(common_util.run, (aot, arg[i], env)))
pool.close()
pool.join()

# print the results
results = [x.get() for x in results]
# serialize the results
with open("bench_lammps_results.pickle", "wb") as f:
pickle.dump(results, f)
for exec, output in results:
print(exec)
lines = output.split("\n")
for line in lines:
if line.__contains__("Execution time:"):
print(line)

# read the results
with open("bench_lammps_results.pickle", "rb") as f:
results = pickle.load(f)
39 changes: 39 additions & 0 deletions artifact/bench_orb_slam3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pickle
import common_util
from multiprocessing import Pool

cmd = [
"rgb",
]
arg = [
[],
]


pool = Pool(processes=40)

# run the benchmarks
results = []
for i in range(len(cmd)):
for j in range(len(common_util.aot_variant)):
for env in ["LINPACK_ARRAY_SIZE=600"]:
aot = cmd[i] + common_util.aot_variant[j]
results.append(pool.apply_async(common_util.run, (aot, arg[i], env)))
pool.close()
pool.join()

# print the results
results = [x.get() for x in results]
# serialize the results
with open("bench_linpack_results.pickle", "wb") as f:
pickle.dump(results, f)
for exec, output in results:
print(exec)
lines = output.split("\n")
for line in lines:
if line.__contains__("Execution time:"):
print(line)

# read the results
with open("bench_linpack_results.pickle", "rb") as f:
results = pickle.load(f)
11 changes: 8 additions & 3 deletions artifact/common_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ def get_func_index(func, file):
list_of_arg = [
"OMP_NUM_THREADS=1",
"OMP_NUM_THREADS=2",
"OMP_NUM_THREADS=4",
"OMP_NUM_THREADS=8",
]
aot_variant = [".aot", "-pure.aot", "-stack.aot", "-ckpt.aot", "-ckpt-br.aot"]
aot_variant = [".aot", "-pure.aot", "-stack.aot", "-ckpt-br.aot"]
# aot_variant = ["-ckpt-every-dirty.aot"]


Expand All @@ -37,14 +39,17 @@ def run(aot_file: str, arg: list[str], env: str) -> tuple[str, str]:
print(cmd)
cmd = cmd.split()
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = result.stdout.decode("utf-8")
try:
output = result.stdout.decode("utf-8")
except:
output = result.stdout
exec = " ".join([env] + [aot_file] + arg)
# print(exec)
# print(output)
return (exec, output)


if __name__ == "__main__":
print(get_func_index("recvfrom", "./test/server.wasm"))
print(get_func_index("$recv ", "./test/tcp_client.wasm"))
print(get_func_index("poll_oneoff", "./test/counter.wasm"))
print(get_func_index("sendto", "./test/client.wasm"))
Binary file added artifact/performance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 68 additions & 21 deletions gateway/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ using namespace Crafter;

std::string client_ip;
std::string server_ip;
int client_port;
int server_port;
pcap_t *handle;
int linkhdrlen = 14;
int packets = 0;
int client_fd;
int fd;
int new_fd;
std::vector<std::jthread> backend_thread;
std::vector<std::tuple<std::string, std::string, std::string>> forward_pair;
bool is_forward = false;
Expand Down Expand Up @@ -151,7 +154,7 @@ void packet_handler(u_char *user, const struct pcap_pkthdr *header, const u_char
packets += 1;
break;
}
if (is_forward) { // Skip the datalink layer header and get the IP header fields.
if (is_forward && !op_data->is_tcp) { // Skip the datalink layer header and get the IP header fields.
// init the socket
for (auto [srcip, destip, new_srcip] : forward_pair) {
if (srcip == inet_ntoa(iphdr->ip_src) && destip == inet_ntoa(iphdr->ip_dst)) {
Expand Down Expand Up @@ -229,7 +232,7 @@ void packet_handler(u_char *user, const struct pcap_pkthdr *header, const u_char
packets += 1;
break;
}
if (is_forward) { // Skip the datalink layer header and get the IP header fields.
if (is_forward && !op_data->is_tcp) { // Skip the datalink layer header and get the IP header fields.
// init the socket
for (auto [srcip_, destip_, new_srcip] : forward_pair) {
LOGV(DEBUG) << header->len << "srcip:" << srcip_ << " destip:" << destip_;
Expand Down Expand Up @@ -446,35 +449,61 @@ int main() {
op_data->addr[idx][1].ip6[4], op_data->addr[idx][1].ip6[5],
op_data->addr[idx][1].ip6[6], op_data->addr[idx][1].ip6[7]);
}
LOGV(INFO) << "server_ip:" << server_ip << ":" << op_data->addr[idx][0].port
<< " client_ip:" << client_ip << ":" << op_data->addr[idx][1].port;
server_port = op_data->addr[0][0].port;
client_port = op_data->addr[0][1].port;
LOGV(INFO) << "server_ip:" << server_ip << ":" << server_port << " client_ip:" << client_ip << ":"
<< client_port;

forward_pair.emplace_back(server_ip, client_ip, "");
// send the fin to server
op_data->op = MVVM_SOCK_FIN;
sleep(2);
if (!op_data->is_tcp) {
LOGV(INFO) << "send fin";
send_fin(client_ip, op_data->addr[idx][1].port, server_ip, op_data->addr[idx][0].port,
(char *)op_data);
send_fin(client_ip, client_port, server_ip, server_port, (char *)op_data);
} else {
LOGV(INFO) << "send fin";

/* Begin the spoofing */
arp_context = ARPSpoofingReply(server_ip, client_ip, MVVM_SOCK_INTERFACE);
PrintARPContext(*arp_context);
// block the connection
start_block(client_ip, server_ip, op_data->addr[0][1].port, op_data->addr[0][0].port);
start_block(client_ip, server_ip, client_port, server_port);

/* TCP connection victim to server */
tcp_v_to_s =
new TCPConnection(server_ip, client_ip, op_data->addr[0][1].port, op_data->addr[0][0].port,
MVVM_SOCK_INTERFACE, TCPConnection::ESTABLISHED);
tcp_s_to_v =
new TCPConnection(client_ip, server_ip, op_data->addr[0][0].port, op_data->addr[0][1].port,
MVVM_SOCK_INTERFACE, TCPConnection::ESTABLISHED); // need
tcp_v_to_s = new TCPConnection(server_ip, client_ip, client_port, server_port,
MVVM_SOCK_INTERFACE, TCPConnection::ESTABLISHED);
tcp_s_to_v = new TCPConnection(client_ip, server_ip, server_port, client_port,
MVVM_SOCK_INTERFACE, TCPConnection::ESTABLISHED); // need
/* Both connection are already established... */
// tcp_v_to_s->Sync();

new_fd = socket(AF_INET, SOCK_STREAM, 0); // Create a socket

// Forcefully attaching socket to the port
if (setsockopt(new_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &opt, sizeof(opt))) {
LOGV(ERROR) << "setsockopt";
exit(EXIT_FAILURE);
}

address.sin_family = AF_INET;
address.sin_port = htons(server_port);
// Convert IPv4 and IPv6 addresses from text to binary form
if (inet_pton(AF_INET, MVVM_SOCK_ADDR, &address.sin_addr) <= 0) {
LOGV(ERROR) << "Invalid address/ Address not supported";
exit(EXIT_FAILURE);
}

// Bind the socket to the network address and port
if (bind(new_fd, (struct sockaddr *)&address, sizeof(address)) < 0) {
LOGV(ERROR) << "bind failed" << errno;
exit(EXIT_FAILURE);
}

// Start listening for connections
if (listen(new_fd, 3) < 0) {
LOGV(ERROR) << "listen";
exit(EXIT_FAILURE);
}
LOGV(ERROR) << "Connections synchronized ";
sleep(1);
tcp_s_to_v->Sync();
Expand All @@ -489,9 +518,8 @@ int main() {
// resume
LOGV(ERROR) << "resume";
auto tmp_tuple = forward_pair[forward_pair.size() - 1];
std::get<2>(tmp_tuple) =
fmt::format("{}.{}.{}.{}", op_data->addr[0][0].ip4[0], op_data->addr[0][0].ip4[1],
op_data->addr[0][0].ip4[2], op_data->addr[0][0].ip4[3]);
auto &&tmp_ip4 = op_data->addr[0][0].ip4;
std::get<2>(tmp_tuple) = fmt::format("{}.{}.{}.{}", tmp_ip4[0], tmp_ip4[1], tmp_ip4[2], tmp_ip4[3]);
LOGV(ERROR) << "forward_pair[forward_pair.size()]" << std::get<0>(forward_pair[forward_pair.size() - 1])
<< std::get<1>(forward_pair[forward_pair.size() - 1]);
// for udp forward from source to remote
Expand All @@ -500,23 +528,42 @@ int main() {
tcp_s_to_v = new TCPConnection(fmt::format("{}.{}.{}.{}", op_data->addr[0][0].ip4[0],
op_data->addr[0][0].ip4[1], op_data->addr[0][0].ip4[2],
op_data->addr[0][0].ip4[3]),
server_ip, op_data->addr[0][0].port, op_data->addr[0][1].port,
MVVM_SOCK_INTERFACE, TCPConnection::ESTABLISHED); // need
server_ip, server_port, client_port, MVVM_SOCK_INTERFACE,
TCPConnection::ESTABLISHED); // need port
/* Both connection are already established... */
// tcp_v_to_s->Sync();
tcp_s_to_v->Sync();

// stop SYN
LOGV(ERROR) << "Connections synchronized ";

while (true) {
sleep(1);
bool closed = false;
backend_thread..emplace_back([](){
while (!closed) {
auto payload = Payload();
tcp_s_to_v->Read(payload);
if (tcp_s_to_v->GetStatus() == IS_CLOSED){
closed = true;
return;
}
if (payload.GetSize() == 0)
continue;
tcp_s_to_v->Send(payload.GetRawPointer(), sizeof(*payload.GetRawPointer()));
}
});
backend_thread..emplace_back([](){
while (!closed) {
auto payload = Payload();
tcp_v_to_s->Read(payload);
if (tcp_v_to_s->GetStatus() == IS_CLOSED){
closed = true;
return;
}
if (payload.GetSize() == 0)
continue;
tcp_v_to_s->Send(payload.GetRawPointer(), sizeof(*payload.GetRawPointer()));
}
});

} else
is_forward = true;
Expand Down
Loading

0 comments on commit 2ac2eee

Please sign in to comment.