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(congestion): write stats to a csv file #10719

Merged
merged 8 commits into from
Mar 11, 2024
Merged

Conversation

wacban
Copy link
Contributor

@wacban wacban commented Mar 7, 2024

This feature allows dumping the stats to a csv file. In a follow up PR I'll figure out how to plot this data conveniently. I implemented the framework and an example in the SimpleBackpressure strategy.

By default the model will add a single column round and populate it for each round.
Each strategy needs to populate the head in the init method and populate the values in the compute_chunk method.

In the simple backpressure strategy the first few rows look like follows:

round,shard_0_incoming_queue,shard_0_outgoing_queue,shard_1_incoming_queue,shard_1_outgoing_queue,shard_2_incoming_queue,shard_2_outgoing_queue,shard_3_incoming_queue,shard_3_outgoing_queue
1,0,0,0,0,0,0,0,0
2,20,0,0,0,0,0,0,0
3,40,0,0,0,0,0,0,0
4,57,0,3,0,0,0,0,0
5,73,0,2,0,2,0,0,0
6,89,0,0,0,3,0,1,0
7,105,0,0,0,0,0,4,0

@wacban wacban requested a review from a team as a code owner March 7, 2024 12:57
@wacban wacban requested a review from jakmeier March 7, 2024 12:57
Copy link

codecov bot commented Mar 7, 2024

Codecov Report

Attention: Patch coverage is 0% with 102 lines in your changes are missing coverage. Please review.

Project coverage is 71.66%. Comparing base (13e573f) to head (55b9873).
Report is 1 commits behind head on master.

Files Patch % Lines
tools/congestion-model/src/main.rs 0.00% 50 Missing ⚠️
tools/congestion-model/src/evaluation/mod.rs 0.00% 40 Missing ⚠️
tools/congestion-model/src/model/queue.rs 0.00% 5 Missing ⚠️
tools/congestion-model/src/model/queue_bundle.rs 0.00% 5 Missing ⚠️
...ngestion-model/src/strategy/simple_backpressure.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10719      +/-   ##
==========================================
- Coverage   71.72%   71.66%   -0.07%     
==========================================
  Files         758      758              
  Lines      152593   152680      +87     
  Branches   152593   152680      +87     
==========================================
- Hits       109451   109418      -33     
- Misses      38191    38295     +104     
- Partials     4951     4967      +16     
Flag Coverage Δ
backward-compatibility 0.24% <ø> (ø)
db-migration 0.24% <ø> (ø)
genesis-check 1.42% <ø> (ø)
integration-tests 36.87% <0.00%> (-0.08%) ⬇️
linux 70.42% <0.00%> (-0.03%) ⬇️
linux-nightly 71.15% <0.00%> (-0.09%) ⬇️
macos 53.05% <0.00%> (-1.71%) ⬇️
pytests 1.64% <ø> (ø)
sanity-checks 1.43% <ø> (ø)
unittests 67.47% <0.00%> (-0.06%) ⬇️
upgradability 0.29% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

jakmeier pushed a commit to jakmeier/nearcore that referenced this pull request Mar 7, 2024
<p>This PR was automatically created by Snyk using the credentials of a
real user.</p><br /><h3>Snyk has created this PR to upgrade
react-router-dom from 6.19.0 to 6.20.0.</h3>

:information_source: Keep your dependencies up-to-date. This makes it
easier to fix existing vulnerabilities and to more quickly identify and
fix newly disclosed vulnerabilities when they affect your project.
<hr/>

- The recommended version is **2 versions** ahead of your current
version.
- The recommended version was released **21 days ago**, on 2023-11-22.


<details>
<summary><b>Release notes</b></summary>
<br/>
  <details>
    <summary>Package name: <b>react-router-dom</b></summary>
    <ul>
      <li>
<b>6.20.0</b> - <a
href="https://snyk.io/redirect/github/remix-run/react-router/releases/tag/react-router-native%406.20.0">2023-11-22</a></br><p>react-router-native@6.20.0</p>
      </li>
      <li>
        <b>6.20.0-pre.0</b> - 2023-11-21
      </li>
      <li>
        <b>6.19.0</b> - 2023-11-16
      </li>
    </ul>
