Question

Using $84 CPU-intensive Droplet for backend, but only 4 people can use at the same time

Hi I have a problem where I already set up a $5 basic droplet for frontend and $84 CPU-intensive droplet for backend.

Unfortunately, only 4 people can process the function in the backend at the same time. The rest will cause error. My backend is heavy as it is heavy on writing the results on images.

Plus, when I view “htop” in the Droplet when running 1 function in the web, all 4 CPU is at 100% and the CPU percentage reach 400%. And it won’t go down even after the process is completed.

May I know if any of you had faced this problem before?

Is the root cause the Droplet itself or can you provide me a guidance to find the root cause. How do I optimized CPU in my droplet? Or please suggest me a good way to solve this matter.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
February 27, 2024

Heya,

The issue you’re experiencing with high CPU usage and limited concurrent processing capacity on your backend server could be due to several factors. To address this problem effectively, it’s important to systematically identify the root cause and then explore optimization strategies. Here’s a structured approach:

Identifying the Root Cause

  1. Code Profiling and Optimization:

    • Use profiling tools to identify which parts of your code are most CPU-intensive.
    • Optimize algorithms or code sections that are consuming the most resources.
    • Check for any infinite loops or unnecessary repeated computations.
  2. Concurrency and Parallel Processing:

    • Investigate how your application handles concurrent requests. If it’s not optimized for concurrency, it could lead to CPU bottlenecks.
    • Implement asynchronous processing or multi-threading/multi-processing where feasible.
  3. Resource Leaks:

    • Look for memory leaks or unclosed resources that might be causing the CPU to remain high even after processing is completed.
    • Ensure proper resource management, like closing file handles and database connections.
  4. Dependency and Library Check:

    • Ensure that all libraries and dependencies are up-to-date and are known for efficient performance.
    • Sometimes, specific versions of libraries may have performance issues.
  5. Server Configuration:

    • Check the server configuration for any limitations set on process handling or resource allocation.
    • Ensure your server is configured to make optimal use of the available CPUs.

Optimization Strategies

  1. Load Balancing:

    • Implement load balancing to distribute the workload across multiple backend servers.
    • This can help in handling more concurrent users and reduce the load on a single server.
  2. Scaling Up or Out:

    • Consider scaling up (upgrading your existing Droplet to a more powerful one) if your application requires more resources.
    • Alternatively, scaling out (adding more Droplets and distributing the load) can also be a viable solution.
  3. Caching:

    • Implement caching mechanisms for frequently accessed data or results to reduce redundant processing.
    • This can significantly decrease the CPU load for repeat operations.
  4. Optimized Image Processing:

    • Since your backend is heavy on writing results on images, optimize your image processing routines.
    • Consider using more efficient image processing libraries or techniques.
  5. Monitoring Tools:

    • Utilize monitoring tools to continuously track the performance of your server.
    • Tools like htop, nmon, or even more sophisticated monitoring solutions can provide insights into real-time performance.

Additional Considerations

  • Architecture Review: Sometimes, the issue is not just the code or the server but the overall architecture of the application. Ensure that your backend architecture is suitable for the tasks it’s performing.
  • External Services: If your backend relies on external services or APIs, check their performance and availability as they can also impact your server’s CPU usage.
  • Testing and Benchmarking: Conduct load testing to understand how your application behaves under different loads. This can provide valuable insights into how to scale and optimize.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel