Skip to content

archive perf test #17522

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

Open
wants to merge 21 commits into
base: compatible
Choose a base branch
from
Open

Conversation

dkijania
Copy link
Member

@dkijania dkijania commented Jul 11, 2025

Enhanced precomputed_blocks test with performance metrics gathering. Addec CI job which also upload it to influx db and once we fill out 10 historical values every measurement will be checked for regression. Example test output:

[{"operation":"Zkapp_account_update.add","avg_time_ms":4.961491803278692},
{"operation":"Zkapp_account_update_body.add","avg_time_ms":3.0950926430517702},
{"operation":"Zkapp_actions.add","avg_time_ms":0.1407001117166212},
{"operation":"Zkapp_events.add","avg_time_ms":0.16317432697547685},
{"operation":"Zkapp_fee_payer_body.add","avg_time_ms":0.4071104508196722},
{"operation":"add_block","avg_time_ms":50.59486046511627},
{"operation":"adding_transactions","avg_time_ms":39.028174395348856},
{"operation":"block_and_zkapp_command.add_if_doesn't_exist","avg_time_ms":0.6587137950819674},
{"operation":"update_chain_status","avg_time_ms":0.3463889069767441},
{"operation":"zkapp_updates.add","avg_time_ms":0.4994985694822891}]

@dkijania
Copy link
Member Author

!ci-build-me

1 similar comment
@dkijania
Copy link
Member Author

!ci-build-me

@dkijania dkijania force-pushed the dkijania/archive_perf_test_extract branch from a29563f to 00f0d43 Compare July 14, 2025 18:43
@dkijania
Copy link
Member Author

!ci-build-me

1 similar comment
@dkijania
Copy link
Member Author

!ci-build-me

@dkijania dkijania changed the title Dkijania/archive perf test extract archive perf test Jul 15, 2025
@dkijania dkijania force-pushed the dkijania/archive_perf_test_extract branch from 7991eca to dd174be Compare July 15, 2025 11:22
@dkijania
Copy link
Member Author

!ci-build-me

@dkijania dkijania self-assigned this Jul 15, 2025
@dkijania dkijania marked this pull request as ready for review July 15, 2025 11:27
@dkijania dkijania requested review from a team as code owners July 15, 2025 11:27
@dkijania
Copy link
Member Author

!ci-build-me

5 similar comments
@dkijania
Copy link
Member Author

!ci-build-me

@dkijania
Copy link
Member Author

!ci-build-me

@dkijania
Copy link
Member Author

!ci-build-me

@dkijania
Copy link
Member Author

!ci-build-me

@dkijania
Copy link
Member Author

!ci-build-me

@@ -444,6 +445,72 @@ def parse(self, content, output_filename, influxdb, branch):

return [output_filename]

class ArchiveBenchmark(Benchmark):
"""
Concrete implementation of Benchmark for ledger test apply benchmark.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confused, is this "ledger test apply" or "archive" benchmark?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy paste issue :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you fix the name, then?

@dkijania
Copy link
Member Author

!ci-build-me

Copy link
Member

@glyh glyh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving.

However, if this is one of the minority places we use InfluxDB in our CI, I'd consider removing InfluxDB as a whole and replace everything with Grafana, so to simplify our already complicated tech-stack

@@ -444,6 +445,72 @@ def parse(self, content, output_filename, influxdb, branch):

return [output_filename]

class ArchiveBenchmark(Benchmark):
"""
Concrete implementation of Benchmark for ledger test apply benchmark.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you fix the name, then?

