Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: benchmarks #450

Merged
merged 35 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4578926
wip
gfyrag Jul 19, 2023
a0c3475
feat: add runID as resource attribute
gfyrag Jul 19, 2023
5782fdc
feat: gracefully stop ledger container
gfyrag Jul 19, 2023
0f67aec
feat: add debug
gfyrag Jul 19, 2023
7d078ae
fix: container stop
gfyrag Jul 19, 2023
93b8022
feat: Add k6 script
flemzord Jul 19, 2023
72441a5
feat: export data from prometheus
gfyrag Jul 20, 2023
c6f33ce
feat: update following rebase
gfyrag Jul 20, 2023
d727fe7
feat: Upgrade tests with k6
flemzord Jul 20, 2023
906f06b
fix: ledger stopping
gfyrag Jul 20, 2023
1c3e1a7
fix: ledger stopping
gfyrag Jul 20, 2023
93ae31f
feat: Update configuration
flemzord Jul 20, 2023
678a153
feat: Update configuration
flemzord Jul 20, 2023
ba698d6
feat: add cpuCount
gfyrag Jul 20, 2023
80cb777
feat: disable prometheus data export
gfyrag Jul 20, 2023
c549908
feat: Update configuration
flemzord Jul 20, 2023
d4db1aa
feat: Update
flemzord Jul 20, 2023
5ab397c
feat: Update
flemzord Jul 20, 2023
595daa2
feat: add metric about locking
gfyrag Jul 21, 2023
0c68396
fix: metrics frequency
gfyrag Jul 21, 2023
3659d40
feat: Upate configuration
flemzord Jul 21, 2023
9a42398
feat: Upate configuration
flemzord Jul 21, 2023
5b42110
fix: db lifecycle
gfyrag Jul 21, 2023
4ce78da
feat: add auto explain on postgres
gfyrag Jul 21, 2023
f0ee93c
chore: Add bench
flemzord Aug 8, 2023
a0b62b7
chore: Update benchmarks
flemzord Aug 8, 2023
9e33c11
chore: upgrade k6 & add README.md
flemzord Aug 8, 2023
c355de5
chore: Nmscript ugprade
flemzord Aug 8, 2023
b46539d
feat: Add dashboard provisionning
flemzord Aug 9, 2023
556005d
feat: Add dashboard provisionning
flemzord Aug 9, 2023
f14a9f1
feat: not drop postgres container between each test
gfyrag Aug 9, 2023
cfd3965
feat: add postgres config
gfyrag Aug 9, 2023
c996750
feat: some optimization
gfyrag Aug 9, 2023
69536ca
feat: clean
gfyrag Sep 12, 2023
23fc59a
chore: fix all lint
flemzord Nov 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [Formance Stack](https://formance.com) • [![Ledger Stars](https://img.shields.io/github/stars/formancehq/ledger?label=Ledger%20stars)](https://github.com/formancehq/ledger/stargazers) [![License MIT](https://img.shields.io/badge/license-mit-purple)](https://github.com/formancehq/ledger/blob/main/LICENSE) [![YCombinator](https://img.shields.io/badge/Backed%20by-Y%20Combinator-%23f26625)](https://www.ycombinator.com/companies/formance-fka-numary) [![slack](https://img.shields.io/badge/slack-formance-brightgreen.svg?logo=slack)](https://bit.ly/formance-slack)
[Formance Stack](https://formance.com) • [![Ledger Stars](https://img.shields.io/github/stars/formancehq/ledger?label=Ledger%20stars)](https://github.com/formancehq/ledger/stargazers) [![License MIT](https://img.shields.io/badge/license-mit-purple)](https://github.com/formancehq/ledger/blob/main/LICENSE) [![YCombinator](https://img.shields.io/badge/Backed%20by-Y%20Combinator-%23f26625)](https://www.ycombinator.com/companies/formance-fka-numary) [![slack](https://img.shields.io/badge/slack-formance-brightgreen.svg?logo=slack)](https://bit.ly/formance-slack)

Formance is a highly modular developer platform to build and operate complex money flows of any size and shapes. It comes with several components, that can be used as a whole as the Formance Stack or separately as standalone micro-services and libraries:

Expand Down
5 changes: 3 additions & 2 deletions components/ledger/internal/api/bulk/bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/formancehq/ledger/internal"
"math/big"

ledger "github.com/formancehq/ledger/internal"
"github.com/formancehq/ledger/internal/api/backend"
"github.com/formancehq/ledger/internal/api/shared"
"github.com/formancehq/ledger/internal/engine/command"
"github.com/formancehq/stack/libs/go-libs/metadata"
"math/big"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion components/ledger/internal/api/v2/controllers_bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package v2

import (
"encoding/json"
"net/http"

"github.com/formancehq/ledger/internal/api/bulk"
"github.com/formancehq/ledger/internal/api/shared"
sharedapi "github.com/formancehq/stack/libs/go-libs/api"
"net/http"
)

func bulkHandler(w http.ResponseWriter, r *http.Request) {
Expand Down
13 changes: 7 additions & 6 deletions components/ledger/internal/api/v2/controllers_bulk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ package v2_test
import (
"bytes"
"fmt"
"math/big"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"time"

ledger "github.com/formancehq/ledger/internal"
"github.com/formancehq/ledger/internal/api/backend"
"github.com/formancehq/ledger/internal/api/bulk"
Expand All @@ -14,12 +21,6 @@ import (
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"math/big"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"time"
)

func TestBulk(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package v2_test
import (
"bytes"
"fmt"
"github.com/formancehq/ledger/internal/api/shared"
"math/big"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"time"

"github.com/formancehq/ledger/internal/api/shared"

ledger "github.com/formancehq/ledger/internal"
v2 "github.com/formancehq/ledger/internal/api/v2"
"github.com/formancehq/ledger/internal/engine/command"
Expand Down
5 changes: 3 additions & 2 deletions components/ledger/internal/api/v2/utils.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package v2

import (
"io"
"net/http"

ledger "github.com/formancehq/ledger/internal"
"github.com/formancehq/ledger/internal/storage/ledgerstore"
"github.com/formancehq/stack/libs/go-libs/collectionutils"
"github.com/formancehq/stack/libs/go-libs/pointer"
"github.com/formancehq/stack/libs/go-libs/query"
"io"
"net/http"
)

func getPITFilter(r *http.Request) (*ledgerstore.PITFilter, error) {
Expand Down
3 changes: 3 additions & 0 deletions components/ledger/internal/engine/command/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"sync"
"sync/atomic"
"time"

"github.com/formancehq/stack/libs/go-libs/collectionutils"
"github.com/formancehq/stack/libs/go-libs/logging"
Expand Down Expand Up @@ -33,6 +34,7 @@ type Accounts struct {
type lockIntent struct {
accounts Accounts
acquired chan struct{}
at time.Time
}

func (intent *lockIntent) tryLock(ctx context.Context, chain *DefaultLocker) bool {
Expand Down Expand Up @@ -105,6 +107,7 @@ func (defaultLocker *DefaultLocker) Lock(ctx context.Context, accounts Accounts)
intent := &lockIntent{
accounts: accounts,
acquired: make(chan struct{}),
at: time.Now(),
}

recheck := func() {
Expand Down
1 change: 1 addition & 0 deletions components/ledger/internal/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ledger

import (
"fmt"

"github.com/formancehq/stack/libs/go-libs/metadata"
)

Expand Down
3 changes: 2 additions & 1 deletion components/ledger/internal/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package ledger

import (
"fmt"
"github.com/pkg/errors"
"math/big"

"github.com/pkg/errors"

"github.com/formancehq/stack/libs/go-libs/metadata"
)

Expand Down
3 changes: 0 additions & 3 deletions components/ledger/libs/otlp/otlpmetrics/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package otlpmetrics

import (
"context"
"fmt"
"time"

"github.com/formancehq/stack/libs/go-libs/logging"
Expand Down Expand Up @@ -64,11 +63,9 @@ func MetricsModule(cfg ModuleConfig) fx.Option {
otlp.LoadResource(cfg.ServiceName, cfg.ResourceAttributes),
fx.Decorate(fx.Annotate(func(mp *sdkmetric.MeterProvider) metric.MeterProvider { return mp }, fx.As(new(metric.MeterProvider)))),
fx.Provide(fx.Annotate(func(options ...sdkmetric.Option) *sdkmetric.MeterProvider {
fmt.Println("run meter provider with options", options)
return sdkmetric.NewMeterProvider(options...)
}, fx.ParamTags(metricsProviderOptionKey))),
fx.Invoke(func(lc fx.Lifecycle, metricProvider *sdkmetric.MeterProvider, options ...runtime.Option) {
fmt.Println("start meter provider")
// set global propagator to tracecontext (the default is no-op).
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(
b3.New(), propagation.TraceContext{})) // B3 format is common and used by zipkin. Always enabled right now.
Expand Down
3 changes: 0 additions & 3 deletions libs/go-libs/otlp/otlpmetrics/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package otlpmetrics

import (
"context"
"fmt"
"time"

"github.com/formancehq/stack/libs/go-libs/logging"
Expand Down Expand Up @@ -64,11 +63,9 @@ func MetricsModule(cfg ModuleConfig) fx.Option {
otlp.LoadResource(cfg.ServiceName, cfg.ResourceAttributes),
fx.Decorate(fx.Annotate(func(mp *sdkmetric.MeterProvider) metric.MeterProvider { return mp }, fx.As(new(metric.MeterProvider)))),
fx.Provide(fx.Annotate(func(options ...sdkmetric.Option) *sdkmetric.MeterProvider {
fmt.Println("run meter provider with options", options)
return sdkmetric.NewMeterProvider(options...)
}, fx.ParamTags(metricsProviderOptionKey))),
fx.Invoke(func(lc fx.Lifecycle, metricProvider *sdkmetric.MeterProvider, options ...runtime.Option) {
fmt.Println("start meter provider")
// set global propagator to tracecontext (the default is no-op).
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(
b3.New(), propagation.TraceContext{})) // B3 format is common and used by zipkin. Always enabled right now.
Expand Down
4 changes: 4 additions & 0 deletions tests/benchmarks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
k6
results
.env
.env
14 changes: 14 additions & 0 deletions tests/benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Benchmarks

## Deps
- xk6
- Task
## Launch benchmarks
For v1:
```bash
task run:v1
```
For v2:
```bash
task run:v2
```
35 changes: 35 additions & 0 deletions tests/benchmarks/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3'

tasks:
tools:
dir: ./tools
cmds:
- docker compose up -d
- sleep 20

build:scripts:
dir: ./scripts
cmds:
- npm run build

build:k6:
cmds:
- xk6 build --with extension=$(pwd)/extension --with github.com/grafana/[email protected]

run:
deps:
- tools
- build:scripts
- build:k6
cmds:
- PGPASSWORD=ledger psql -h 127.0.0.1 -U ledger -c "DROP DATABASE IF EXISTS ledgerv2;"
- PGPASSWORD=ledger psql -h 127.0.0.1 -U ledger -c "CREATE DATABASE ledgerv2;"
- TEST_ID=$(date +%s)-v2 K6_PROMETHEUS_RW_TREND_AS_NATIVE_HISTOGRAM=true K6_PROMETHEUS_RW_SERVER_URL=http://127.0.0.1:9090/api/v1/write ./k6 run --summary-trend-stats="avg,min,med,max,p(90),p(95),p(99)" --out xk6-prometheus-rw scripts/dist/ledger-v2.js
env:
POSTGRES_DSN: postgresql://ledger:ledger@postgres:5432/ledgerv2?sslmode=disable
DOCKER_NETWORK: tools_benchmarks

cleanup:
dir: ./tools
cmds:
- docker compose down -v
Loading