If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

Website Performance Optimization

Started by magdalenaprzes, Sep 05, 2023, 12:02 AM

Previous topic - Next topic

magdalenaprzesTopic starter

Recently, I noticed that my website on Peterhost hosting started to slow down even with low traffic (I won't provide a link to avoid advertising). After investigating, I discovered a bottleneck in the website's operation. There isn't enough storage space on the hosting, so some images need to be stored on another hosting. However, for SEO purposes, it's better to have all the images on the same domain as the site.

To address this issue, a picture proxy script was implemented two years ago using PHP. Here's a simplified version of the script written for clarification:

<?php
$imgs = file('./img-links.txt');
$addr = trim($imgs[$_REQUEST['id']]);
header('Content-type: image/jpeg');
readfile($addr);

I mentioned the hosting company's name because the tariff we use supports perl and c/c++ scripts. My question to the community is whether it would be beneficial to rewrite the proxy script in perl or c++. Would it reduce the processor and memory load? And how can it be implemented more easily and efficiently?

Changing hosting providers is not an option as cheap VDS hosting performs even worse than shared hosting due to limited resources. Switching to a dedicated server is also out of the question due to high rental costs.

UPDATE: Caching the images doesn't provide much benefit since they are downloaded approximately the same number of times. We use free services like Google Image Hosting-Picasa and Dropbox. Paying for large hosting resources is not feasible for us. To maintain SEO, we have to conceal the actual image placement from search engines. Additionally, our project targets users coming from search engines.

The main issue is not the performance of the script itself, but the overhead of creating a new PHP instance.

I would also like to emphasize the need to minimize time and money spent on the project. If we consider multiple projects, such as ten, then managing and monitoring the performance of ten dedicated servers would require me to transition from a programmer to a system administrator. Even now, there is not enough time to implement certain tasks. If I have to continue dealing with settings and infrastructure support, it might become overwhelming.
  •  


neodototh

Rewriting the proxy script in Perl or C++ may not necessarily reduce the processor and memory load significantly, as the bottleneck appears to be related to the overhead of creating a new PHP instance rather than the performance of the script itself.

However, if you are experienced in Perl or C++ programming and believe that optimizing the script in one of these languages could yield better results, it might be worth exploring. Keep in mind that rewriting the script will require time and effort, so it's important to evaluate the potential benefits and drawbacks before proceeding.

In terms of implementation, once you have rewritten the proxy script in your chosen language, you would need to modify your web server configuration to handle the new script accordingly. This may involve configuring the web server to execute Perl or C++ scripts and ensuring that the necessary dependencies are installed.

Alternatively, you could consider other approaches to address the storage limitation issue. For example, you could explore options to optimize image sizes, compress images for faster delivery, or offload image hosting to a separate service specifically designed for image delivery. These approaches may help improve website performance without having to rewrite the entire proxy script.

If you're looking to further optimize the performance of your website, there are a few additional steps you can consider:

1. Use a Content Delivery Network (CDN): A CDN can help distribute your website's static content (including images) across multiple servers, reducing the load on your hosting provider and improving delivery speed for users.

2. Implement caching: Implementing a caching mechanism can help store and serve frequently accessed content more efficiently, reducing the load on your server. This can be achieved through various caching techniques such as browser caching, reverse proxy caching, or using caching plugins for popular CMS platforms like WordPress.

3. Optimize your images: Ensure that your images are appropriately sized and compressed without sacrificing quality. Tools like image optimization plugins, or online services like TinyPNG or Kraken.io, can help compress your images while preserving visual quality.

4. Minify and compress your scripts: Minifying and compressing your JavaScript and CSS files can reduce their file size, leading to faster page load times. There are many online tools and build processes available that can automatically minify and compress your code.

5. Enable Gzip compression: Enabling Gzip compression on your server can significantly reduce the size of data transferred between the server and the user's browser, resulting in faster page load times.

6. Use a performance monitoring tool: Consider using a performance monitoring tool like New Relic or Google Analytics to gain insights into your website's performance, identify bottlenecks, and track improvements over time.

7. Enable HTTP/2: If your hosting provider and website infrastructure support it, consider enabling HTTP/2. This newer version of the HTTP protocol offers improved performance by allowing multiple file requests to be sent simultaneously over a single connection.

8. Enable browser caching: Configure your server to set appropriate caching headers for static resources like images, CSS, and JavaScript files. This allows browsers to store these resources locally, reducing the need to download them with each request.

9. Remove unnecessary plugins and scripts: Regularly audit your website for unused or unnecessary plugins, scripts, or other resources. Removing those that are not essential can reduce the overall load on your website and improve performance.

10. Optimize your database: If your website relies heavily on a database, make sure it is properly optimized. This includes using indexes, avoiding unnecessary queries or database calls, optimizing database queries, and ensuring proper database maintenance.

11. Monitor and optimize server resources: Keep an eye on your server's resource usage, such as CPU, memory, and disk I/O. Make sure that your website's demands are not exceeding the resources allocated by your hosting provider. If needed, consider upgrading to a higher-tier plan or exploring options for resource optimization.

12. Reduce external requests: Minimize the number of external requests your website makes, such as requests to third-party APIs, analytics services, or social media platforms. Each external request adds latency and potential points of failure.

13. Implement lazy loading: Consider implementing lazy loading for images and other content that may not be immediately visible on the user's screen. Lazy loading loads content as the user scrolls, reducing the initial page load time.

14. Consider using a performance-oriented web server: Depending on your hosting provider, you may have options to choose from different web servers like Apache, NGINX, or LiteSpeed. Research and compare their performance characteristics to determine which one can better handle your website's workload.

15. Enable Gzip compression: Gzip compression can significantly reduce the size of your website's files before they are sent to the user's browser. This reduces the bandwidth usage and speeds up the page load time. Most web servers and content management systems have options to enable Gzip compression.

16. Minimize redirects: Each redirect adds additional time and latency to the page load process. Review your website for unnecessary or excessive redirects and try to eliminate or minimize them.

17. Optimize DNS lookup time: DNS lookup time can impact the overall page load time. Consider using a DNS provider that offers fast and reliable lookup times, or even explore the option of using a DNS resolver like Google's public DNS.

18. Use a lightweight theme or template: If you're using a content management system like WordPress, choose a lightweight theme or template that is optimized for performance. Avoid complex and resource-intensive themes that can slow down your website.

19. Optimize third-party scripts and integrations: Evaluate the third-party scripts and integrations on your website, such as social media widgets or tracking pixels. Limit the number of these scripts or use asynchronous loading techniques to prevent them from blocking the rendering of your webpage.

20. Regularly update and maintain your website: Keep your website's CMS, plugins, themes, and scripts up to date to ensure you have the latest security patches and performance improvements. Regular maintenance can help optimize your website's performance.

21. Offload processes to the client-side: Whenever possible, offload resource-intensive processes like image resizing or complex calculations to the client-side using JavaScript. This reduces the server load and improves the responsiveness of your website for the user.

22. Monitor website performance with analytics: Utilize website performance analytics tools to track and analyze your website's performance metrics. This will help you identify bottlenecks and areas for improvement.

23. Implement server-side caching: Use server-side caching techniques like opcode caching (e.g., OPcache) or full-page caching to store pre-processed content that can be served directly from memory, reducing the load on your server and improving response times.

24. Utilize a load balancer: If your website experiences high traffic or you have multiple servers, consider using a load balancer to distribute the incoming requests across multiple servers. Load balancing helps distribute the load evenly and improves overall performance and availability.

25. Optimize database queries: Review your database queries and optimize them for efficiency. Ensure that you use appropriate indexes, avoid unnecessary queries, and optimize the schema design to minimize database resource usage.

26. Utilize asynchronous processing: Offload time-consuming tasks to background processes using technologies like message queues or task/job queues. This allows your web server to handle requests faster since it doesn't need to wait for these tasks to complete.

27. Implement application-level caching: Utilize in-memory caching systems like Redis or Memcached to cache frequently accessed data, such as query results or API responses. This reduces the need to make repeated expensive calculations or database queries.

28. Consider using a content distribution network (CDN): CDN services can cache your website's static content across multiple servers worldwide, delivering it from a server closer to the user's location. This reduces latency and improves content delivery speed.

29. Optimize front-end performance: Minimize the number of HTTP requests by combining and minifying CSS and JS files, using image sprites, and leveraging browser caching. Consider implementing techniques like lazy loading and deferred loading of non-critical resources to improve initial page load times.

30. Monitor website performance regularly: Continuously monitor your website's performance using tools like Google PageSpeed Insights, Pingdom, or GTmetrix. Identify areas that need improvement and work on fixing them to ensure optimal performance.
  •  

Rickweqw2bjf

1) Create a dedicated domain for static content.
2) Implement a load balancer for this domain, such as static.site.com -> 0.static.site.com, 1.static.site.com, and so on.