let%bind lines = Reader.file_lines log_file in
let perf_metrics =
List.filter_map lines ~f:(fun line ->
if String.is_substring line ~substring:" took " then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so fragile.

We have structured log, and parser specifically for structure logs, right?

Why can't we reuse that?

Copy link
Member

@glyh glyh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved too fast, I think it worth to factor out the manual log parsing part and use structured log parsing utilities we already have in our codebase.

(* Convert performance metrics to a JSON format suitable for output *)
(* The metrics are expected to be a list of tuples (operation, avg_time) *)
(* where operation is a string and avg_time is a float representing the average time in milliseconds *)
let perf_metrics_to_yojson metrics =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

@dkijania
Copy link
Member Author

!ci-build-me

Copy link
Member

@glyh glyh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider remove the use of regex as I suggested

(* Extract the operation and time from the line *)
(* Parse the JSON line to extract the message field *)
let pattern =
Re.Perl.compile_pat {|(.+) took (\d+(?:\.\d+)?)(ms|us)|}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using regex is an anti-pattern when we could have store the log information in a structural way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd consider replace these loggings to structural alternative

$ rg ' took '
lib/diff.ml
97:      "Archive data generation for $state_hash: accounts-accessed took $time ms"
129:      "Archive data generation for $state_hash: accounts-created took $time ms"

lib/metrics.ml
10:    "%s took %s" label

e.g.

in metrics.ml:

let time ~label f =
  let start = Time.now () in
  let%map x = f () in
  let stop = Time.now () in
  [%log' info (Logger.create ())]
    "%s took %s" label
    (Time.Span.to_string_hum (Time.diff stop start)) ;
  x

would be replaced by

let time ~label f =
  let start = Time.now () in
  let%map x = f () in
  let stop = Time.now () in
  let elapsed = Time.diff stop start in
  [%log' info (Logger.create ())]
    "%s took %s" label
    (Time.Span.to_string_hum elapsed)
    ~metadata:
      [ ("IS_ARCHIVE_PERF_METRICS", `Bool true)
      ; ("label", `String label)
      ; ("elapsed", `Float (Time.Span.to_ms elapsed))
      ] ;
  x

Which is much easier to parse with yojson alone without regex.

@dkijania
Copy link
Member Author

!ci-build-me

@dkijania dkijania force-pushed the dkijania/archive_perf_test_extract branch from c67d4ff to c76daee Compare July 21, 2025 20:48
@dkijania dkijania force-pushed the dkijania/archive_perf_test_extract branch from c069f60 to 00108a1 Compare July 21, 2025 20:50
@dkijania
Copy link
Member Author

!ci-build-me

-- This file is autogenerated during builds. It remains checked in to ensure
-- dhall configuration can still execute locally without running codegen.
let Pipeline = ../Pipeline/Dsl.dhall in [] : List Pipeline.CompoundType
[ -- Autogenerated do not edit by hand ,
Copy link
Member

@glyh glyh Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these still in the scope of this PR? I thought it's only for a test for archive nodes.

But anyway, I think it'll be infra engs reviewing this part.

Copy link
Member

@glyh glyh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor change requested, but LGTM overall

(* Extract performance metrics from the log file *)
(* where X is a floating point number representing the time taken for the operation *)
(* log output should be in JSON format *)
(* Example log line: {..., "message": "Operation took 123.45 ms"} *)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is outdated.

[ ("state_hash", Mina_base.State_hash.to_yojson state_hash)
; ( "time"
, `Float (Time.Span.to_ms (Time.diff accounts_accessed_time start)) )
] ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this perf info is not important?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not needed as we are taking avg from all measurements.

|> Option.value_exn
~message:
("Missing elapsed in log entry in log line: " ^ line)
|> Yojson.Safe.to_string |> Float.of_string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use Yojson.Safe.Util.to_float to avoid an additional level of converison.

@dkijania
Copy link
Member Author

!ci-build-me

@dkijania
Copy link
Member Author

!ci-build-me

1 similar comment
@dkijania
Copy link
Member Author

!ci-build-me

@dkijania dkijania force-pushed the dkijania/archive_perf_test_extract branch from c7a7abd to b0abfc5 Compare July 22, 2025 21:25
@dkijania
Copy link
Member Author

!ci-build-me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants