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

Increase k8s resources for spatial microservice #4026

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from

Conversation

Mnoble-19
Copy link
Contributor

@Mnoble-19 Mnoble-19 commented Dec 8, 2024

Description

[Increase memory for spatial microservice]

Related Issues

This microservice was assigned limited space during creation. this PR increases it. @Psalmz777 with regards to cost optimisation OKR. @sserurich has clarified that the mozilla funding should cater for this and incase of need for more. Mozilla is in position to provide more.
Screenshot 2024-12-09 at 00 52 51

Changes Made

  • Add more resources (cpu, memory) both requests and limits

Additional Notes

[Add any additional notes or comments here]

Summary by CodeRabbit

  • New Features
    • Increased resource limits for the airqo-spatial-api application to enhance performance.
    • Added resource limits for the airqo-stage-spatial-api application.
  • Bug Fixes
    • Adjusted CPU and memory requests for both applications to optimize resource allocation.

Copy link
Contributor

coderabbitai bot commented Dec 8, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request involve updates to the resource limits and requests for the airqo-spatial-api and airqo-stage-spatial-api applications in their respective Kubernetes configuration files. The values-prod.yaml file sees significant increases in both CPU and memory limits and requests, while the values-stage.yaml file introduces new resource limits and updates existing requests. Overall, the structure of both configuration files remains unchanged aside from these resource adjustments.

Changes

File Path Change Summary
k8s/spatial/values-prod.yaml - Updated CPU limits from 100m to 1000m
- Updated memory limits from 350Mi to 1800Mi
- Updated CPU requests from 10m to 400m
- Updated memory requests from 250Mi to 550Mi
k8s/spatial/values-stage.yaml - Added CPU limits set to 900m
- Added memory limits set to 1200Mi
- Updated CPU requests from 10m to 100m
- Updated memory requests from 180Mi to 400Mi

Possibly related PRs

  • Update/implement celery k8s executor #3595: The changes in this PR involve updates to resource limits in the values-stage.yaml file, which is related to resource allocation similar to the changes made in the main PR for values-prod.yaml.

Suggested reviewers

  • BenjaminSsempala
  • Psalmz777
  • Baalmart

🌟 In the land of code where limits rise,
The spatial-api reaches for the skies.
With memory and CPU now set to soar,
Our applications thrive, ready to explore!
In staging and production, changes align,
A brighter future for all, how divine! 🌟


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>, 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 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.

Copy link

codecov bot commented Dec 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 11.73%. Comparing base (be69e9b) to head (96e7eb9).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           staging    #4026   +/-   ##
========================================
  Coverage    11.73%   11.73%           
========================================
  Files          114      114           
  Lines        15331    15331           
  Branches       319      319           
========================================
  Hits          1799     1799           
  Misses       13532    13532           

Copy link
Contributor

@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

🧹 Outside diff range and nitpick comments (1)
k8s/spatial/values-prod.yaml (1)

18-19: Consider adjusting the memory limit to request ratio

The current configuration shows:

  • Memory requests: 550Mi
  • Memory limits: 1800Mi
  • Ratio: ~3.3:1

While this configuration will work, consider reducing the memory limit or increasing the request to achieve a ratio closer to 2:1 or 2.5:1. This would:

  • Improve resource utilization predictability
  • Reduce the risk of node pressure during spikes
  • Better align with Kubernetes best practices

Suggested adjustments (choose one):

  resources:
    limits:
      cpu: 1000m
-     memory: 1800Mi
+     memory: 1375Mi  # 2.5:1 ratio
    requests:
      cpu: 400m
      memory: 550Mi

OR

  resources:
    limits:
      cpu: 1000m
      memory: 1800Mi
    requests:
      cpu: 400m
-     memory: 550Mi
+     memory: 720Mi  # 2.5:1 ratio
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between be69e9b and 96e7eb9.

📒 Files selected for processing (2)
  • k8s/spatial/values-prod.yaml (1 hunks)
  • k8s/spatial/values-stage.yaml (1 hunks)
