Skip to content

Commit

Permalink
Merge branch 'main' of github.com:appnet-org/appnet into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jokerwyt committed Aug 13, 2024
2 parents 20faf7a + 8cebb4d commit 1b666c1
Show file tree
Hide file tree
Showing 18 changed files with 558 additions and 71 deletions.
2 changes: 1 addition & 1 deletion compiler
Submodule compiler updated 43 files
+4 −0 .gitmodules
+20 −4 compiler/element/__init__.py
+142 −0 compiler/element/backend/envoy_native/appnettype.py
+66 −0 compiler/element/backend/envoy_native/finalizer.py
+942 −0 compiler/element/backend/envoy_native/nativegen.py
+149 −0 compiler/element/backend/envoy_native/nativetype.py
+1 −0 compiler/element/backend/envoy_native/template
+28 −0 compiler/element/backend/envoy_native/types.py
+0 −0 compiler/element/backend/envoy_wasm/__init__.py
+1 −1 compiler/element/backend/envoy_wasm/analyzer.py
+0 −0 compiler/element/backend/envoy_wasm/boilerplate.py
+4 −4 compiler/element/backend/envoy_wasm/finalizer.py
+0 −0 compiler/element/backend/envoy_wasm/templates/build.rs
+0 −0 compiler/element/backend/envoy_wasm/templates/rust-toolchain.toml
+3 −3 compiler/element/backend/envoy_wasm/wasmgen.py
+1 −1 compiler/element/backend/envoy_wasm/wasmtype.py
+1 −1 compiler/element/node.py
+297 −0 compiler/graph/backend/envoy_native.py
+28 −0 examples/elements/echo_elements/admissioncontrol.appnet
+25 −0 examples/elements/echo_elements/bandwidthlimit.appnet
+22 −0 examples/elements/echo_elements/cache.appnet
+23 −0 examples/elements/echo_elements/cachestrong.appnet
+23 −0 examples/elements/echo_elements/cacheweak.appnet
+22 −0 examples/elements/echo_elements/circuitbreaker.appnet
+14 −0 examples/elements/echo_elements/decrypt.appnet
+14 −0 examples/elements/echo_elements/encrypt.appnet
+11 −18 examples/elements/echo_elements/fault.appnet
+18 −30 examples/elements/echo_elements/firewall.appnet
+17 −30 examples/elements/echo_elements/firewallstrong.appnet
+17 −30 examples/elements/echo_elements/firewallweak.appnet
+16 −0 examples/elements/echo_elements/lbsticky.appnet
+17 −0 examples/elements/echo_elements/lbstickystrong.appnet
+17 −0 examples/elements/echo_elements/lbstickyweak.appnet
+9 −13 examples/elements/echo_elements/logging.appnet
+16 −22 examples/elements/echo_elements/metrics.appnet
+14 −0 examples/elements/echo_elements/mutation.appnet
+12 −0 examples/elements/echo_elements/null.appnet
+24 −0 examples/elements/echo_elements/ratelimit.appnet
+0 −0 examples/elements/ping_elements/firewall.appnet
+0 −0 examples/elements/ping_elements/firewallstrong.appnet
+0 −0 examples/elements/ping_elements/firewallweak.appnet
+0 −32 examples/elements/ping_elements/test.appnet
+7 −0 utils/setup.sh
7 changes: 7 additions & 0 deletions config/samples/hotel/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### Preparation

```bash
sed -i 's|<docker-username>|<your-docker-user-name>|g' config/samples/hotel/hotel_reservation.yaml
sed -i 's|<APPNET_DIR_PATH>|'"$(pwd)"'|g' config/samples/hotel/sample_hotel.yaml
```

### Deploy services

