Skip to content

Commit

Permalink
add a simple go application to demo acceleration
Browse files Browse the repository at this point in the history
  • Loading branch information
y-f-u committed Mar 25, 2024
1 parent 0cb4373 commit 1a6e410
Show file tree
Hide file tree
Showing 10 changed files with 564 additions and 0 deletions.
6 changes: 6 additions & 0 deletions acceleration/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM golang

ADD . .

ENTRYPOINT ["go", "run", "main.go"]

17 changes: 17 additions & 0 deletions acceleration/Dockerfile.spiceai
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM rust as build

RUN apt-get update && apt-get install -yqq git

RUN git clone https://github.com/spiceai/spiceai.git

RUN cd spiceai && make -C bin/spiced

FROM debian

RUN apt-get update && apt-get install -yqq libssl-dev sqlite3

COPY --from=build /spiceai/target/release/spiced /usr/local/bin

WORKDIR /root

ENTRYPOINT ["spiced", "--flight", "0.0.0.0:50051"]
159 changes: 159 additions & 0 deletions acceleration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# Sample

This sample showcases the way to use spiced to simplify the process of building a CQRS pattern for your application.

In this sample, we have a `/orders` API which creates a random order with a random count.

There are 3 `/rankings` API to show the top 5 selling products:
- /rankings - fetch data from postgres
- /rankings-accelerated - fetch data from spiced runtime without materialized ranking view, it pulls data from postgres into edge acceleration to improve query performance
- /rankings-materialized - fetch data from spiced runtime with materialized ranking view, it pulls data from ranking view from the previous spiced runtime and accelerates it locally

## Performance benchmark using oha

### From Postgres
```bash
…/sample-1 main ❯ oha -n20000 -c100 'http://localhost:9999/ranking'
Summary:
Success rate: 100.00%
Total: 47.4194 secs
Slowest: 1.1856 secs
Fastest: 0.0003 secs
Average: 0.2364 secs
Requests/sec: 421.7687

Total data: 2.70 MiB
Size/request: 14
Size/sec: 58.41 KiB

Response time histogram:
0.000 [1] |
0.119 [8011] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.237 [2189] |■■■■■■■■
0.356 [3873] |■■■■■■■■■■■■■■■
0.474 [3152] |■■■■■■■■■■■■
0.593 [1840] |■■■■■■■
0.711 [736] |■■
0.830 [154] |
0.949 [30] |
1.067 [9] |
1.186 [5] |

Response time distribution:
10.00% in 0.0029 secs
25.00% in 0.0523 secs
50.00% in 0.2186 secs
75.00% in 0.3927 secs
90.00% in 0.4981 secs
95.00% in 0.5898 secs
99.00% in 0.7113 secs
99.90% in 0.9032 secs
99.99% in 1.1139 secs


Details (average, fastest, slowest):
DNS+dialup: 0.0027 secs, 0.0012 secs, 0.0031 secs
DNS-lookup: 0.0000 secs, 0.0000 secs, 0.0002 secs

Status code distribution:
[200] 19964 responses
[500] 36 responses
```

### From spiced with acceleration, without materialized view

```bash
…/sample-1 main 47s ❯ oha -n20000 -c100 'http://localhost:9999/ranking-accelerated'
Summary:
Success rate: 100.00%
Total: 22.3230 secs
Slowest: 0.2257 secs
Fastest: 0.0058 secs
Average: 0.1115 secs
Requests/sec: 895.9356

Total data: 2.71 MiB
Size/request: 14
Size/sec: 124.24 KiB

Response time histogram:
0.006 [1] |
0.028 [146] |
0.050 [744] |■■■■■
0.072 [2089] |■■■■■■■■■■■■■■■
0.094 [3462] |■■■■■■■■■■■■■■■■■■■■■■■■■
0.116 [4356] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.138 [4175] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.160 [3134] |■■■■■■■■■■■■■■■■■■■■■■■
0.182 [1467] |■■■■■■■■■■
0.204 [384] |■■
0.226 [42] |

Response time distribution:
10.00% in 0.0634 secs
25.00% in 0.0854 secs
50.00% in 0.1122 secs
75.00% in 0.1379 secs
90.00% in 0.1588 secs
95.00% in 0.1701 secs
99.00% in 0.1912 secs
99.90% in 0.2083 secs
99.99% in 0.2235 secs


Details (average, fastest, slowest):
DNS+dialup: 0.0027 secs, 0.0012 secs, 0.0032 secs
DNS-lookup: 0.0000 secs, 0.0000 secs, 0.0002 secs

Status code distribution:
[200] 20000 responses
```

### From spiced with acceleration, with materialized view