3) Adjust the configuration because using the nginx+php_fpm bundle is approximately 97% faster than using httpd+mod_php (unless there are specific dependencies on httpd).

4) When considering a VDS hosting provider, keep in mind that in most cases, Russian hosters oversell their resources. This means that (1) you might receive less than the promised CPU allocation and (2) the network may already be heavily congested due to other users, with hosts often providing only 100Mbps of network connectivity.

P.S. As an additional suggestion, consider moving to the cloud. For example, Joyent offers affordable small instances with the ability to easily scale up as needed. If you choose Joyent SmartOS, it will provide even more convenience. Additionally, Joyent provides a total shared port of 10Gbps, with the guaranteed speed determined by the share of resources from your purchased RAM. For instance, if you buy 1GB of instances, you will be allocated a theoretical network speed of 125Mbps (10Gbps/80*1). In real-life scenarios, you can expect speeds of up to 100Mbps. Furthermore, Joyent offers 20TB of premium traffic per month per instance.
  •  

Cydayslacle

In this scenario, I would eliminate php from the equation by following this approach (for instance):

1. To begin, you can establish symbolic links to all the necessary files within a specific directory using the ln -s command. These links should be named based on their respective IDs, as outlined in your img-links.txt file. It is vital to ensure that the link-to-file correspondence remains up-to-date, either manually or through automated means (e.g., a cron job). By doing so, there will be no need to invoke php for every request; instead, you can directly serve the files using httpd (be it Apache or Nginx).

2. In cases where the IDs do not possess extensions, it becomes necessary to register the file type within the corresponding table. Fortunately, this process is not overly complicated.

3. I echo the recommendation of configuring an expiration period for static content, ideally spanning several days (or even weeks).

Ultimately, this methodology should bring about faster request handling, potentially circumventing disk swaps and resolving the problem at hand. However, without precise knowledge of the hosting parameters and traffic conditions, it is challenging to make definitive statements.
  •  

Leachemep

Rewriting the proxy script in Perl or C++ might not significantly reduce the processor and memory load, as the overhead of creating a new PHP instance is the primary concern. However, using a more efficient language like Perl or C++ might provide some minor benefits. To implement the script more efficiently, consider using a caching mechanism, such as Memcached or Redis, to store frequently accessed images.
Additionally, optimizing the script for parallel processing using multi-threading or multi-processing techniques could improve performance.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...