run `kubectl apply -Rf hotel_reservation.yaml`
Expand Down
34 changes: 17 additions & 17 deletions config/samples/hotel/hotel_reservation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
cpu: 1000m
requests:
cpu: 100m
# nodeName: h2.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h2.<node-name>
restartPolicy: Always
---
apiVersion: v1
Expand Down Expand Up @@ -117,7 +117,7 @@ spec:
cpu: 1000m
requests:
cpu: 100m
# nodeName: h2.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h2.<node-name>
restartPolicy: Always
status: {}
---
Expand Down Expand Up @@ -179,7 +179,7 @@ spec:
cpu: 1000m
requests:
cpu: 100m
# nodeName: h4.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h4.<node-name>
restartPolicy: Always
status: {}
---
Expand Down Expand Up @@ -241,7 +241,7 @@ spec:
cpu: 1000m
requests:
cpu: 100m
# nodeName: h2.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h2.<node-name>
restartPolicy: Always
status: {}
---
Expand Down Expand Up @@ -303,7 +303,7 @@ spec:
cpu: 1000m
requests:
cpu: 100m
# nodeName: h3.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h3.<node-name>
restartPolicy: Always
status: {}
---
Expand Down Expand Up @@ -365,7 +365,7 @@ spec:
cpu: 1000m
requests:
cpu: 100m
# nodeName: h5.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h5.<node-name>
restartPolicy: Always
status: {}
---
Expand Down Expand Up @@ -427,7 +427,7 @@ spec:
cpu: 1000m
requests:
cpu: 100m
# nodeName: h3.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h3.<node-name>
restartPolicy: Always
status: {}
---
Expand Down Expand Up @@ -490,7 +490,7 @@ spec:
cpu: 1000m
requests:
cpu: 100m
# nodeName: h2.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h2.<node-name>
restartPolicy: Always
status: {}
---
Expand Down Expand Up @@ -714,7 +714,7 @@ spec:
- mountPath: /data/db
name: user
hostname: user-db
# nodeName: h2.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h2.<node-name>
restartPolicy: Always
volumes:
- name: user
Expand Down Expand Up @@ -762,7 +762,7 @@ spec:
cpu: 1000m
requests:
cpu: 100m
# nodeName: h4.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h4.<node-name>
restartPolicy: Always
status: {}
---
Expand Down Expand Up @@ -806,7 +806,7 @@ spec:
- mountPath: /data/db
name: reservation
hostname: reservation-db
# nodeName: h4.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h4.<node-name>
restartPolicy: Always
volumes:
- name: reservation
Expand Down Expand Up @@ -854,7 +854,7 @@ spec:
- mountPath: /data/db
name: recommendation
hostname: recommendation-db
# nodeName: h2.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h2.<node-name>
restartPolicy: Always
volumes:
- name: recommendation
Expand Down Expand Up @@ -901,7 +901,7 @@ spec:
volumeMounts:
- mountPath: /data/db
name: rate
# nodeName: h3.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h3.<node-name>
restartPolicy: Always
volumes:
- name: rate
Expand Down Expand Up @@ -949,7 +949,7 @@ spec:
cpu: 1000m
requests:
cpu: 100m
# nodeName: h3.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h3.<node-name>
restartPolicy: Always
status: {}
---
Expand Down Expand Up @@ -993,7 +993,7 @@ spec:
cpu: 1000m
requests:
cpu: 100m
# nodeName: h5.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h5.<node-name>
restartPolicy: Always
status: {}
---
Expand Down Expand Up @@ -1037,7 +1037,7 @@ spec:
- mountPath: /data/db
name: profile
hostname: profile-db
# nodeName: h5.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h5.<node-name>
restartPolicy: Always
volumes:
- name: profile
Expand Down Expand Up @@ -1084,7 +1084,7 @@ spec:
volumeMounts:
- mountPath: /data/db
name: geo
# nodeName: h3.hotelbench.meshbench-pg0.clemson.cloudlab.us
# nodeName: h3.<node-name>
restartPolicy: Always
volumes:
- name: geo
Expand Down
68 changes: 68 additions & 0 deletions config/samples/prequal/prequal_client.appnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
state:
QRIF: float
num_choices: int

init():
QRIF = 0.8
num_choices = 3

req(rpc):
# Choose a subset of replicas
backends = get_backends()
sampled_backends = ramdom_choices(num_choices, 3)

# Get their load and RIF information and store it in a list
sorted_backend_info = sort(map(get_backend_info(), sampled_backends), RIF)
index = int(len(sorted_backend_info)*QRIF)

# (hot-cold lexicographic) Divide it to hot and cold backend
cold_backend = slice(sorted_backend_info, 0, index)
hot_backend = slice(sorted_backend_info, index, len(sorted_backend_info))

