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

Add 321.pdf-generator benchmark and its data #217

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

octonawish-akcodes
Copy link
Collaborator

@octonawish-akcodes octonawish-akcodes commented Aug 24, 2024

This Pull Request introduces a new PDF Generation benchmark for SEBS, implemented using Node.js. The benchmark leverages the Puppeteer library to facilitate the PDF generation process.

Details

  • Library: The benchmark utilizes puppeteer-core at version 22.15.0.
  • Browser Compatibility: This version of puppeteer-core does not include a bundled browser. For optimal performance and compatibility, the benchmark is configured to work with Chrome version 127.0.6533.88, which is fully supported by puppeteer-core version 22.15.0.

The specific Chrome version was chosen to ensure compatibility and stability with the selected puppeteer-core version, allowing the benchmark to reliably generate PDFs in various testing environments.

Summary by CodeRabbit

  • New Features

    • Introduced configuration files for PDF generation benchmarks, allowing customizable settings.
    • Added functionality to automate the generation of input configurations, handling HTML and image uploads.
    • Implemented serverless functions to convert HTML to PDF using Puppeteer.
    • Added shell scripts for automating the setup of a Chromium browser environment for testing.
    • Established new Node.js projects for benchmarking PDF generation.
  • Bug Fixes

    • Improved error handling during PDF generation processes.

Copy link

coderabbitai bot commented Aug 24, 2024

Walkthrough

The recent updates involve the addition of new files and configurations for a benchmark project focused on PDF generation using Puppeteer. Key changes include the introduction of configuration files, scripts for input generation, and automation for setting up a Chromium environment. These modifications streamline the process of converting HTML to PDF in a cloud setting and enhance resource management.

Changes

Files Change Summary
benchmarks-data Updated subproject commit identifier.
benchmarks/600.pdf/.../config.json New configuration file for generator settings, including timeout, memory, and supported languages.
benchmarks/600.pdf/.../input.py New file for generating input configurations, including functions for managing HTML files and images.
benchmarks/600.pdf/.../nodejs/function.js New serverless function to generate PDF from HTML using Puppeteer.
benchmarks/600.pdf/.../nodejs/init.sh New shell script for automating Chromium setup.
benchmarks/600.pdf/.../nodejs/package.json New package.json file for the Node.js project specifying dependencies and project metadata.
benchmarks/300.utilities/.../config.json New configuration file for the PDF generator with timeout, memory, and supported languages.
benchmarks/300.utilities/.../input.py New file for generating input configurations for PDF generation.
benchmarks/300.utilities/.../nodejs/function.js New Node.js function to generate a PDF from HTML using Puppeteer.
benchmarks/300.utilities/.../nodejs/init.sh New shell script for setting up the Chromium environment.
benchmarks/300.utilities/.../nodejs/package.json New package.json file for the PDF generator project.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Generator
    participant CloudStorage
    participant Puppeteer

    User->>Generator: Request PDF generation
    Generator->>CloudStorage: Retrieve HTML file
    CloudStorage->>Generator: Send HTML file
    Generator->>Puppeteer: Render HTML to PDF
    Puppeteer-->>Generator: Return PDF
    Generator->>CloudStorage: Upload PDF
    CloudStorage-->>Generator: Confirm upload
    Generator-->>User: PDF generation complete
Loading

🐇 In the garden of code, new blooms arise,
With configs and scripts that reach for the skies.
HTML to PDF, a whimsical dance,
In the land of benchmarks, giving change a chance!
Hops and skips, the functions unite,
A world of automation, oh what a delight! 🌼✨

Warning

Review ran into problems

Problems (1)
  • Git: Failed to clone repository. Please contact CodeRabbit support.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@octonawish-akcodes
Copy link
Collaborator Author

When I was testing the HTML code with sample image puppeteer couldn't fetch the image from the location to add it in the pdf, so that's why I was thinking to use a direct (URL of the image in the HTML) document or use the web page URL (which of course we cant use because of the discussion we had). So this was the main issue, other wise the benchmark is working perfectly fine.

@mcopik

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: 5

Outside diff range, codebase verification and nitpick comments (1)
benchmarks/600.pdf/601.pdf-generator/input.py (1)

7-32: Add comments to clarify the input generation process.

The function generate_input is well-structured but could benefit from additional comments to explain its steps.

Consider adding comments like this:

def generate_input(data_dir, size, benchmarks_bucket, input_paths, output_paths, upload_func):
    # Paths for the HTML template and images
    input_file_path = os.path.join(data_dir, 'template', 'demo.html')
    images_dir = os.path.join(data_dir, 'template', 'images')

    # Initialize the input configuration dictionary
    input_config = {'object': {}, 'bucket': {}}

    # Upload the HTML file to the input bucket
    upload_func(0, "demo.html", input_file_path)

    # Configure the bucket paths
    input_config['bucket']['bucket'] = benchmarks_bucket
    input_config['bucket']['input'] = input_paths[0]
    input_config['bucket']['output'] = output_paths[0]

    # Upload each image in the images directory
    for file in glob.glob(os.path.join(images_dir, '*.png')):
        img = os.path.relpath(file, data_dir)
        upload_func(0, img, file)

    # Store image configuration in 'object'
    input_config['object']['key'] = "images/"
    input_config['object']['input_file'] = 'demo.html'

    return input_config
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6d7b456 and 019d571.

Files selected for processing (6)
  • benchmarks-data (1 hunks)
  • benchmarks/600.pdf/601.pdf-generator/config.json (1 hunks)
  • benchmarks/600.pdf/601.pdf-generator/input.py (1 hunks)
  • benchmarks/600.pdf/601.pdf-generator/nodejs/function.js (1 hunks)
  • benchmarks/600.pdf/601.pdf-generator/nodejs/init.sh (1 hunks)
  • benchmarks/600.pdf/601.pdf-generator/nodejs/package.json (1 hunks)
