From c2b3a41d7fed395f7a43c748eab35cfa05280f37 Mon Sep 17 00:00:00 2001 From: jinhoonbang Date: Tue, 5 Nov 2024 13:06:49 -0800 Subject: [PATCH] trigger build --- .../workflows/build-publish-develop-pr.yml | 4 +- README.md | 17 +++++--- core/capabilities/compute/cache.go | 19 +++++++- core/capabilities/compute/compute.go | 3 ++ core/main.go | 43 +++++++++++++++++++ 5 files changed, 77 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-publish-develop-pr.yml b/.github/workflows/build-publish-develop-pr.yml index 467411ab4ea..caf46c1a3ed 100644 --- a/.github/workflows/build-publish-develop-pr.yml +++ b/.github/workflows/build-publish-develop-pr.yml @@ -56,7 +56,7 @@ jobs: - uses: actions/cache/restore@v4 with: - path: dist/linux_arm64 + path: dist/linux_arm64_v8.0 key: chainlink-arm64-${{ github.sha }} fail-on-cache-miss: true @@ -86,7 +86,7 @@ jobs: - runner: ubuntu-24.04-4cores-16GB-ARM goarch: arm64 - dist_name: linux_arm64 + dist_name: linux_arm64_v8.0 steps: - name: Checkout repository uses: actions/checkout@v4.2.1 diff --git a/README.md b/README.md index e7c21c1e094..70e6556ca8e 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ the given `_test` database. Note: Other environment variables should not be set for all tests to pass There helper script for initial setup to create an appropriate test user. It requires postgres to be running on localhost at port 5432. You will be prompted for -the `postgres` user password +the `postgres` user password ```bash make setup-testdb @@ -195,6 +195,7 @@ This script will save the `CL_DATABASE_URL` in `.dbenv` Changes to database require migrations to be run. Similarly, `pull`'ing the repo may require migrations to run. After the one-time setup above: + ``` source .dbenv make testdb @@ -202,12 +203,12 @@ make testdb If you encounter the error `database accessed by other users (SQLSTATE 55006) exit status 1` and you want force the database creation then use + ``` source .dbenv make testdb-force ``` - 7. Run tests: ```bash @@ -260,9 +261,11 @@ flowchart RL github.com/smartcontractkit/chainlink/core/scripts --> github.com/smartcontractkit/chainlink/v2 ``` + The `integration-tests` and `core/scripts` modules import the root module using a relative replace in their `go.mod` files, so dependency changes in the root `go.mod` often require changes in those modules as well. After making a change, `go mod tidy` can be run on all three modules using: + ``` make gomodtidy ``` @@ -282,6 +285,7 @@ pnpm i ```bash pnpm test ``` + NOTE: Chainlink is currently in the process of migrating to Foundry and contains both Foundry and Hardhat tests in some versions. More information can be found here: [Chainlink Foundry Documentation](https://github.com/smartcontractkit/chainlink/blob/develop/contracts/foundry.md). Any 't.sol' files associated with Foundry tests, contained within the src directories will be ignored by Hardhat. @@ -291,7 +295,7 @@ Go generate is used to generate mocks in this project. Mocks are generated with ### Nix -A [shell.nix](https://nixos.wiki/wiki/Development_environment_with_nix-shell) is provided for use with the [Nix package manager](https://nixos.org/). By default,we utilize the shell through [Nix Flakes](https://nixos.wiki/wiki/Flakes). +A [shell.nix](https://nixos.wiki/wiki/Development_environment_with_nix-shell) is provided for use with the [Nix package manager](https://nixos.org/). By default,we utilize the shell through [Nix Flakes](https://nixos.wiki/wiki/Flakes). Nix defines a declarative, reproducible development environment. Flakes version use deterministic, frozen (`flake.lock`) dependencies to gain more consistency/reproducibility on the built artifacts. @@ -329,8 +333,9 @@ We use [changesets](https://github.com/changesets/changesets) to manage versioni Every PR that modifies any configuration or code, should most likely accompanied by a changeset file. To install `changesets`: - 1. Install `pnpm` if it is not already installed - [docs](https://pnpm.io/installation). - 2. Run `pnpm install`. + +1. Install `pnpm` if it is not already installed - [docs](https://pnpm.io/installation). +2. Run `pnpm install`. Either after or before you create a commit, run the `pnpm changeset` command to create an accompanying changeset entry which will reflect on the CHANGELOG for the next release. @@ -349,3 +354,5 @@ Contributions are welcome to Chainlink's source code. Please check out our [contributing guidelines](./docs/CONTRIBUTING.md) for more details. Thank you! + +> test diff --git a/core/capabilities/compute/cache.go b/core/capabilities/compute/cache.go index 7b7cd78aaab..50fe84e860d 100644 --- a/core/capabilities/compute/cache.go +++ b/core/capabilities/compute/cache.go @@ -1,6 +1,7 @@ package compute import ( + "log" "sync" "time" @@ -43,6 +44,9 @@ type moduleCache struct { } func newModuleCache(clock clockwork.Clock, tick, timeout time.Duration, evictAfterSize int) *moduleCache { + log.Println("evictAfterSize", evictAfterSize) + log.Println("timeout in seconds", timeout.Seconds()) + log.Println("mc.tickInterval", tick) return &moduleCache{ m: map[string]*module{}, tickInterval: tick, @@ -67,15 +71,19 @@ func (mc *moduleCache) close() { } func (mc *moduleCache) reapLoop() { + log.Println("reapLoop started") ticker := mc.clock.NewTicker(mc.tickInterval) for { select { case <-ticker.Chan(): + log.Println("before evictOlderThan") mc.evictOlderThan(mc.timeout) + log.Println("after evictOlderThan") if mc.onReaper != nil { mc.onReaper <- struct{}{} } case <-mc.stopChan: + log.Println("stopChan") return } } @@ -85,8 +93,10 @@ func (mc *moduleCache) add(id string, mod *module) { mc.mu.Lock() defer mc.mu.Unlock() mod.lastFetchedAt = time.Now() - mc.m[id] = mod - moduleCacheAddition.Inc() + if _, exists := mc.m[id]; !exists { + mc.m[id] = mod + moduleCacheAddition.Inc() + } } func (mc *moduleCache) get(id string) (*module, bool) { @@ -109,12 +119,17 @@ func (mc *moduleCache) evictOlderThan(duration time.Duration) { evicted := 0 + log.Println("len(mc.m)", len(mc.m)) if len(mc.m) > mc.evictAfterSize { for id, m := range mc.m { + log.Println("mc.clock", mc.clock.Now()) + log.Println("m.lastFetchedAt", m.lastFetchedAt) + log.Println("duration", duration) if mc.clock.Now().Sub(m.lastFetchedAt) > duration { delete(mc.m, id) m.module.Close() evicted++ + log.Println("evicted. id:", id) } if len(mc.m) <= mc.evictAfterSize { diff --git a/core/capabilities/compute/compute.go b/core/capabilities/compute/compute.go index 01a4de94102..68f20bb31e5 100644 --- a/core/capabilities/compute/compute.go +++ b/core/capabilities/compute/compute.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "fmt" + "log" "strings" "sync" "time" @@ -219,6 +220,8 @@ func (c *Compute) initModule(id string, cfg *host.ModuleConfig, binary []byte, w func (c *Compute) executeWithModule(ctx context.Context, module *host.Module, config []byte, req capabilities.CapabilityRequest) (capabilities.CapabilityResponse, error) { executeStart := time.Now() capReq := capabilitiespb.CapabilityRequestToProto(req) + log.Println("executeWithModule req", req) + log.Println("executeWithModule capReq", capReq) wasmReq := &wasmpb.Request{ Id: uuid.New().String(), diff --git a/core/main.go b/core/main.go index 4ff013d9c96..a21a8d0c066 100644 --- a/core/main.go +++ b/core/main.go @@ -3,7 +3,12 @@ package core import ( "fmt" "log" + "net/http" + _ "net/http/pprof" "os" + "runtime" + "runtime/debug" + "time" "github.com/Masterminds/semver/v3" @@ -25,7 +30,45 @@ func init() { } } +// Helper function to convert bytes to megabytes +func bToMb(b uint64) uint64 { + return b / 1024 / 1024 +} + +func printGCStats() { + for { + // Create MemStats and GCStats structs to hold stats data + var memStats runtime.MemStats + var gcStats debug.GCStats + + // Read memory statistics + runtime.ReadMemStats(&memStats) + debug.ReadGCStats(&gcStats) + + // Print memory allocation and GC details + log.Printf("Alloc = %v MiB", bToMb(memStats.Alloc)) + log.Printf("TotalAlloc = %v MiB", bToMb(memStats.TotalAlloc)) + log.Printf("Sys = %v MiB", bToMb(memStats.Sys)) + log.Printf("NumGC = %v", memStats.NumGC) + log.Printf("PauseTotalNs = %v", memStats.PauseTotalNs) + log.Printf("LastGC = %v", time.Unix(0, int64(memStats.LastGC))) + + log.Printf("GC Last Run: %v", gcStats.LastGC) + log.Printf("GC NumGC: %v", gcStats.NumGC) + log.Printf("GC PauseTotal: %v", gcStats.PauseTotal) + log.Printf("GC Pause history (last few GCs): %v", gcStats.Pause) + + // Sleep for the specified interval + time.Sleep(5 * time.Minute) // Adjust interval as needed + } +} + func Main() (code int) { + go printGCStats() // Run printGCStats in a separate goroutine + go func() { + log.Println("Starting pprof server on :6060") + log.Println(http.ListenAndServe(":6060", nil)) + }() recovery.ReportPanics(func() { app := cmd.NewApp(newProductionClient()) if err := app.Run(os.Args); err != nil {