Skip to content

Commit

Permalink
docs: Use firehose for restaurant delivery to edge replication (#1043)
Browse files Browse the repository at this point in the history
  • Loading branch information
johanandren authored Oct 18, 2023
1 parent b708b15 commit 9103b2f
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ Scala
Java
: @@snip [DroneDeliveriesServer.java](/samples/grpc/restaurant-drone-deliveries-service-java/src/main/java/central/DroneDeliveriesServer.java) { #composeAndBind }

Since we expect a high number of local-drone-control edge systems connecting to the restaurant-drone-deliveries-service
to consume the restaurant orders we configure the @extref[events-by-slice-firehose](akka:persistence-query.html#eventsbyslice-and-currenteventsbyslice)
for the projection. The firehose tries to share the stream of events across consumers connected to the same node, instead
of each consumer executing its queries in parallel, so that less load is applied to the database.

The firehose is enabled through the following configuration selecting it as query-plugin-id for the `akka.projection.grpcproducer`
and then configuring the actual underlying `akka.persistence.r2dbc.query` as query plugin for the firehose:

Scala
: @@snip [persistence.conf](/samples/grpc/restaurant-drone-deliveries-service-scala/src/main/resources/persistence.conf) { #firehose }

Java
: @@snip [persistence.conf](/samples/grpc/restaurant-drone-deliveries-service-java/src/main/resources/persistence.conf) { #firehose }

## Delivery queue actor

Expand Down
54 changes: 54 additions & 0 deletions samples/grpc/local-drone-control-java/kubernetes/deployment2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: local-drone-control-service-2
name: local-drone-control-service-2
namespace: local-drone-control-namespace
spec:
# note: the default image cannot scale out as it uses a local database
replicas: 1
selector:
matchLabels:
app: local-drone-control-service-2
template:
metadata:
labels:
app: local-drone-control-service-2
actorSystemName: local-drone-control-service-2
spec:
containers:
- name: restaurant-drone-deliveries-service-2
# use specific image version from docker publish
image: johanandren/local-drone-control:20230922-090652-37e49e0
# these will need to be increased/tuned for production environments!
resources:
limits:
memory: "512Mi"
requests:
memory: "512Mi"
cpu: "1000m"
ports:
- name: grpc
containerPort: 8080
protocol: TCP
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: JAVA_TOOL_OPTIONS
value: "-XX:InitialRAMPercentage=75 -XX:MaxRAMPercentage=75"
- name: LOCATION_ID
# one of the location ids supported by the restaurant-drone-deliveries service
value: "sweden/stockholm/norrmalm"
- name: CENTRAL_DRONE_CONTROL_HOST
# update with public endpoint for restaurant-drone-deliveries
value: k8s-restaura-restaura-5bd7dc845f-48570e637882db8c.elb.us-east-2.amazonaws.com
- name: CENTRAL_DRONE_CONTROL_PORT
value: "80"
- name: H2_DATABASE_PATH
# for state to survive restarts this would need to be a volume
# right now a restarted node will replay all orders from central
# and only report new drone updates
value: /tmp/drone-db
Empty file.
67 changes: 67 additions & 0 deletions samples/grpc/local-drone-control-scala/kubernetes/deploymentn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: local-drone-control-service-45
name: local-drone-control-service-45
namespace: local-drone-control-namespace
spec:
# note: the default image cannot scale out as it uses a local database
replicas: 1
selector:
matchLabels:
app: local-drone-control-service-45
template:
metadata:
labels:
app: local-drone-control-service-45
actorSystemName: local-drone-control-service-45
spec:
containers:
- name: restaurant-drone-deliveries-service-45
# use specific image version from docker publish
image: johanandren/local-drone-control:1.5.0-M4-31-1976d92e-20231009-1730
# these will need to be increased/tuned for production environments!
resources:
limits:
memory: "128Mi"
requests:
memory: "128Mi"
cpu: "100m"
ports:
- name: grpc
containerPort: 8080
protocol: TCP
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: JAVA_TOOL_OPTIONS
value: "-XX:InitialRAMPercentage=75 -XX:MaxRAMPercentage=75"
- name: LOCATION_ID
# one of the location ids supported by the restaurant-drone-deliveries service
value: "sweden/stockholm/45"
- name: CENTRAL_DRONE_CONTROL_HOST
# update with public endpoint for restaurant-drone-deliveries
value: k8s-restaura-restaura-7b1be84b8e-04cc949d9f276f68.elb.us-east-2.amazonaws.com
- name: CENTRAL_DRONE_CONTROL_PORT
value: "80"
- name: H2_DATABASE_PATH
# for state to survive restarts this would need to be a volume
# right now a restarted node will replay all orders from central
# and only report new drone updates
value: /tmp/drone-db
---
apiVersion: v1
kind: Service
metadata:
name: local-drone-control-service-45-svc
spec:
selector:
app: local-drone-control-service-45
type: NodePort
ports:
- protocol: TCP
port: 8080
targetPort: 8080
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ akka {
loglevel = DEBUG
}

akka.projection.grpc {
producer {
query-plugin-id = "akka.persistence.r2dbc.query"
}
}

restaurant-drone-deliveries-service {
drone-ask-timeout = 3s
restaurant-deliveries-ask-timeout = 3s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,18 @@ akka {
}
}
}

// #firehose
akka.projection.grpc {
producer {
# use the firehose for order events so that the local-drone-control consumers
# shares the same firehose instead of each lead to load on the database
query-plugin-id = "akka.persistence.query.events-by-slice-firehose"
}
}

akka.persistence.query.events-by-slice-firehose {
delegate-query-plugin-id = "akka.persistence.r2dbc.query"
}
// #firehose

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ akka {
loglevel = DEBUG
}

akka.projection.grpc {
producer {
query-plugin-id = "akka.persistence.r2dbc.query"
}
}

restaurant-drone-deliveries-service {
drone-ask-timeout = 3s
restaurant-deliveries-ask-timeout = 3s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,18 @@ akka {
}
}
}

// #firehose
akka.projection.grpc {
producer {
# use the firehose for order events so that the local-drone-control consumers
# shares the same firehose instead of each lead to load on the database
query-plugin-id = "akka.persistence.query.events-by-slice-firehose"
}
}

akka.persistence.query.events-by-slice-firehose {
delegate-query-plugin-id = "akka.persistence.r2dbc.query"
}
// #firehose

0 comments on commit 9103b2f

Please sign in to comment.