PHP Control site concurrency

Source: Internet
Author: User

Generally speaking, a project will always have some difficult to deal with the business, such as business complex pattern of search, using search system such as sphinx,lucence, such as processing, if the data source changes too fast (such as top, step, browse number, etc.), the first time to push the data is more difficult to measure the frequency, In addition, you cannot search or sort accurately. So the general practice is to search through DB and, in addition to trying to break the business down to the program level, add a layer of cache in front of the db. But there are a number of known drawbacks to this:

1, in fact, a lot of business can not be put into ordinary PHP processing, such as some more complex sorting, screening, through the ordinary PHP to achieve the efficiency is not as good as MySQL.

2, the cache hit rate is not a good guarantee, especially for some use keywords to query the business, keyword changes too much.


If you encounter a malicious brush, the DB server is easy to hang up directly, so we can add a layer of limiter at the program level, limit the number of concurrent, the limiter has the following features:

1, high efficiency (nonsense, otherwise the direct brush limiter will be maxed out). Now is the atomic operation count using Memcache, which can be extended to use other methods.

2, accurate to the action layer. Individual pages can be restricted individually.

3, convenient. Let's go.

4, low cost. Including research and development costs and hardware costs.


According to the pressure measurement, originally only 100 concurrent search function, limit 100, pressure measurement 800 results normal.


Here's how to use it:


<?php

/**

* Search

*/

Public Function Search () {

Added counter function, more than the number of times to return to the system busy

$viewlimiter = Library::load (' Viewlimiter ');

The name of the access limiter, please use controller+action, try to keep a single page unique

$limitName = ' Search_search ';

Maximum number of simultaneous accesses

$limit = 100;

If the quantity exceeds the direct return

if (! $viewlimiter->check ($limitName, $limit)) {

Ajaxoutput (0, $this->lang->line (' Multi_search_limit '));

}


/*----complex and perverted business logic-----*/

$xxxModel->search ($params);

}

End Func

?>


PHP Control site concurrency

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.