Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
RC 0.2.0 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
nodiesBlade authored Apr 9, 2024
1 parent 06e4577 commit 77f325f
Show file tree
Hide file tree
Showing 53 changed files with 281 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package config
import (
"fmt"
"github.com/joho/godotenv"
"github.com/pokt-network/gateway-server/internal/global_config"
"os"
"pokt_gateway_server/internal/global_config"
"strconv"
"time"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gateway_server/internal/config/provider.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package config

import (
"pokt_gateway_server/internal/global_config"
"github.com/pokt-network/gateway-server/internal/global_config"
)

type GatewayServerProvider interface {
Expand Down
16 changes: 8 additions & 8 deletions cmd/gateway_server/internal/controllers/pokt_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package controllers
import (
"context"
"github.com/jackc/pgtype"
"github.com/pokt-network/gateway-server/cmd/gateway_server/internal/common"
"github.com/pokt-network/gateway-server/cmd/gateway_server/internal/models"
"github.com/pokt-network/gateway-server/cmd/gateway_server/internal/transform"
"github.com/pokt-network/gateway-server/internal/apps_registry"
"github.com/pokt-network/gateway-server/internal/db_query"
"github.com/pokt-network/gateway-server/internal/global_config"
"github.com/pokt-network/gateway-server/pkg/pokt/pokt_v0"
pokt_models "github.com/pokt-network/gateway-server/pkg/pokt/pokt_v0/models"
"github.com/pquerna/ffjson/ffjson"
"github.com/valyala/fasthttp"
"go.uber.org/zap"
"pokt_gateway_server/cmd/gateway_server/internal/common"
"pokt_gateway_server/cmd/gateway_server/internal/models"
"pokt_gateway_server/cmd/gateway_server/internal/transform"
"pokt_gateway_server/internal/apps_registry"
"pokt_gateway_server/internal/db_query"
"pokt_gateway_server/internal/global_config"
"pokt_gateway_server/pkg/pokt/pokt_v0"
pokt_models "pokt_gateway_server/pkg/pokt/pokt_v0/models"
)

type addApplicationBody struct {
Expand Down
8 changes: 4 additions & 4 deletions cmd/gateway_server/internal/controllers/qos_nodes.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package controllers

import (
"github.com/pokt-network/gateway-server/cmd/gateway_server/internal/common"
"github.com/pokt-network/gateway-server/cmd/gateway_server/internal/models"
"github.com/pokt-network/gateway-server/cmd/gateway_server/internal/transform"
"github.com/pokt-network/gateway-server/internal/session_registry"
"github.com/valyala/fasthttp"
"go.uber.org/zap"
"pokt_gateway_server/cmd/gateway_server/internal/common"
"pokt_gateway_server/cmd/gateway_server/internal/models"
"pokt_gateway_server/cmd/gateway_server/internal/transform"
"pokt_gateway_server/internal/session_registry"
)

// QosNodeController handles requests for staked applications
Expand Down
6 changes: 3 additions & 3 deletions cmd/gateway_server/internal/controllers/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package controllers

import (
"fmt"
"github.com/pokt-network/gateway-server/cmd/gateway_server/internal/common"
"github.com/pokt-network/gateway-server/pkg/pokt/pokt_v0"
"github.com/pokt-network/gateway-server/pkg/pokt/pokt_v0/models"
"github.com/valyala/fasthttp"
"go.uber.org/zap"
"pokt_gateway_server/cmd/gateway_server/internal/common"
"pokt_gateway_server/pkg/pokt/pokt_v0"
"pokt_gateway_server/pkg/pokt/pokt_v0/models"
"strings"
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/gateway_server/internal/controllers/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package controllers
// Basic imports
import (
"errors"
pocket_service_mock "pokt_gateway_server/mocks/pocket_service"
"pokt_gateway_server/pkg/pokt/pokt_v0/models"
pocket_service_mock "github.com/pokt-network/gateway-server/mocks/pocket_service"
"github.com/pokt-network/gateway-server/pkg/pokt/pokt_v0/models"
"testing"

"github.com/stretchr/testify/suite"
Expand Down
4 changes: 2 additions & 2 deletions cmd/gateway_server/internal/middleware/x-api-key.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package middleware

import (
"github.com/pokt-network/gateway-server/cmd/gateway_server/internal/common"
config2 "github.com/pokt-network/gateway-server/internal/global_config"
"github.com/valyala/fasthttp"
"pokt_gateway_server/cmd/gateway_server/internal/common"
config2 "pokt_gateway_server/internal/global_config"
)

func retrieveAPIKey(ctx *fasthttp.RequestCtx) string {
Expand Down
3 changes: 2 additions & 1 deletion cmd/gateway_server/internal/models/qos_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package models
import "time"

type PublicQosNode struct {
NodePublicKey string `json:"node_public_key"`
ServiceUrl string `json:"service_url"`
Chain string `json:"chain"`
SessionHeight uint `json:"session_height"`
AppPublicKey string `json:"app_public_key"`
TimeoutUntil time.Time `json:"timeout_until"`
TimeoutReason string `json:"timeout_reason"`
LastKnownErr string `json:"last_known_err"`
IsHeathy bool `json:"is_heathy"`
IsHealthy bool `json:"is_healthy"`
IsSynced bool `json:"is_synced"`
LastKnownHeight uint64 `json:"last_known_height"`
P90Latency float64 `json:"p90_latency"`
Expand Down
4 changes: 2 additions & 2 deletions cmd/gateway_server/internal/transform/pokt_application.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package transform

import (
"pokt_gateway_server/cmd/gateway_server/internal/models"
internal_model "pokt_gateway_server/internal/apps_registry/models"
"github.com/pokt-network/gateway-server/cmd/gateway_server/internal/models"
internal_model "github.com/pokt-network/gateway-server/internal/apps_registry/models"
)

func ToPoktApplication(app *internal_model.PoktApplicationSigner) *models.PublicPoktApplication {
Expand Down
7 changes: 4 additions & 3 deletions cmd/gateway_server/internal/transform/qos_node.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package transform

import (
"github.com/pokt-network/gateway-server/cmd/gateway_server/internal/models"
internal_model "github.com/pokt-network/gateway-server/internal/node_selector_service/models"
"math"
"pokt_gateway_server/cmd/gateway_server/internal/models"
internal_model "pokt_gateway_server/internal/node_selector_service/models"
)

func ToPublicQosNode(node *internal_model.QosNode) *models.PublicQosNode {
Expand All @@ -12,13 +12,14 @@ func ToPublicQosNode(node *internal_model.QosNode) *models.PublicQosNode {
latency = 0.0
}
return &models.PublicQosNode{
NodePublicKey: node.MorseNode.PublicKey,
ServiceUrl: node.MorseNode.ServiceUrl,
Chain: node.GetChain(),
SessionHeight: node.MorseSession.SessionHeader.SessionHeight,
AppPublicKey: node.MorseSigner.PublicKey,
TimeoutReason: string(node.GetTimeoutReason()),
LastKnownErr: node.GetLastKnownErrorStr(),
IsHeathy: node.IsHealthy(),
IsHealthy: node.IsHealthy(),
IsSynced: node.IsSynced(),
LastKnownHeight: node.GetLastKnownHeight(),
TimeoutUntil: node.GetTimeoutUntil(),
Expand Down
29 changes: 15 additions & 14 deletions cmd/gateway_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ import (
"github.com/fasthttp/router"
fasthttpprometheus "github.com/flf2ko/fasthttp-prometheus"
"github.com/jellydator/ttlcache/v3"
"github.com/pokt-network/gateway-server/cmd/gateway_server/internal/config"
"github.com/pokt-network/gateway-server/cmd/gateway_server/internal/controllers"
"github.com/pokt-network/gateway-server/cmd/gateway_server/internal/middleware"
"github.com/pokt-network/gateway-server/internal/apps_registry"
"github.com/pokt-network/gateway-server/internal/chain_configurations_registry"
"github.com/pokt-network/gateway-server/internal/db_query"
"github.com/pokt-network/gateway-server/internal/logging"
"github.com/pokt-network/gateway-server/internal/node_selector_service"
qos_models "github.com/pokt-network/gateway-server/internal/node_selector_service/models"
"github.com/pokt-network/gateway-server/internal/relayer"
"github.com/pokt-network/gateway-server/internal/session_registry"
"github.com/pokt-network/gateway-server/pkg/pokt/pokt_v0"
"github.com/valyala/fasthttp"
"pokt_gateway_server/cmd/gateway_server/internal/config"
"pokt_gateway_server/cmd/gateway_server/internal/controllers"
"pokt_gateway_server/cmd/gateway_server/internal/middleware"
"pokt_gateway_server/internal/apps_registry"
"pokt_gateway_server/internal/chain_configurations_registry"
"pokt_gateway_server/internal/db_query"
"pokt_gateway_server/internal/logging"
"pokt_gateway_server/internal/node_selector_service"
qos_models "pokt_gateway_server/internal/node_selector_service/models"
"pokt_gateway_server/internal/relayer"
"pokt_gateway_server/internal/session_registry"
"pokt_gateway_server/pkg/pokt/pokt_v0"
)

const (
userAgent = "pokt-gw-server"
// Maximum amount of DB connections opened at a time. This should not have to be modified
// as most of our database queries are periodic and not ran concurrently.
maxDbConns = 50
Expand All @@ -47,7 +48,7 @@ func main() {
defer pool.Close()

// Initialize a POKT client using the configured POKT RPC host and timeout
client, err := pokt_v0.NewBasicClient(gatewayConfigProvider.GetPoktRPCFullHost(), gatewayConfigProvider.GetPoktRPCRequestTimeout())
client, err := pokt_v0.NewBasicClient(gatewayConfigProvider.GetPoktRPCFullHost(), userAgent, gatewayConfigProvider.GetPoktRPCRequestTimeout())
if err != nil {
// If POKT client initialization fails, log the error and exit
logger.Sugar().Fatal(err)
Expand All @@ -68,7 +69,7 @@ func main() {
sessionRegistry := session_registry.NewCachedSessionRegistryService(client, poktApplicationRegistry, sessionCache, nodeCache, logger.Named("session_registry"))
nodeSelectorService := node_selector_service.NewNodeSelectorService(sessionRegistry, client, chainConfigurationRegistry, logger.Named("node_selector"))

relayer := relayer.NewRelayer(client, sessionRegistry, poktApplicationRegistry, nodeSelectorService, chainConfigurationRegistry, gatewayConfigProvider, logger.Named("relayer"))
relayer := relayer.NewRelayer(client, sessionRegistry, poktApplicationRegistry, nodeSelectorService, chainConfigurationRegistry, userAgent, gatewayConfigProvider, logger.Named("relayer"))

// Define routers
r := router.New()
Expand Down
16 changes: 0 additions & 16 deletions docs/benchmarks/03-2024-benchmark.md

This file was deleted.

96 changes: 96 additions & 0 deletions docs/benchmarks/03_2024/03-2024-benchmark.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# March 2024 Benchmark (RC 0.2.0)

## Benchmark Purpose
The purpose of this benchmark is to comprehensively assess the performance metrics, particularly CPU and Memory behaviors, incurred while serving requests through the gateway server. Specifically, this evaluation aims to gauge the efficiency of various operations involved with sending a relay such as JSON serialization, IO handling, cryptographic signing, and asynchronous background processes (QoS checks).

## Benchmark Environment
- **POKT Testnet**: The benchmark is conducted within the environment of the POKT Testnet to simulate real-world conditions accurately.
- **RPC Method web3_clientVersion**: The benchmark uses a consistent time RPC method, web3_clientVersion, chosen deliberately to isolate the impact of the gateway server overhead. It's noteworthy that the computational overhead of sending a request to the POKT Network remains independent of the specific RPC Method employed.
- **Gateway Server Hardware**: The gateway server is deployed on a dedicated DigitalOcean droplet instance (16 GB Memory / 8 Prem. Intel vCPUs / 100 GB Disk / FRA1), ensuring controlled conditions for performance evaluation.
- **Tooling**: Utilizes [Vegeta](https://github.com/tsenart/vegeta), a versatile HTTP load testing too
- **Vegeta Server Hardware**: The load tester is deployed on a seperate dedicated DigitalOcean droplet instance (8 GB Memory / 50 GB Disk / FRA1) to prevent any thrashing with the gateway server.
- **Grafana**: Used to visualize Gateway server internal metrics.

## Scripts

Load Testing Command
```sh
vegeta attack -duration=180s -rate=100/1s -targets=gateway_server.config | tee results.bin | vegeta report
```

Vegeta Target
```sh
POST http://{endpoint}
Content-Type: application/json
@payload.json
```

Payload.json
```json
{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}
```

## Load Test Results
100 RPS
```text
Requests [total, rate, throughput] 18000, 100.01, 99.87
Duration [total, attack, wait] 3m0s, 3m0s, 239.445ms
Latencies [min, mean, 50, 90, 95, 99, max] 170.168ms, 191.573ms, 176.331ms, 200.473ms, 230.392ms, 283.411ms, 3.284s
Bytes In [total, mean] 1260000, 70.00
Bytes Out [total, mean] 1206000, 67.00
Success [ratio] 100.00%
Status Codes [code:count] 200:18000
Error Set:
```

500 RPS
```text
Requests [total, rate, throughput] 90000, 500.01, 499.51
Duration [total, attack, wait] 3m0s, 3m0s, 176.636ms
Latencies [min, mean, 50, 90, 95, 99, max] 169.036ms, 182.464ms, 176.267ms, 197.629ms, 212.595ms, 263.593ms, 3.61s
Bytes In [total, mean] 6300000, 70.00
Bytes Out [total, mean] 6030000, 67.00
Success [ratio] 100.00%
Status Codes [code:count] 200:90000
Error Set:
```

1000 RPS
```text
Requests [total, rate, throughput] 180000, 1000.00, 998.87
Duration [total, attack, wait] 3m0s, 3m0s, 204.308ms
Latencies [min, mean, 50, 90, 95, 99, max] 168.406ms, 183.103ms, 176.947ms, 190.737ms, 196.224ms, 216.507ms, 7.122s
Bytes In [total, mean] 12600000, 70.00
Bytes Out [total, mean] 12060000, 67.00
Success [ratio] 100.00%
Status Codes [code:count] 200:180000
Error Set:
```

## Analysis

### CPU Metrics
![cpu-03-2024.png](resources%2Fcpu-03-2024.png)
CPU metrics exhibit a slight uptick from approximately 10% to around 125% at peak load of 1,000 RPS. However, it's noteworthy that the gateway server did not reach full CPU utilization, with the maximum observed at 800%.

### Ram Metrics
![memory-03-2024.png](resources%2Fmemory-03-2024.png)
RAM metrics show a similar pattern, with a slight increase from around 120MiB to approximately 280MiB at peak load. This increase is expected due to the opening of more network connections while serving traffic.

### Latency Analysis
Upon closer inspection, despite the tenfold increase in load from 100 RPS to 1,000 RPS, the benchmark latency remained relatively consistent at ~150MS. Nodies, with the gateway server in production, has seen multiple node operators achieve lower latencies, typically ranging from 50ms to 70ms P90 latency at similar or higher request rates. Therefore, a consistent baseline latency of ~150ms at even 100 RPS in our benchmarking environment warranted further investigation to determine root cause.

By analyzing Prometheus metrics emitted by the gateway server, specifically `pocket_relay_latency` (which measures the latency of creating a relay, including hashing, signing, and sending it to POKT Nodes) and `relay_latency` (providing an end-to-end latency metric including node selection), it was possible to identify the source of additional latency overhead.

![node-selection-overhead-03-2024.png](resources%2Fnode-selection-overhead-03-2024.png)

This deep dive revealed that the bottleneck does not lie in QoS/Node selection, as the intersection of the two metrics indicated that node selection completes within fractions of a second, ruling out that the gateway server code has a bottleneck.

The baseline latency overhead therefore is attributed to protocol requirements (hashing/signing a relay) and hardware specifications. To mitigate this latency, upgrading to more powerful CPUs or dedicated machines should decrease this latency. Nodies currently uses the AMD 5950X CPU for their gateway servers.

### Summary
This benchmark provides a comprehensive quantitative assessment of the gateway server's performance under varying loads within the POKT Testnet environment. Analysis of CPU metrics reveals a slight uptick in CPU utilization from approximately 10% to around 125% at peak load of 1,000 RPS, with a maximum observed utilization of 800%. Memory metrics also show a similar pattern, with memory utilization increasing from around 120MiB to approximately 280MiB at peak load.

Despite the increase in load, the gateway server demonstrates resilience, maintaining consistent latency across different request rates.

In order to achieve better latency performance in production, gateway operators should strive for modern CPU's such as the AMD Ryzen 9 or EPYC processors.
Binary file added docs/benchmarks/03_2024/resources/cpu-03-2024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module pokt_gateway_server
module github.com/pokt-network/gateway-server

go 1.21.4

Expand Down
2 changes: 1 addition & 1 deletion internal/apps_registry/app_registry_service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package apps_registry

import "pokt_gateway_server/internal/apps_registry/models"
import "github.com/pokt-network/gateway-server/internal/apps_registry/models"

type AppsRegistryService interface {
GetApplications() []*models.PoktApplicationSigner
Expand Down
10 changes: 5 additions & 5 deletions internal/apps_registry/cached_app_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package apps_registry
import (
"context"
"errors"
"github.com/pokt-network/gateway-server/internal/apps_registry/models"
"github.com/pokt-network/gateway-server/internal/db_query"
"github.com/pokt-network/gateway-server/internal/global_config"
"github.com/pokt-network/gateway-server/pkg/pokt/pokt_v0"
pokt "github.com/pokt-network/gateway-server/pkg/pokt/pokt_v0/models"
"go.uber.org/zap"
"pokt_gateway_server/internal/apps_registry/models"
"pokt_gateway_server/internal/db_query"
"pokt_gateway_server/internal/global_config"
"pokt_gateway_server/pkg/pokt/pokt_v0"
pokt "pokt_gateway_server/pkg/pokt/pokt_v0/models"
"sort"
"strings"
"sync"
Expand Down
2 changes: 1 addition & 1 deletion internal/apps_registry/models/application.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package models

import (
"pokt_gateway_server/pkg/pokt/pokt_v0/models"
"github.com/pokt-network/gateway-server/pkg/pokt/pokt_v0/models"
)

type PoktApplicationSigner struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package chain_configurations_registry

import (
"context"
"github.com/pokt-network/gateway-server/internal/db_query"
"go.uber.org/zap"
"pokt_gateway_server/internal/db_query"
"sync"
"time"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package chain_configurations_registry

import "pokt_gateway_server/internal/db_query"
import "github.com/pokt-network/gateway-server/internal/db_query"

type ChainConfigurationsService interface {
GetChainConfiguration(chainId string) (db_query.GetChainConfigurationsRow, bool)
Expand Down
4 changes: 2 additions & 2 deletions internal/db_query/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/golang-migrate/migrate/v4/source/iofs"
"github.com/jackc/pgx/v4/pgxpool"
"github.com/pkg/errors"
root "github.com/pokt-network/gateway-server"
"github.com/pokt-network/gateway-server/internal/global_config"
"go.uber.org/zap"
root "pokt_gateway_server"
"pokt_gateway_server/internal/global_config"
)

// InitDB - runs DB migrations and provides a code-generated query interface
Expand Down
Loading

0 comments on commit 77f325f

Please sign in to comment.