```bash
…/sample-1 main ❯ oha -n20000 -c100 'http://localhost:9999/ranking-materialized'
Summary:
Success rate: 100.00%
Total: 4.4439 secs
Slowest: 0.0628 secs
Fastest: 0.0010 secs
Average: 0.0222 secs
Requests/sec: 4500.5780

Total data: 2.71 MiB
Size/request: 14
Size/sec: 624.10 KiB

Response time histogram:
0.001 [1] |
0.007 [65] |
0.013 [953] |■■■
0.020 [6626] |■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.026 [7627] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.032 [3117] |■■■■■■■■■■■■■
0.038 [1126] |■■■■
0.044 [358] |
0.050 [99] |
0.057 [17] |
0.063 [11] |

Response time distribution:
10.00% in 0.0153 secs
25.00% in 0.0178 secs
50.00% in 0.0212 secs
75.00% in 0.0254 secs
90.00% in 0.0307 secs
95.00% in 0.0346 secs
99.00% in 0.0421 secs
99.90% in 0.0533 secs
99.99% in 0.0623 secs


Details (average, fastest, slowest):
DNS+dialup: 0.0027 secs, 0.0013 secs, 0.0033 secs
DNS-lookup: 0.0000 secs, 0.0000 secs, 0.0001 secs

Status code distribution:
[200] 20000 responses
```
66 changes: 66 additions & 0 deletions acceleration/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
services:
web:
build: .
ports:
- "9999:8080"
depends_on:
- postgres
- spiced
- spiced-materialized
environment:
- POSTGRES_CONN=host=postgres port=5432 dbname=postgres user=postgres password=postgres sslmode=disable
spiced:
build:
dockerfile: Dockerfile.spiceai
depends_on:
- postgres
volumes:
- ./spicepod.yaml:/root/spicepod.yaml
expose:
- "50051"
deploy:
resources:
limits:
cpus: '2'
memory: 2G
reservations:
cpus: '2'
memory: 2G
spiced-materialized:
build:
dockerfile: Dockerfile.spiceai
depends_on:
- spiced
volumes:
- ./spicepod-materialized.yaml:/root/spicepod.yaml
expose:
- "50051"
entrypoint:
- /bin/bash
- -c
- |
sleep 10 && spiced --flight 0.0.0.0:50051
deploy:
resources:
limits:
cpus: '2'
memory: 2G
reservations:
cpus: '2'
memory: 2G
postgres:
image: "postgres:alpine"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
expose:
- "5432"
deploy:
resources:
limits:
cpus: '2'
memory: 2G
reservations:
cpus: '2'
memory: 2G
29 changes: 29 additions & 0 deletions acceleration/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module github.com/spiceai/sample-1

go 1.22.1

require (
github.com/apache/arrow/go/v16 v16.0.0-20240325050224-f100eff39fd3
github.com/lib/pq v1.10.9
)

require (
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/flatbuffers v24.3.7+incompatible // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.19.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
88 changes: 88 additions & 0 deletions acceleration/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
github.com/apache/arrow/go/v16 v16.0.0-20240325050224-f100eff39fd3 h1:MUo4Mm9RGXxm6SiVxVjyz6jadI5yVBOx5l9yYyNP3bw=
github.com/apache/arrow/go/v16 v16.0.0-20240325050224-f100eff39fd3/go.mod h1:VVbdJivCXZAJ6IhOSCSzk/RVQ/PlcitjskAWEST3Sc0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/flatbuffers v24.3.7+incompatible h1:BxGUkIQnOciBu33bd5BdvqY8Qvo0O/GR4SPhh7x9Ed0=
github.com/google/flatbuffers v24.3.7+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
gonum.org/v1/gonum v0.15.0 h1:2lYxjRbTYyxkJxlhC+LvJIx3SsANPdRybu1tGj9/OrQ=
gonum.org/v1/gonum v0.15.0/go.mod h1:xzZVBJBtS+Mz4q0Yl2LJTk+OxOg4jiXZ7qBoM0uISGo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 h1:AjyfHzEPEFp/NpvfN5g+KDla3EMojjhRVZc1i7cj+oM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s=
google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk=
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI=
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4=
modernc.org/libc v1.41.0 h1:g9YAc6BkKlgORsUWj+JwqoB1wU3o4DE3bM3yvA3k+Gk=
modernc.org/libc v1.41.0/go.mod h1:w0eszPsiXoOnoMJgrXjglgLuDy/bt5RR4y3QzUUeodY=
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
modernc.org/memory v1.7.2 h1:Klh90S215mmH8c9gO98QxQFsY+W451E8AnzjoE2ee1E=
modernc.org/memory v1.7.2/go.mod h1:NO4NVCQy0N7ln+T9ngWqOQfi7ley4vpwvARR+Hjw95E=
modernc.org/sqlite v1.29.5 h1:8l/SQKAjDtZFo9lkJLdk8g9JEOeYRG4/ghStDCCTiTE=
modernc.org/sqlite v1.29.5/go.mod h1:S02dvcmm7TnTRvGhv8IGYyLnIt7AS2KPaB1F/71p75U=
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
Loading

0 comments on commit 1a6e410

Please sign in to comment.