Skip to content

feat: create many concurrent requests #14

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 7 commits into
base: main
Choose a base branch
from

Conversation

MantisClone
Copy link
Member

@MantisClone MantisClone commented Apr 16, 2025

Problem

I needed a way to simulate many concurrent users persisting requests at the same time.

Solution

This PR adds the createManyConcurrentRequests.js script which uses p-limit to control the concurrency of an array of Promises. Each promise creates one request.

Summary by CodeRabbit

  • New Features
    • Added a script to create multiple concurrent payment requests with real-time progress tracking.
  • Documentation
    • Updated the README to include instructions for the new script.
  • Chores
    • Added new dependencies to support progress tracking and concurrency control.

Copy link

coderabbitai bot commented Apr 16, 2025

Walkthrough

The changes introduce a new script, create-many, to the project. This script enables the creation of multiple concurrent payment requests using the Request Network client. The necessary dependencies (cli-progress and p-limit) are added to support concurrency control and progress visualization. The README.md is updated to document the new script command, and the package.json is modified to include the new script and dependencies. The script itself, located at src/createManyConcurrentRequests.js, is implemented to manage concurrent request creation with progress tracking and graceful interruption handling.

Changes

File(s) Change Summary
README.md Added documentation for the new npm run create-many script command.
package.json Added the create-many script; added cli-progress and p-limit as new dependencies.
src/createManyConcurrentRequests.js Added a new script to create multiple concurrent payment requests with concurrency control and progress bars.

Suggested reviewers

  • rodrigopavezi
  • sstefdev
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@MantisClone MantisClone marked this pull request as ready for review April 25, 2025 23:32
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (6)
README.md (1)

44-44: Documentation update is minimal but sufficient.

The new command is documented alongside existing commands, which is good. Consider enhancing this with a brief description of what the command does and any parameters it accepts.

src/createManyConcurrentRequests.js (5)

15-18: Make configuration values externally configurable.

Currently, TOTAL_REQUESTS and CONCURRENCY_LIMIT are hard-coded. Consider making these configurable via environment variables or command-line arguments to improve flexibility.

- const TOTAL_REQUESTS = 100; // Total number of requests to create
- const CONCURRENCY_LIMIT = 100; // Number of requests to create concurrently
+ const TOTAL_REQUESTS = parseInt(process.env.TOTAL_REQUESTS || '100', 10); // Total number of requests to create
+ const CONCURRENCY_LIMIT = parseInt(process.env.CONCURRENCY_LIMIT || '100', 10); // Number of requests to create concurrently

23-26: Consider validating all required environment variables.

Currently, only PAYEE_PRIVATE_KEY is validated. Consider checking other potentially required variables like JSON_RPC_PROVIDER_URL that might be needed for the Request Network client.


103-138: Make request parameters configurable.

The currency, network, and other request parameters are hard-coded. Consider making these configurable to improve reusability for different testing scenarios.

You could extract key parameters to variables at the top of the file or read them from environment variables:

+ // Request configuration from env vars or defaults
+ const CURRENCY_TYPE = process.env.CURRENCY_TYPE || Types.RequestLogic.CURRENCY.ERC20;
+ const CURRENCY_VALUE = process.env.CURRENCY_VALUE || "0x370DE27fdb7D1Ff1e1BaA7D11c5820a324Cf623C";
+ const CURRENCY_NETWORK = process.env.CURRENCY_NETWORK || "sepolia";
+ const EXPECTED_AMOUNT = process.env.EXPECTED_AMOUNT || "1000000000000000000";

// Later in the requestCreateParameters
  currency: {
-   type: Types.RequestLogic.CURRENCY.ERC20,
-   value: "0x370DE27fdb7D1Ff1e1BaA7D11c5820a324Cf623C",
-   network: "sepolia",
+   type: CURRENCY_TYPE,
+   value: CURRENCY_VALUE,
+   network: CURRENCY_NETWORK,
  },
- expectedAmount: "1000000000000000000",
+ expectedAmount: EXPECTED_AMOUNT,

145-150: Improved error handling.

The error handling is good, with simplified error output to prevent console spam during concurrent operations. Consider adding more specific error handling for common failure scenarios to help with debugging.


1-184: Overall excellent implementation with room for configurability improvements.

The script is well-structured with proper error handling, progress tracking, and abort handling. The main improvement opportunity is to make the various hard-coded parameters configurable to increase flexibility and reusability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2442c6f and 2ba7ad4.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • README.md (1 hunks)
  • package.json (1 hunks)
  • src/createManyConcurrentRequests.js (1 hunks)
🔇 Additional comments (6)
package.json (3)

14-15: Is the "hinkal-deposit" script related to this PR?

I notice both a "hinkal-deposit" script and the new "create-many" script were added. Since the PR description only mentions creating concurrent requests, could you clarify if the "hinkal-deposit" script is part of this PR's scope or should be addressed separately?


15-15: The create-many script integration looks good.

The script name follows the existing naming pattern and correctly points to the implementation file.


23-23: Dependencies added appropriately.

The cli-progress and p-limit libraries are appropriate choices for this feature. The version constraints using caret notation (^) match the project's versioning style.

Also applies to: 26-26

src/createManyConcurrentRequests.js (3)

34-37: Good implementation of abort handling.

The script properly handles SIGINT (Ctrl+C) to gracefully abort the operation, which is essential for long-running tasks.


39-54: Excellent progress tracking implementation.

The multi-progress bar with successful, failed, and in-progress counters provides clear visibility into the operation status.


170-182: Comprehensive execution summary.

The summary at the end provides clear statistics about the operation, which is valuable for understanding the results.

Comment on lines +62 to +67
const requestClient = new RequestNetwork({
nodeConnectionConfig: {
baseURL: "http://localhost:3000/",
},
signatureProvider: epkSignatureProvider,
});
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Make node URL configurable.

The node connection URL is hard-coded to "http://localhost:3000/". Consider making this configurable via an environment variable to support different environments.

  const requestClient = new RequestNetwork({
    nodeConnectionConfig: {
-      baseURL: "http://localhost:3000/",
+      baseURL: process.env.REQUEST_NODE_URL || "http://localhost:3000/",
    },
    signatureProvider: epkSignatureProvider,
  });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const requestClient = new RequestNetwork({
nodeConnectionConfig: {
baseURL: "http://localhost:3000/",
},
signatureProvider: epkSignatureProvider,
});
const requestClient = new RequestNetwork({
nodeConnectionConfig: {
baseURL: process.env.REQUEST_NODE_URL || "http://localhost:3000/",
},
signatureProvider: epkSignatureProvider,
});

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.

1 participant