Files skipped from review due to trivial changes (3)
  • benchmarks-data
  • benchmarks/600.pdf/601.pdf-generator/config.json
  • benchmarks/600.pdf/601.pdf-generator/nodejs/package.json
Additional context used
Shellcheck
benchmarks/600.pdf/601.pdf-generator/nodejs/init.sh

[warning] 4-4: VERBOSE appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 9-9: SCRIPT_DIR appears unused. Verify use (or export if used externally).

(SC2034)

benchmarks/600.pdf/601.pdf-generator/nodejs/init.sh Outdated Show resolved Hide resolved
benchmarks/600.pdf/601.pdf-generator/nodejs/init.sh Outdated Show resolved Hide resolved
benchmarks/600.pdf/601.pdf-generator/nodejs/function.js Outdated Show resolved Hide resolved
benchmarks/600.pdf/601.pdf-generator/nodejs/function.js Outdated Show resolved Hide resolved
benchmarks/600.pdf/601.pdf-generator/nodejs/function.js Outdated Show resolved Hide resolved
@octonawish-akcodes
Copy link
Collaborator Author

Benchmark PR data is here spcl/serverless-benchmarks-data#4

Signed-off-by: Abhishek Kumar <[email protected]>
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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 019d571 and 7802114.

Files selected for processing (5)
  • benchmarks/300.utilities/321.pdf-generator/config.json (1 hunks)
  • benchmarks/300.utilities/321.pdf-generator/input.py (1 hunks)
  • benchmarks/300.utilities/321.pdf-generator/nodejs/function.js (1 hunks)
  • benchmarks/300.utilities/321.pdf-generator/nodejs/init.sh (1 hunks)
  • benchmarks/300.utilities/321.pdf-generator/nodejs/package.json (1 hunks)
Files skipped from review due to trivial changes (1)
  • benchmarks/300.utilities/321.pdf-generator/nodejs/package.json
Additional context used
Shellcheck
benchmarks/300.utilities/321.pdf-generator/nodejs/init.sh

[warning] 4-4: VERBOSE appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 9-9: SCRIPT_DIR appears unused. Verify use (or export if used externally).

(SC2034)

Additional comments not posted (11)
benchmarks/300.utilities/321.pdf-generator/config.json (3)

2-2: LGTM!

The timeout setting of 60 seconds seems reasonable for a PDF generation task.


3-3: LGTM!

The memory setting of 256 MB seems reasonable for a PDF generation task.


4-4: LGTM!

The languages setting appropriately includes "nodejs" for the task.

benchmarks/300.utilities/321.pdf-generator/nodejs/init.sh (4)

6-10: LGTM!

The Chromium URL and download directory setup are appropriate.

Tools
Shellcheck

[warning] 9-9: SCRIPT_DIR appears unused. Verify use (or export if used externally).

(SC2034)


12-16: LGTM!

The directory creation and file download are correctly implemented.


18-22: LGTM!

The file extraction and cleanup are correctly implemented.


24-28: LGTM!

The file move and directory removal are correctly implemented.

benchmarks/300.utilities/321.pdf-generator/input.py (1)

1-5: LGTM!

The imports are appropriate, and the buckets_count function correctly returns a tuple.

benchmarks/300.utilities/321.pdf-generator/nodejs/function.js (3)

7-9: LGTM!

The variable declarations are appropriate for the task at hand.

The code changes are approved.


12-53: Improve error handling and readability.

  1. Add error handling for page.setContent and page.pdf to handle potential errors during PDF generation.
  2. Consider using async/await for stream operations to improve readability.
  3. Ensure the inputStream is properly closed after use.

Apply this diff to improve error handling and readability:

try {
  // Download the HTML file from storage
  const inputStream = await readStreamPromise;
  inputStream.pipe(htmlStream);

  // Launch Puppeteer and generate the PDF
  const browser = await puppeteer.launch({ executablePath: browserPath });
  const page = await browser.newPage();
  try {
    await page.setContent(await streamToString(htmlStream), { waitUntil: 'networkidle0' });
    const pdfBuffer = await page.pdf({ format: 'A4' });
    
    // Close Puppeteer
    await browser.close();

    // Pipe the PDF buffer into the write stream
    writeStream.write(pdfBuffer);
    writeStream.end();

    // Wait for upload to complete
    await promise;

    return { bucket: output_prefix, key: uploadName };
  } catch (error) {
    console.error('Error generating PDF:', error);
    await browser.close();
    throw error;
  } finally {
    inputStream.destroy();
  }
} catch (error) {
  console.error('Error generating PDF:', error);
  throw error;
}

55-63: LGTM!

The streamToString function is well-implemented and handles stream conversion correctly.

The code changes are approved.

@octonawish-akcodes octonawish-akcodes changed the title Add 601.pdf-generator benchmark and its data Add 321.pdf-generator benchmark and its data Aug 26, 2024
@mcopik
Copy link
Collaborator

mcopik commented Aug 27, 2024

@octonawish-akcodes Thanks for the PR! What would be needed to add later a Python version?

@octonawish-akcodes
Copy link
Collaborator Author

@octonawish-akcodes Thanks for the PR! What would be needed to add later a Python version?

Yes, python version is remaining, since nodejs one was quite fast in development, I first added that. Need to dig deeper about the supported pyppeteer library and its corresponding supported chrome.

Signed-off-by: Abhishek Kumar <[email protected]>
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7802114 and 6d574fe.

Files selected for processing (1)
  • benchmarks/300.utilities/321.pdf-generator/nodejs/function.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • benchmarks/300.utilities/321.pdf-generator/nodejs/function.js

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