🔇 Additional comments (1)
k8s/spatial/values-prod.yaml (1)

15-16: Verify the significant increase in resource limits

The CPU and memory limits have been increased substantially:

  • CPU: 100m → 1000m (10x increase)
  • Memory: 350Mi → 1800Mi (~5x increase)

While the PR mentions Mozilla funding support, we should verify:

  1. Historical resource utilization patterns justifying these increases
  2. Cost implications of these new limits
✅ Verification successful

Since we couldn't access the Kubernetes metrics directly, let's analyze the historical context and documentation to understand the rationale behind these resource increases. This will help us verify if these changes align with documented requirements or previous patterns.


Let's analyze the staging configuration and recent changes to understand if there's a pattern of increased resource usage or documented performance issues that justify these significant increases.


Resource increases appear reasonable based on staging environment patterns

The significant resource increases in production align with the staging environment configuration, which shows similar resource patterns:

  • Staging uses 900m CPU limit vs. 1000m in production
  • Staging uses 1200Mi memory limit vs. 1800Mi in production
  • Both environments maintain similar CPU limit:request ratios

The incremental increase from staging to production (approximately 10-50% higher) follows a reasonable pattern for production scaling, especially with the higher replica count and load expectations in production.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Retrieve recent resource usage metrics for the spatial service

# Get recent pod metrics
kubectl top pod -n production -l app=airqo-spatial-api --sort-by=memory

# Get recent HPA events
kubectl get events -n production --field-selector involvedObject.kind=HorizontalPodAutoscaler,involvedObject.name=airqo-spatial-api

Length of output: 403


Script:

#!/bin/bash
# Let's try to analyze the git history of the values file to understand the context
# and previous resource configurations

# Show the full history of changes to the values file
git log -p k8s/spatial/values-prod.yaml

# Also check if there are any related configuration files or documentation
fd -t f "values.*ya?ml" k8s/spatial/

# Look for any related documentation about resource requirements
rg -i "resource|memory|cpu" README.md docs/

Length of output: 143


Script:

#!/bin/bash
# Let's compare the staging and production configurations
cat k8s/spatial/values-stage.yaml

# Also check for any recent changes to both files
git log --since="3 months ago" --oneline k8s/spatial/values-stage.yaml k8s/spatial/values-prod.yaml

# Look for any performance-related issues or discussions in recent commits
git log --since="3 months ago" --grep="performance\|memory\|cpu\|resource" --oneline

Length of output: 789

Comment on lines +15 to 19
cpu: 900m
memory: 1200Mi
requests:
cpu: 100m
memory: 400Mi
Copy link
Contributor

@coderabbitai coderabbitai bot Dec 8, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Adjust CPU request to maintain reasonable limit:request ratio

The current configuration shows concerning ratios:

  1. CPU limit:request = 9:1 (900m:100m)
    • This is significantly higher than the production ratio of 2.5:1
    • High ratios can lead to resource contention and unpredictable performance
  2. Memory limit:request = 3:1 (1200Mi:400Mi)
    • This aligns well with production's ratio

Recommended changes to maintain environment parity and best practices:

  resources:
    limits:
      cpu: 900m
      memory: 1200Mi
    requests:
-     cpu: 100m
+     cpu: 360m  # Creates a 2.5:1 ratio, matching production
      memory: 400Mi

Additional considerations:

  1. The staging environment now has:

    • 90% of production's CPU limits
    • 67% of production's memory limits
      This seems reasonable for a staging environment while maintaining similar characteristics.
  2. Different autoscaling configurations:

    • Staging: maxReplicas: 2, targetMemoryUtilizationPercentage: 80%
    • Production: maxReplicas: 3, targetMemoryUtilizationPercentage: 70%
      This aligns with expected staging vs production scaling needs.
📝 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
cpu: 900m
memory: 1200Mi
requests:
cpu: 100m
memory: 400Mi
cpu: 900m
memory: 1200Mi
requests:
cpu: 360m
memory: 400Mi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Psalmz777 share your opinion on this

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

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