from <a
href="https://snyk.io/redirect/github/remix-run/react-router/releases">react-router-dom
GitHub release notes</a>
  </details>
</details>


<details>
  <summary><b>Commit messages</b></summary>
  </br>
  <details>
    <summary>Package name: <b>react-router-dom</b></summary>
    <ul>
<li><a
href="https://snyk.io/redirect/github/remix-run/react-router/commit/3cc38eac4753702a9a8a1fe239e2138d63ac6cc5">3cc38ea</a>
chore: Update version for release (near#11050)</li>
<li><a
href="https://snyk.io/redirect/github/remix-run/react-router/commit/77862f95f71397d92b8b583a16674c56efccc55f">77862f9</a>
Exit prerelease mode</li>
<li><a
href="https://snyk.io/redirect/github/remix-run/react-router/commit/1621319ffa353bf33f33064d7611859df16286ee">1621319</a>
Update Release Notes TOC</li>
<li><a
href="https://snyk.io/redirect/github/remix-run/react-router/commit/f1f8ed0acffb3d6c2860c362fc2b376dbf87df24">f1f8ed0</a>
Update release notes</li>
<li><a
href="https://snyk.io/redirect/github/remix-run/react-router/commit/1e026b6f1ac34a774b4f77e5e3696251e8f79940">1e026b6</a>
chore: Update version for release (pre) (near#11047)</li>
<li><a
href="https://snyk.io/redirect/github/remix-run/react-router/commit/4a08d64c368c07816e753632345a13b8da050111">4a08d64</a>
Enter prerelease mode</li>
<li><a
href="https://snyk.io/redirect/github/remix-run/react-router/commit/c0b4e12d12c5abdf5f7723e71959c4eb5e9effd9">c0b4e12</a>
Merge branch &#x27;main&#x27; into release-next</li>
<li><a
href="https://snyk.io/redirect/github/remix-run/react-router/commit/58d421fc4c592661a68dea59edc507fc4668ba5d">58d421f</a>
Fix other code paths for resolveTo from a splat route (near#11045)</li>
<li><a
href="https://snyk.io/redirect/github/remix-run/react-router/commit/5f530a775cd266940f725894277b6ea7bc55b5d0">5f530a7</a>
Do not revalidate unmounted fetchers when v7_persistFetcher is enabled
(near#11044)</li>
<li><a
href="https://snyk.io/redirect/github/remix-run/react-router/commit/f320378b5145f59bb266a35a7655b563f712daef">f320378</a>
Add additional test case for near#10983</li>
<li><a
href="https://snyk.io/redirect/github/remix-run/react-router/commit/a48c43c8118bbf75b23b3ee748648bb3ee4d688e">a48c43c</a>
feat: export &#x60;PathParam&#x60; type (near#10719)</li>
<li><a
href="https://snyk.io/redirect/github/remix-run/react-router/commit/1d56e55d3f95730f99617dff23cf153f82394921">1d56e55</a>
Remove tag links from headings in CHANGELOG.md</li>
<li><a
href="https://snyk.io/redirect/github/remix-run/react-router/commit/3b1a7364c730209b4baed9454c7f6c17c55e3ba8">3b1a736</a>
Fix flaky test</li>
<li><a
href="https://snyk.io/redirect/github/remix-run/react-router/commit/406a1ddecd399ede2a517d7cae5f3ee63d02ed91">406a1dd</a>
Merge branch &#x27;release-next&#x27; into dev</li>
<li><a
href="https://snyk.io/redirect/github/remix-run/react-router/commit/6a5939b07c06c9dacd82705645dbbbe46de90e5e">6a5939b</a>
Merge branch &#x27;release-next&#x27;</li>
    </ul>

<a
href="https://snyk.io/redirect/github/remix-run/react-router/compare/dcf0c2a85aac3a78059a287ea478ff12adcb6a2d...3cc38eac4753702a9a8a1fe239e2138d63ac6cc5">Compare</a>
  </details>
</details>
<hr/>

**Note:** *You are seeing this because you or someone else with access
to this repository has authorized Snyk to open upgrade PRs.*

For more information: <img
src="https://api.segment.io/v1/pixel/track?data=eyJ3cml0ZUtleSI6InJyWmxZcEdHY2RyTHZsb0lYd0dUcVg4WkFRTnNCOUEwIiwiYW5vbnltb3VzSWQiOiIyZmI3YjkxYi0zN2NiLTQzYzgtOWNkYS02ODAzNTFmYzMwNmQiLCJldmVudCI6IlBSIHZpZXdlZCIsInByb3BlcnRpZXMiOnsicHJJZCI6IjJmYjdiOTFiLTM3Y2ItNDNjOC05Y2RhLTY4MDM1MWZjMzA2ZCJ9fQ=="
width="0" height="0"/>

🧐 [View latest project
report](https://app.snyk.io/org/ecp88/project/98480bdc-d80b-4fd1-89d7-c4c56a706763?utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr)

🛠 [Adjust upgrade PR
settings](https://app.snyk.io/org/ecp88/project/98480bdc-d80b-4fd1-89d7-c4c56a706763/settings/integration?utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr)

🔕 [Ignore this dependency or unsubscribe from future upgrade
PRs](https://app.snyk.io/org/ecp88/project/98480bdc-d80b-4fd1-89d7-c4c56a706763/settings/integration?pkg&#x3D;react-router-dom&amp;utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr#auto-dep-upgrades)

<!---
(snyk:metadata:{"prId":"2fb7b91b-37cb-43c8-9cda-680351fc306d","prPublicId":"2fb7b91b-37cb-43c8-9cda-680351fc306d","dependencies":[{"name":"react-router-dom","from":"6.19.0","to":"6.20.0"}],"packageManager":"npm","type":"auto","projectUrl":"https://app.snyk.io/org/ecp88/project/98480bdc-d80b-4fd1-89d7-c4c56a706763?utm_source=github&utm_medium=referral&page=upgrade-pr","projectPublicId":"98480bdc-d80b-4fd1-89d7-c4c56a706763","env":"prod","prType":"upgrade","vulns":[],"issuesToFix":[],"upgrade":[],"upgradeInfo":{"versionsDiff":2,"publishedDate":"2023-11-22T16:56:32.720Z"},"templateVariants":[],"hasFixes":false,"isMajorUpgrade":false,"isBreakingChange":false,"priorityScoreList":[]})
--->

Co-authored-by: snyk-bot <snyk-bot@snyk.io>
Co-authored-by: nikurt <86772482+nikurt@users.noreply.github.com>
@wacban wacban force-pushed the waclaw-congestion-model-csv branch from 0de8198 to e2503f2 Compare March 7, 2024 14:26
@wacban
Copy link
Contributor Author

wacban commented Mar 7, 2024

Balanced Simple Backpressure

Screenshot 2024-03-07 at 15 38 11

AllToOne SimpleBackpressure

Screenshot 2024-03-07 at 15 37 59

@wacban
Copy link
Contributor Author

wacban commented Mar 7, 2024

A few more stats need to be added as well as stats for other strategies but I'll leave that for later.

Copy link
Contributor

@jakmeier jakmeier left a comment

Choose a reason for hiding this comment

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

I love this conceptually! Getting all the data out in a CSV is exactly what we need to solve the evaluation part cleanly. The summary table was a very crude first example of how we could get an output, this is miles better.

However, you are breaking several of the code architecture invariants. 😅 Not your fault, of course, you couldn't know it. But the way I had it in my mind, I wanted to keep the code base modular with minimal cross-over between the 4 main components (strategy, workload, model, evaluation). You can kind of see it how your changes forced you to pass around the stats writer to many files that shouldn't be affected by such a change.

I've tried to explain what my architectural idea is in in-line comments. Please take a look and let me know if you agree / want to follow my proposed architecture. Or if you think it's too much work or just not a good idea, we can can also work out a different architecture together, I'm open to your suggestions.

@wacban wacban force-pushed the waclaw-congestion-model-csv branch from e2503f2 to 30ccf14 Compare March 10, 2024 17:34
@@ -23,17 +23,17 @@ impl QueueBundle {
};

for &shard in shards {
let mailbox = this.new_queue(shard);
let mailbox = this.new_queue(shard, "mailbox");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What the heck is mailbox? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Borrowed vocabulary from the actor model

https://www.brianstorti.com/the-actor-model/

The model basically treats each shard as an actor and the implicit incoming receipts queue is the actor's mailbox. And that's no coincidence. I always like to map problems to solutions that already exist.

Not only is the model implemented this way, I think even the real implementation can be thought of this way. Taking inspiration from Erlang, Akka, Actix, and other established actor frameworks could be useful. But it's also quite limited since they generally react to full queues by dropping messages / returning failures (which I still think we can avoid) and they don't operate on a global round-based clock that the blockchain has thanks to block heights. I think those are the main differences in constraints.

Anyway, sorry for the off-topic rambling... "mailbox" as the queue name makes sense in my mind but open to other names :)

@wacban
Copy link
Contributor Author

wacban commented Mar 10, 2024

new impl with new stats

simple backpressure, balanced - unbounded - waiting transactions is ever growing
Screenshot 2024-03-10 at 18 30 52

simple backpressure, all to one - deadlocking - finished transactions goes flat about halfway the evaluation
Screenshot 2024-03-10 at 18 31 43

@wacban wacban requested a review from jakmeier March 10, 2024 17:53
Copy link
Contributor

@jakmeier jakmeier left a comment

Choose a reason for hiding this comment

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

Thanks @wacban for the changes! I personally like this much better, as it now fits in perfectly with the intended architecture.

This is going to be suuper helpful to analyse and compare different strategies!

@@ -23,17 +23,17 @@ impl QueueBundle {
};

for &shard in shards {
let mailbox = this.new_queue(shard);
let mailbox = this.new_queue(shard, "mailbox");
Copy link
Contributor

Choose a reason for hiding this comment

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

Borrowed vocabulary from the actor model

https://www.brianstorti.com/the-actor-model/

The model basically treats each shard as an actor and the implicit incoming receipts queue is the actor's mailbox. And that's no coincidence. I always like to map problems to solutions that already exist.

Not only is the model implemented this way, I think even the real implementation can be thought of this way. Taking inspiration from Erlang, Akka, Actix, and other established actor frameworks could be useful. But it's also quite limited since they generally react to full queues by dropping messages / returning failures (which I still think we can avoid) and they don't operate on a global round-based clock that the blockchain has thanks to block heights. I think those are the main differences in constraints.

Anyway, sorry for the off-topic rambling... "mailbox" as the queue name makes sense in my mind but open to other names :)

@@ -38,7 +38,7 @@ pub struct Model {
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ShardId(usize);
pub struct ShardId(pub usize);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still needed, or just an artefact from previous code iterations? If it's not necessary, I'd prefer this to stay private.

Making it pub is okay for our little model if it makes things easier. But generally speaking, it breaks the intended type safety. While the value is private, we can guarantee that ShardId can only be created inside this file. So it's easy to check invariants on it. That's about halve the motivation for wrapping the usize in a new type. It's the same pattern I used for QueueId, TransactionId, and ReceiptId.

If you just need read-only access to the number, adding a simple getter method, or maybe impl From<ShardId> for usize {} or even impl Deref for ShardId { type Target = usize } could do the trick without breaking type properties but still allows reading the number with id.into() or *id, which seems just as convenient as id.0.

@wacban wacban enabled auto-merge March 11, 2024 08:40
@wacban wacban added this pull request to the merge queue Mar 11, 2024
Merged via the queue into master with commit 6d38a71 Mar 11, 2024
30 checks passed
@wacban wacban deleted the waclaw-congestion-model-csv branch March 11, 2024 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants