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

Jemalloc #1697

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG VM_DEBUG

# Install Alpine Dependencies
RUN apt-get update && \
apt-get install build-essential cargo git golang upx-ucl -y
apt-get install build-essential cargo git golang upx-ucl libjemalloc-dev libjemalloc2 -y

WORKDIR /app

Expand All @@ -21,7 +21,7 @@ RUN upx-ucl /app/build/juno
# Stage 2: Build Docker image
FROM ubuntu:23.10 AS runtime

RUN apt-get update && apt-get install -y ca-certificates curl gawk grep
RUN apt-get update && apt-get install -y ca-certificates curl gawk grep libjemalloc-dev libjemalloc2

COPY --from=build /app/build/juno /usr/local/bin/

Expand Down
1 change: 1 addition & 0 deletions cmd/juno/juno.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"syscall"
"time"

_ "github.com/NethermindEth/juno/jemalloc"

Check failure on line 16 in cmd/juno/juno.go

View workflow job for this annotation

GitHub Actions / lint

could not import github.com/NethermindEth/juno/jemalloc (-: go build github.com/NethermindEth/juno/jemalloc:
"github.com/NethermindEth/juno/node"
"github.com/NethermindEth/juno/utils"
"github.com/ethereum/go-ethereum/common"
Expand Down
28 changes: 28 additions & 0 deletions jemalloc/jemalloc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package jemalloc

Check failure on line 1 in jemalloc/jemalloc.go

View workflow job for this annotation

GitHub Actions / lint

: go build github.com/NethermindEth/juno/jemalloc:

/*
// This cgo directive is what actually causes jemalloc to be linked in to the
// final Go executable
#cgo pkg-config: jemalloc

#include <jemalloc/jemalloc.h>

void _refresh_jemalloc_stats() {
// You just need to pass something not-null into the "epoch" mallctl.
size_t random_something = 1;
mallctl("epoch", NULL, NULL, &random_something, sizeof(random_something));
}
int _get_jemalloc_active() {
size_t stat, stat_size;
stat = 0;
stat_size = sizeof(stat);
mallctl("stats.active", &stat, &stat_size, NULL, 0);
return (int)stat;
}
*/
import "C"

func GetActive() C.int {
C._refresh_jemalloc_stats()
return C._get_jemalloc_active()
}
11 changes: 11 additions & 0 deletions node/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"github.com/NethermindEth/juno/clients/gateway"
"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/db"
"github.com/NethermindEth/juno/jemalloc"

Check failure on line 13 in node/metrics.go

View workflow job for this annotation

GitHub Actions / lint

could not import github.com/NethermindEth/juno/jemalloc (-: go build github.com/NethermindEth/juno/jemalloc:
"github.com/NethermindEth/juno/jsonrpc"
"github.com/NethermindEth/juno/l1"
"github.com/NethermindEth/juno/sync"
Expand Down Expand Up @@ -261,3 +262,13 @@
},
}
}

func makeJeMallocMetrics() {
active := prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "jemalloc",
Name: "active",
}, func() float64 {
return float64(jemalloc.GetActive())
})
prometheus.MustRegister(active)
}
1 change: 1 addition & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen
client.WithListener(makeFeederMetrics())
gatewayClient.WithListener(makeGatewayMetrics())
metricsService = makeMetrics(cfg.MetricsHost, cfg.MetricsPort)
makeJeMallocMetrics()
}
if cfg.GRPC {
services = append(services, makeGRPC(cfg.GRPCHost, cfg.GRPCPort, database, version))
Expand Down
Loading