Optimization news for WeChat applet's 10 request concurrency limit! ! !

不言
Release: 2018-12-14 11:23:46
forward
6917 people have browsed it

This article brings you optimization news about the 10 concurrent request limit of WeChat applet! ! ! It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

This may be cold news, so the title is more exciting.

Mini program concurrency limit has been around for a long time, from 5 concurrency when it was first released, to 10 concurrency later. If the number of requests issued at the same time exceeds this limit, it will be cruelly abandoned, which gave birth to Many developers have built "request queuing" wheels in their projects. However, in fact, this restriction was officially lifted by WeChat a year and a half ago.

Concurrency limit of 10 requests

Regarding the concurrency limit, the WeChat developer documentation says this:

Optimization news for WeChat applets 10 request concurrency limit! ! !

This restriction means that at the same time, the total number of concurrent wx.request, wx.uploadFile, and wx.downloadFile cannot exceed 10.

To this day, there are still many developers who abide by this rule.

Many people carefully maintain the number of requests when writing business. In order to control the number of requests, some parallel requests are specifically changed to serial, or a request queue is introduced to maintain mini program requests.

The effort these senior developers took to comply with this rule somewhat reflected their helplessness in the early years when they requested to be cruelly abandoned after the amount was exceeded.

Attached is the console error of the mini program basic library version 1.3.0:

Optimization news for WeChat applets 10 request concurrency limit! ! !

To this day, there are still developers discussing Methods to solve the concurrency limit of mini programs

Ignored messages

In fact, WeChat did this in the upgrade of the basic library to version 1.4.0 in July 2017 Optimization, requests that exceed the concurrency limit are queued, but many developers are not aware of this news.

Strictly speaking, this optimization does not completely lift the original concurrency restrictions. The current upper limit for processing requests at the same time is still 10, but requests beyond 10 will be queued. When a previous request is completed, the requests in the queue will be sent and processed in order. * Will not directly exceed 10 as before The request is discarded.

Attachment Mini Program Basic Library 1.4.0 update log (part):

Optimization news for WeChat applets 10 request concurrency limit! ! !

Now, we can finally ignore the request concurrency limit , happily sent the request. After all, all requests can be sent out, but the efficiency will be slower than no concurrency limit.

Correct posture for sending requests

As mentioned above, the WeChat applet adds queue processing for requests that exceed the concurrency limit in version 1.4.0 of the basic library Optimized, in versions below 1.4.0, requests that exceed the concurrent part will be discarded.

According to WeChat official data, as of December 2018, the proportion of users below version 1.4.0 was approximately 0.04%. Although currently small programs are rarely compatible with such a low version, it is suitable for some Small programs with special needs Also pay attention to the differences in basic libraries.

Another thing to note is the queuing mechanism of concurrent requests for mini programs. When there are more than 10 requests called at the same time, the applet will first initiate 10 concurrent requests, and the parts exceeding 10 will be queued in the order of calls. When the previous request is completed, the next request in the queue will be sent.

Attached is a 20 request concurrent test:

Optimization news for WeChat applets 10 request concurrency limit! ! !

Test results:

Optimization news for WeChat applets 10 request concurrency limit! ! !

As can be seen from the figure, the first 10 requests are sent at the same time, and the starting point of the subsequent request corresponds to the end point of a previous request, which can reflect the queuing behavior of the request.

This means that when there are many concurrent requests, you should prepare a queuing strategy and adjust the calling order according to the importance of the request and the response time. If you encounter a slow response to the request, you can consider doing timeout processing. , to avoid a lot of waiting and affect the user experience.

The above is the detailed content of Optimization news for WeChat applet's 10 request concurrency limit! ! !. For more information, please follow other related articles on the PHP Chinese website!

source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!