Analysis of QBlog technical principles of the autumn color Park: Performance Optimization: user and article counter solution (17)

Source: Internet
Author: User
Tags database sharding

Summary in the previous section:

 

Previous sectionAnalysis of QBlog technical principles in the autumn color Garden: Performance Optimization: Concurrent limit of access and Distributed Concurrency solution of sub-databases (16) Medium,

This article introduces the maximum concurrency of Access and, to some extentQBlogThe maximum concurrency is increased from 64 to 64 * N (databases). Although the maximum concurrency is increased, however, the maximum value of a single database does not change, or the maximum concurrency value of a single table does not change. The maximum value is still 64.

Therefore, it is time to optimize access counters (User tables and article tables) that frequently generate update operations.

 

Summary:

 

This section describes QBlog On the user and article counters.

 

BenSection content:

 

Autumn GardenQBlogOriginal access counter policy:

1: obtain the number of counters in the cache. [User value cache, number on the document value Page]

2: Based on the Session or Cookie, each user can only perform one access within a certain period of time.

3: Memory count + 1 on the retrieved number.

4: The probability is directly updated to the user table and article table.

 

In this solution, the ldb problem of 4 K gold is determined by the traffic and Probability Problems. The lower the probability value, the safer the problem. However, if the memory is frequently recycled, the loss of numbers is also common.

 

AutumnColor GardenQBlogNew Access counter optimization policy:

1: The Memory counter + 1 is retained.

2: probabilistic update, unifiedBuilt-in threadScheduled Update.

In this way, the possible concurrency update problem of the original probability is now changed to one link being updated, effectively reducing the problem of the Golden 4 K.

3: to reduce the probability of loss, a new database (Qblogvisit. mdb) And data tables:

Two new tables are created:Blog_UserVisit and Blog_ContentHit.

New table fields:ID and Hits

The two tables in the new database increase the update frequency and are used to physically store user or article counters to avoid memory digital loss probability. When memory numbers are lost, first, extract the original number from the new table and then perform the plus 1 operation to effectively reduce the number loss problem.

 

PS: built-in threads: this is a dangerous thing. It will produce more than expected problems and require comprehensive processing possible: concurrency (when the application pool is recycled) multiple Threads and exceptions are generated.

 

Code for enabling the built-in thread:

 

Static page displays counter numbers dynamically

First: Autumn GardenQBlogMost of the pages are static *. html, but you will find that the counter of the article, whether it is the homepage, list, or article page, is changed. How to display static numbers and dynamic changes?

Is JavaScript asynchronous? No. Autumn GardenQBlogThe whole site has no js. If there is js, it should be another implementation method.

Then: Because URLRewrite does not directly turn to * when a request is encountered *. html, but all turn *. ashx, and then load *. html, so that the background program can perform secondary processing on the static html.

In fact, if you have read the articles in this series, you should find that the lifecycle of Page_OnCache is what you are doing here.

Therefore, you only need to obtain the number in the list, and then find the corresponding number from the memory. If yes, update the number.

Result: The number of the access counter is displayed dynamically.

 

Code for displaying dynamic numbers:

 

Summary

 

In this section, the counters that frequently generate database interactions are changed to single-threaded updates, effectively solving the golden 4 K problem.

At the same time, in order to reduce the probability of digital loss, a new database is added to physically store the number of the article, but the structure of the original table is not changed.

Result: At present, the problem is solved.

However, the problem of 4 K gold is not over, because, apart from the write operation, more is the read operation.

As mentioned in the previous section:

CYQ. Data uses Lock to Lock insertion, update, and deletion. These steps enable only one link at a time.

However, through the example in the previous section, we found that the link is to be opened for reading.

Therefore, the optimization has not been stopped, and this series is still in progress. Please stay tuned.

 

Review of historical articles:

1. Analysis of QBlog technology principles in the autumn Garden: Opening part: Overall understanding (1) -- introduces the role of the overall folder and file

2: Analysis of QBlog technical principles of the autumn color Garden: Understanding the whole site processing process (2)-introducing the business processing process of the autumn color Garden

3: Analysis of QBlog technical principles in the autumn color Park: UrlRewrite's principle of URL without a suffix (3) -- introduces how to implement URL without a suffix

4: Analysis of QBlog technical principles in the autumn Garden: URL redirection System of UrlRewrite (4) -- introduce how to locate the processing program in the URL

5. Technical Principles of QBlog in the autumn color Park: Module-based page base class design (5)-Introduction to creating base classes and custom lifecycles

6: Analysis of QBlog technology principles in the autumn Garden: Module Page Base-Lifecycle Process (6)-Introduction to internal services of the basic Lifecycle

7. Technical Principles of QBlog in the autumn Garden: Module-based lifecycle-page loading (7)-Introduction to html Loading Principles

8. Technical Principles of QBlog in the autumn Garden: webpage processing-content filling (8)-How to fill html content

9: Analysis of QBlog technology principles in the autumn Garden: unique multi-language translation mechanism (9)-Introduction to the principles of html multi-language translation

10: Analysis of Technical Principles of QBlog in the autumn Garden: demo of page content filling and multi-language translation process (10) -- Summary DEMO code

11: Analysis of QBlog technical principles in the autumn Garden: page Post Submission mechanism (11) -- Introduction if Post submits data

12: Analysis of QBlog technology principles in the autumn color Garden: Performance Optimization: byte and cache and concurrency (12)-Performance Optimization: byte, concurrency and Cache

13: Analysis of QBlog technology principles in the autumn Garden: Performance Optimization article: Global SQL statement optimization (13)-Introduce Global SQL and perform targeted Optimization

14. Technical Principles of QBlog in the autumn color Garden: Performance Optimization article: constructing a continuous cache solution when the cache is always ineffective (14th)-introducing the second cache Solution

15: Analysis of QBlog technology principles in the autumn color Garden: Performance Optimization article: Database articles table sharding and database sharding and decompression solutions (15th)-Introduction to content sharding and decompression

16: Analysis of QBlog technology principles in the autumn color Garden: Performance Optimization article: Concurrent limit of access and Distributed Concurrency solution for database sharding (16) -- Introduce the upper limit of access concurrency

Appendix:

1: Analysis of QBlog technical principles of the autumn color Garden: technical implementation of one-click blog Installation Tool [Download source code] -- Principle of the open source autumn color garden Installation Tool

2: how to install and deploy the CYQBlog site of the autumn Garden

3: how to install and deploy the CYQBlog site of the autumn Garden in Windows 7

 

PS:QBlog:Http://www.cyqdata.com/download/article-detail-427

 

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.