# if all probes are hot, then the one with lowest RIF is chosen.
# Otherwise, the cold probe with the lowest latency is chosen
match len(coldBackend) == 0:
true =>
selected = get(hot_backend, 0)
false =>
selected = min(cold_backend, latency)

set(rpc, dst, selected)
send(rpc, down)


resp(rpc):
send(rpc, up)


state:
QRIF: float
num_choices: int

init():
QRIF = 0.8
num_choices = 3

req(rpc):
# Choose a subset of replicas
backends = get_backends()
sampled_backends = ramdom_choices(backends, num_choices)

# Get their load and RIF information and store it in a list
# get_backend_info is a built-in function that receives backend name and returns a dictionary: {"backend": xxx, "latency": xxx, "RIF": xxx}
sorted_backend_info = sort(map(get_backend_info, sampled_backends), "RIF")
index = int(len(sorted_backend_info) * QRIF)

match index == 0:
true =>
# all probes are hot
selected = get(array_get(sorted_backend_info, 0), "backend")
false =>
# cold probe with the lowest latency is chosen
selected = get(array_min(sorted_backend_info, 0, index, "latency"), "backend")

set(rpc, dst, selected)
send(rpc, down)

resp(rpc):
send(rpc, up)
19 changes: 19 additions & 0 deletions config/samples/prequal/prequal_server.appnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
state:
outstanding_req_count: int
request_map<int, float>

init():
outstanding_req_count = 0

req(rpc):
outstanding_req_count = outstanding_req_count + 1
rpc_id = get(rpc, "id")
set(request_map, rpc_id, current_time())
send(rpc, up)

resp(rpc):
outstanding_req_count = outstanding_req_count - 1
rpc_id = get(rpc, "id")
latency = time_diff(current_time(), get(request_map, rpc_id))
send(rpc, down)

26 changes: 0 additions & 26 deletions config/samples/sample_hotel.yaml

This file was deleted.

26 changes: 0 additions & 26 deletions config/samples/sample_ping.yaml

This file was deleted.

87 changes: 87 additions & 0 deletions config/samples/servicerouter/sr_client.appnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
state:
// backend id -> queue length, timestamp
load_map: Map<int, <int, float>>
epsilon: float

init():
epsilon = 1.0
num_choices = 3

req(rpc):
shard_key = get(rpc, "key")
backends = get_backends(shard_key)

sampled_backends = random_choices(backends, num_choices)


selected = 0
min_load = inf
for each backend in sampled_backends:
backend_load, last_ts = get(load_map, backend)
freshness = time_diff(current_time(), last_ts) - epsilon

match freshness > 0:
true =>
pass
false =>
backend_load = get(load_map_global, backend)
set(load_map, (backendload, current_time())

match backend_load < min_load:
true =>
selected = backend
min_load = backend_load
false =>
pass

set(rpc, "dst", selected)
send(rpc, down)

resp(rpc):
load = get(rpc, "load")
dst = get(rpc, "dst")
set(load_map, dst, (load, current_time()))
send(rpc, up)


state:
load_map: Map<int, <int, float>>
epsilon: float

init():
epsilon = 1.0

req(rpc):
shard_key = get(rpc, "key")
backends = get_backends(shard_key)

sampled_backends = random_choices(backends, 3)

# Filter function to update freshness and backend load
update_backend = lambda backend:
backend_load, last_ts = get(load_map, backend)
freshness = time_diff(current_time(), last_ts) - epsilon
match freshness > 0:
true => (backend, backend_load)
false => (backend, get(load_map_global, backend))

updated_backends = map(sampled_backends, update_backend)

# Reduce function to find the backend with the minimum load
min_backend = reduce(updated_backends, lambda acc, backend_tuple:
match backend_tuple[1] < acc[1]:
true => backend_tuple
false => acc, (None, inf))

selected, min_load = min_backend

set(rpc, "dst", selected)
send(rpc, down)

resp(rpc):
load = get(rpc, "load")
dst = get(rpc, "dst")
set(load_map, dst, (load, current_time()))
send(rpc, up)


Loading

0 comments on commit 1b666c1

Please sign in to comment.