Welcome to Tencent cloud community, get more Tencent mass technology practice dry goods oh ~

Author: Huang Xitong, Tencent Cloud expert engineer

Since 2012, we have directed the 404 pages of various businesses in Tencent to the baby home, and since 2013, we have opened the 404 family access to third-party websites. These diversion has brought great pressure to the visit of Babyhomecoming forum, so we have migrated the forum server of Babyhomecoming to Tencent cloud to provide more stable services. A flash block for 4 years.

Volunteers who went to work on National Day and got baby home first said the website seemed a bit slow, then said it wouldn’t work. Log in the server to see the log, the traffic growth is a little fierce ah, suspected CC attack, opened a variety of protection, traffic is still high. Had to quickly open the elastic expansion, when the machine can not carry the rapid expansion of the past.

(Elastic scaling is one of the best friends of programmers and operations)

Then he asked the brothers of operation and security to help analyze the log, but could not find out what the result was. However, when he saw that the number of requests for profile pictures skyrocketed hundreds of times and occupied the majority of the log, he divided the requests for profile pictures and transferred them to CDN to relieve the pressure. However, CDN could not cache the case that the user did not set the profile picture (404), so it modified the server configuration to support “soft 404”, that is, when the profile picture cannot be found, the default profile picture is returned by the way of 200, avoiding 404.

After all this, traffic finally slowed down, and when we re-analyzed the log, we saw a ten-fold increase in traffic, almost all from Android phones. Then I suddenly remembered something. Before the National Day, there was a small internal group discussing the issue of directing the failed pages of the “QQ browser” to a family search project. At that time, I did not care, because according to baidu statistics, QQ browser in the domestic market share is less than 10%, it is estimated that the project should not bring too much traffic impact. Is it possible that at that time the discussion was not “QQ browser” but “X5 kernel”?

X5 is the core of Tencent’s mobile browser, which is widely used on Tencent’s Android apps such as wechat and QQ. Before returning to the National Day group inside a question, as expected accidentally attracted this big customer. How big is this customer? It is bigger than wechat and mobile QQ combined. If there is no accident, it is the largest in the country

It is good to have traffic, but the family search project is a public welfare project, so there is no such budget prepared in advance. Or from the technical solution, who let us be professional volunteers?

1. First check the problem of the abnormal surge of avatar traffic: why page views increase tens of times, avatar visits increase hundreds of times? After comparing and analyzing discuz’s mobile and PC pages, I quickly found out why: When opening a post on the Discuz forum, the profile pictures of all the commenters were displayed, so the number of page views of the profile picture should have been ten to dozens of times higher than the number of page views of the post. However, DisCUZ adopted optimization methods such as static link and lazy load for loading profile picture on PC terminal, which greatly reduced the page view of profile picture with protocol cache. However, these optimization methods were not made on mobile terminal.

To know why it is good to do, in the template/default/touch/forum/viewthread the HTM

<span class="avatar"><img src="<! --{if !$post['authorid'] || $post['anonymous']}--><! --{avatar(0, small, true)}--><! --{else}--><! --{avatar($post[authorid], small, true)}--><! --{/if}-->" style="width:32px; height:32px;" /></span>
Copy the code

Instead of

<span class="avatar" style=Zoom: "0.62"> <! - {if !$post['authorid'] | |$post['anonymous']} -- > <! --{avatar(0, small,false.false.true)} -- > <! - {else} -- > <! --{avatar($post[authorid], small, false.false.true)} -- > <! -- {/if} -- >Copy the code

Follow the PC side of the avatar link generation method. However, the head size of PC is larger than that of mobile, so we made a zoom.

But this did not slow down the server traffic… After the head picture is shunted comprehensively by CDN, the access ability of the post is released, and now the post of visiting the forum has become the main source of pressure.

Discuz forum posts can be made pseudo – static, but can not support true static. There are several reasons: if the visitor comes in with a login state, he should be given a personalized dynamic number. If a link is accessed from a PC, mobile phone, pad, or WAP terminal, the corresponding version should be returned. So Discuz relies on server caching rather than statics to carry the load.

However, an analysis of the user scene shows that there is a lot of room for optimization under the current situation: more than 90% of the users are users of other apps with X5 drainage, and the registered users are basically not forum users. The display device is android phone, so there is no need to consider the compatibility of various devices.

Therefore, we put the search page to an independent domain name 404.baobeihuijia.com, this domain name through CDN to cache through the forum posts, and use discuz pseudo-static link to achieve true static. For terminal compatibility, two things need to be done: a: modify the background PHP to always return the mobile phone version of the post in the case of identifying access through 404.baobeihuijia.com domain name b: monitor the user client on the page script of the static post. If the current user is not a mobile terminal, use the script to switch back to the original domain name bbs.baobeihuijia.com to provide dynamic services.

Having done this, the CDN takes most of the new pressure away: static

After optimization, the server load is still much heavier than before, but it can be carried by a single server

So what kind of server did the x5-resistant forum use?

Why is the configuration so low? Who call this Tencent cloud server so can carry ah ~~~

## Read recommendations

How to install SQL SERVER in Guardian Image?

Has been authorized by the author tencent cloud community released, reproduced please indicate the article source The original link: https://cloud.tencent.com/community/article/271724