Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7d75f6899 | ||
|
|
96cf433793 |
@@ -52,6 +52,35 @@ Configuration is read from environment variables:
|
||||
| `RBCS_DIGEST` | *(unset)* | Hash the key with this algorithm (e.g. `sha256`) |
|
||||
| `RBCS_MAX_AGE` | `7d` | Value TTL (`s`/`m`/`h`/`d`) |
|
||||
|
||||
### Configuring Granian
|
||||
|
||||
The server runs on [Granian](https://github.com/emmett-framework/granian) via
|
||||
its RSGI interface. Any granian option can be configured with its standard
|
||||
`GRANIAN_*` environment variables (see `granian --help`), for example:
|
||||
|
||||
```bash
|
||||
GRANIAN_LOOP=rloop GRANIAN_WORKERS=4 GRANIAN_HTTP=2 rbcs-server
|
||||
```
|
||||
|
||||
Every granian CLI option has a matching `GRANIAN_*` variable
|
||||
(`GRANIAN_LOOP`, `GRANIAN_WORKERS`, `GRANIAN_HTTP`, `GRANIAN_TASK_IMPL`,
|
||||
`GRANIAN_RUNTIME_THREADS`, `GRANIAN_BLOCKING_THREADS`, `GRANIAN_LOG_LEVEL`,
|
||||
`GRANIAN_METRICS`, `GRANIAN_WS`, ...).
|
||||
|
||||
When a `GRANIAN_*` variable and the corresponding `RBCS_*` variable are both
|
||||
set, the granian one wins:
|
||||
|
||||
- `GRANIAN_HOST` overrides `RBCS_HOST` (default `127.0.0.1`)
|
||||
- `GRANIAN_PORT` overrides `RBCS_PORT` (default `8080`)
|
||||
- `GRANIAN_INTERFACE` overrides the default `rsgi` interface
|
||||
|
||||
The Docker image ships the `rloop` event loop, so `GRANIAN_LOOP=rloop` works
|
||||
out of the box:
|
||||
|
||||
```bash
|
||||
docker run -e GRANIAN_LOOP=rloop -e RBCS_MEMCACHE_HOST=memcached kaya-rbcs
|
||||
```
|
||||
|
||||
The app is also a plain ASGI application, so it can be served by any ASGI
|
||||
server, e.g. `daphne kaya_rbcs.app:app`.
|
||||
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
# Manually-triggered benchmark jobs comparing rbcs (java) vs rbcs-kaya (kaya-rbcs).
|
||||
# Create them with:
|
||||
# kubectl create -f k8s/benchmark-jobs.yaml
|
||||
# (or `kubectl apply` — they only run when created, not on updates).
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: rbcs-client-config
|
||||
namespace: rbcs
|
||||
data:
|
||||
rbcs-client.xml: |
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<profiles xmlns="urn:net.woggioni.rbcs.client">
|
||||
<profile name="rbcs"
|
||||
base-url="http://rbcs:8080/"
|
||||
max-connections="50"
|
||||
enable-compression="false">
|
||||
<no-auth/>
|
||||
</profile>
|
||||
<profile name="rbcs-kaya"
|
||||
base-url="http://rbcs-kaya:8080/"
|
||||
max-connections="50"
|
||||
enable-compression="false">
|
||||
<no-auth/>
|
||||
</profile>
|
||||
</profiles>
|
||||
---
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: benchmark-rbcs
|
||||
namespace: rbcs
|
||||
labels:
|
||||
role: benchmark
|
||||
target: rbcs
|
||||
spec:
|
||||
backoffLimit: 1
|
||||
ttlSecondsAfterFinished: 3600
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
role: benchmark
|
||||
target: rbcs
|
||||
spec:
|
||||
restartPolicy: Never
|
||||
containers:
|
||||
- name: client
|
||||
image: gitea.woggioni.net/woggioni/rbcs:latest
|
||||
args:
|
||||
- client
|
||||
- -p
|
||||
- rbcs
|
||||
- benchmark
|
||||
- -s
|
||||
- "256"
|
||||
- -e
|
||||
- "10000"
|
||||
env:
|
||||
- name: RBCS_CONFIGURATION_DIR
|
||||
value: /etc/rbcs-config
|
||||
volumeMounts:
|
||||
- name: client-config
|
||||
mountPath: /etc/rbcs-config
|
||||
readOnly: true
|
||||
resources:
|
||||
requests:
|
||||
cpu: "1"
|
||||
memory: 512Mi
|
||||
limits:
|
||||
cpu: "1"
|
||||
memory: 512Mi
|
||||
volumes:
|
||||
- name: client-config
|
||||
configMap:
|
||||
name: rbcs-client-config
|
||||
items:
|
||||
- key: rbcs-client.xml
|
||||
path: rbcs-client.xml
|
||||
---
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: benchmark-kaya-rbcs
|
||||
namespace: rbcs
|
||||
labels:
|
||||
role: benchmark
|
||||
target: rbcs-kaya
|
||||
spec:
|
||||
backoffLimit: 1
|
||||
ttlSecondsAfterFinished: 3600
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
role: benchmark
|
||||
target: rbcs-kaya
|
||||
spec:
|
||||
restartPolicy: Never
|
||||
containers:
|
||||
- name: client
|
||||
image: gitea.woggioni.net/woggioni/rbcs:latest
|
||||
args:
|
||||
- client
|
||||
- -p
|
||||
- rbcs-kaya
|
||||
- benchmark
|
||||
- -s
|
||||
- "256"
|
||||
- -e
|
||||
- "10000"
|
||||
env:
|
||||
- name: RBCS_CONFIGURATION_DIR
|
||||
value: /etc/rbcs-config
|
||||
volumeMounts:
|
||||
- name: client-config
|
||||
mountPath: /etc/rbcs-config
|
||||
readOnly: true
|
||||
resources:
|
||||
requests:
|
||||
cpu: "1"
|
||||
memory: 512Mi
|
||||
limits:
|
||||
cpu: "1"
|
||||
memory: 512Mi
|
||||
volumes:
|
||||
- name: client-config
|
||||
configMap:
|
||||
name: rbcs-client-config
|
||||
items:
|
||||
- key: rbcs-client.xml
|
||||
path: rbcs-client.xml
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: rbcs
|
||||
labels:
|
||||
kubernetes.io/metadata.name: rbcs
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: memcached
|
||||
namespace: rbcs
|
||||
labels:
|
||||
app: memcached
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: memcached
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: memcached
|
||||
spec:
|
||||
containers:
|
||||
- name: memcached
|
||||
image: memcached:alpine
|
||||
args: ["-m", "1024"]
|
||||
ports:
|
||||
- name: memcache
|
||||
containerPort: 11211
|
||||
resources:
|
||||
requests:
|
||||
cpu: "1"
|
||||
memory: 1Gi
|
||||
limits:
|
||||
cpu: "1"
|
||||
memory: 1Gi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: memcached
|
||||
namespace: rbcs
|
||||
spec:
|
||||
selector:
|
||||
app: memcached
|
||||
ports:
|
||||
- port: 11211
|
||||
targetPort: 11211
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: rbcs-server-config
|
||||
namespace: rbcs
|
||||
data:
|
||||
rbcs-server.xml: |
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<rbcs:server xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:rbcs="urn:net.woggioni.rbcs.server"
|
||||
xmlns:rbcs-memcache="urn:net.woggioni.rbcs.server.memcache"
|
||||
xs:schemaLocation="urn:net.woggioni.rbcs.server.memcache jpms://net.woggioni.rbcs.server.memcache/net/woggioni/rbcs/server/memcache/schema/rbcs-memcache.xsd urn:net.woggioni.rbcs.server jpms://net.woggioni.rbcs.server/net/woggioni/rbcs/server/schema/rbcs-server.xsd">
|
||||
<bind host="0.0.0.0" port="8080" incoming-connections-backlog-size="1024"/>
|
||||
<cache xs:type="rbcs-memcache:memcacheCacheType" max-age="P1D" key-prefix="rbcs">
|
||||
<server host="memcached" port="11211" max-connections="50" connection-timeout="PT10S"/>
|
||||
</cache>
|
||||
<authentication>
|
||||
<none/>
|
||||
</authentication>
|
||||
</rbcs:server>
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: rbcs
|
||||
namespace: rbcs
|
||||
labels:
|
||||
app: rbcs
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: rbcs
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: rbcs
|
||||
spec:
|
||||
containers:
|
||||
- name: rbcs
|
||||
image: gitea.woggioni.net/woggioni/rbcs:memcache
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 8080
|
||||
env:
|
||||
- name: RBCS_CONFIGURATION_DIR
|
||||
value: /etc/rbcs-config
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: /etc/rbcs-config
|
||||
readOnly: true
|
||||
resources:
|
||||
requests:
|
||||
cpu: "1"
|
||||
memory: 512Mi
|
||||
limits:
|
||||
cpu: "1"
|
||||
memory: 512Mi
|
||||
volumes:
|
||||
- name: config
|
||||
configMap:
|
||||
name: rbcs-server-config
|
||||
items:
|
||||
- key: rbcs-server.xml
|
||||
path: rbcs-server.xml
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: rbcs
|
||||
namespace: rbcs
|
||||
spec:
|
||||
selector:
|
||||
app: rbcs
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: rbcs-kaya
|
||||
namespace: rbcs
|
||||
labels:
|
||||
app: rbcs-kaya
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: rbcs-kaya
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: rbcs-kaya
|
||||
spec:
|
||||
containers:
|
||||
- name: rbcs-kaya
|
||||
image: gitea.woggioni.net/woggioni-opencode-agent/kaya-rbcs:0.0.2
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 8080
|
||||
env:
|
||||
- name: RBCS_HOST
|
||||
value: "0.0.0.0"
|
||||
- name: RBCS_PORT
|
||||
value: "8080"
|
||||
- name: RBCS_MEMCACHE_HOST
|
||||
value: memcached
|
||||
- name: RBCS_MEMCACHE_PORT
|
||||
value: "11211"
|
||||
- name: RBCS_KEY_PREFIX
|
||||
value: "kaya"
|
||||
resources:
|
||||
requests:
|
||||
cpu: "1"
|
||||
memory: 512Mi
|
||||
limits:
|
||||
cpu: "1"
|
||||
memory: 512Mi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: rbcs-kaya
|
||||
namespace: rbcs
|
||||
spec:
|
||||
selector:
|
||||
app: rbcs-kaya
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
@@ -0,0 +1,134 @@
|
||||
# Default deny: no traffic in or out of the namespace unless explicitly allowed below.
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: default-deny-all
|
||||
namespace: rbcs
|
||||
spec:
|
||||
podSelector: {}
|
||||
policyTypes: [Ingress, Egress]
|
||||
---
|
||||
# Allow all pods to resolve services via cluster DNS.
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: allow-dns-egress
|
||||
namespace: rbcs
|
||||
spec:
|
||||
podSelector: {}
|
||||
policyTypes: [Egress]
|
||||
egress:
|
||||
- to:
|
||||
- namespaceSelector:
|
||||
matchLabels:
|
||||
kubernetes.io/metadata.name: kube-system
|
||||
podSelector:
|
||||
matchLabels:
|
||||
k8s-app: kube-dns
|
||||
ports:
|
||||
- protocol: UDP
|
||||
port: 53
|
||||
- protocol: TCP
|
||||
port: 53
|
||||
---
|
||||
# memcached: only the two cache servers may reach it; it needs no egress.
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: memcached-allow
|
||||
namespace: rbcs
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: memcached
|
||||
policyTypes: [Ingress, Egress]
|
||||
ingress:
|
||||
- from:
|
||||
- podSelector:
|
||||
matchExpressions:
|
||||
- key: app
|
||||
operator: In
|
||||
values: [rbcs, rbcs-kaya]
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 11211
|
||||
egress: []
|
||||
---
|
||||
# rbcs (java): reachable by benchmark client pods only; egress to memcached only.
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: rbcs-allow
|
||||
namespace: rbcs
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: rbcs
|
||||
policyTypes: [Ingress, Egress]
|
||||
ingress:
|
||||
- from:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
role: benchmark
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 8080
|
||||
egress:
|
||||
- to:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: memcached
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 11211
|
||||
---
|
||||
# rbcs-kaya (kaya-rbcs): reachable by benchmark client pods only; egress to memcached only.
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: rbcs-kaya-allow
|
||||
namespace: rbcs
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: rbcs-kaya
|
||||
policyTypes: [Ingress, Egress]
|
||||
ingress:
|
||||
- from:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
role: benchmark
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 8080
|
||||
egress:
|
||||
- to:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: memcached
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 11211
|
||||
---
|
||||
# Benchmark client pods: no ingress; egress only to the two cache servers.
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: benchmark-allow
|
||||
namespace: rbcs
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
role: benchmark
|
||||
policyTypes: [Ingress, Egress]
|
||||
ingress: []
|
||||
egress:
|
||||
- to:
|
||||
- podSelector:
|
||||
matchExpressions:
|
||||
- key: app
|
||||
operator: In
|
||||
values: [rbcs, rbcs-kaya]
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 8080
|
||||
@@ -26,6 +26,7 @@ dependencies = [
|
||||
server = [
|
||||
"kaya-rsgi",
|
||||
"granian",
|
||||
"rloop",
|
||||
]
|
||||
dev = [
|
||||
"httpx",
|
||||
|
||||
@@ -4,3 +4,4 @@ kaya-core
|
||||
aiomcache
|
||||
kaya-rsgi
|
||||
granian
|
||||
rloop
|
||||
|
||||
@@ -25,6 +25,8 @@ pwo==0.1.2
|
||||
# via
|
||||
# kaya-core
|
||||
# kaya-rsgi
|
||||
rloop==0.3.1
|
||||
# via -r requirements.in
|
||||
typing-extensions==4.16.0
|
||||
# via
|
||||
# kaya-core
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
import sys
|
||||
from typing import List, NoReturn
|
||||
|
||||
@@ -14,15 +15,17 @@ def main() -> NoReturn:
|
||||
) from exc
|
||||
|
||||
config = Config.from_env()
|
||||
args: List[str] = [
|
||||
'--interface',
|
||||
'rsgi',
|
||||
'--host',
|
||||
config.host,
|
||||
'--port',
|
||||
str(config.port),
|
||||
'kaya_rbcs.app:app',
|
||||
]
|
||||
args: List[str] = []
|
||||
# Only inject our own values when the equivalent GRANIAN_* environment
|
||||
# variable is not set, so every granian option stays configurable via
|
||||
# granian's standard GRANIAN_* environment variables.
|
||||
if not os.getenv('GRANIAN_INTERFACE'):
|
||||
args += ['--interface', 'rsgi']
|
||||
if not os.getenv('GRANIAN_HOST'):
|
||||
args += ['--host', config.host]
|
||||
if not os.getenv('GRANIAN_PORT'):
|
||||
args += ['--port', str(config.port)]
|
||||
args.append('kaya_rbcs.app:app')
|
||||
sys.argv = [sys.argv[0], *args]
|
||||
entrypoint() # type: ignore[no-untyped-call]
|
||||
raise SystemExit(0)
|
||||
|
||||
Reference in New Issue
Block a user