Javaweb development optimization

has done a personal blog project, the home page needs to show a lot of content, with the basic information of the website, a list of the latest blogs, personal introductions, latest comments, recommended articles, popular articles, popular article tags and so on. All of these need to query the database.
I use springmvc, when visiting the home page, first visit a Controller and then look up all this information through the database, and then put it into model and then display it, but I feel that this is too inefficient, showing a home page requires nearly 10 visits to the database. With Tencent Cloud 1m bandwidth of the server, access to the home page need to wait 5 seconds to display all the information, it is too slow, I would like to ask how to achieve this kind of home page? How do you access the database? How to optimize?

Mar.30,2021

it is recommended to test the access speed locally to clarify the problem:
1. If there are many bottlenecks in database access, it has nothing to do with 1m bandwidth. You can consider using ajax, where the main content is loaded first and the rest is loaded asynchronously.
2. If too many databases are returned, resulting in slow network transmission, it has something to do with bandwidth. At this time, paging queries are generally done to reduce the amount of data. In addition, gzip compression is started on the server, which will greatly reduce the network transmission volume.

theoretically, in a business action, accessing the database for 10 times is nothing. If a small amount of data is queried, the query processing time for a single database is generally tens of milliseconds, and the total time should be less than 1 second.

another idea is static processing, because blogs do not change frequently within the site, static pages can be generated when the content is published, and only generated static problems are displayed when users visit, so the speed is much faster.


for a server with Tencent Cloud's 1m bandwidth, you need to wait 5 seconds to access the home page to display all the information
In fact, the bandwidth of

1m is only 128kb. If more resources need to be loaded, it is natural to be slow

.
first visit a Controller and then look up all this information through the database

if you are confident, you can try to parallel these queries. It is safer for ajax, to decompose multiple queries into (partially) parallel multiple requests


there are two ways:
1. Second-level cache, when the server starts, load all these data into the cache, so that you don't have to send a request to the database every time;
2. Use ajax to load asynchronously on the page and use asynchronous concurrency to get server data.
this should be the easiest two ways to implement. If not, you can try it, or you can use both.


this kind of ajax request is better. Single-page routing


1: latest comments, recommended articles, popular articles, Tags, etc., are put into the cache (redis or ehcache cache, etc.), and it is not necessary to get them from the database every time.
2: the article list page can also be cached. Just make the cache update strategy.
3: the article details page can be statically processed, and the sidebar data can be obtained using ajax.
Resources such as 4:css and js use CDN, 's free CDN a lot.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b946-2c29f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b946-2c29f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?