Many users, does not represent your server traffic, traffic is not necessarily your server pressure! Let’s switch to a more professional question: how to optimize the server to avoid excessive server stress under high concurrency?
1, the whole architecture: the distributed architecture can be adopted, and the micro-service architecture can be used to split the service deployment in different service nodes to avoid the service unavailability caused by the failure of a single node!
2, database: the use of master-slave replication, read and write separation, and even sub-database sub-table, table data according to the different query methods using different indexes such as B tree, hash, key field index, SQL avoid compound function, avoid combination of sorting, avoid the use of non-index fields as conditional grouping, sorting and so on! Reduce the number of interactions and definitely don’t use SELECT *!
3, add cache: use such as memcache, Redis, EhCache and other cache database definition table, result table and so on, the middle data of the database slow down storage, avoid multiple access to modify table data! Login information session and other slow storage to achieve sharing! Such as commodity classification, province, age classification and other data that do not often change, slow down storage, do not put database!
Also avoid cache avalanches and penetrations that cause cache crashes!
4, incremental statistics: do not real-time statistics of a large number of data, should be used in the evening scheduled task statistics, incremental statistics and other ways to advance statistics, to avoid real-time statistics of memory, CPU pressure!
5, plus picture server: pictures and other large files, must go through the file server alone, to avoid IO speed on dynamic data! Ensure that the system does not crash because of files!
6, HTML files, enumeration, static method return value and other static processing, into the cache!
7, load balancing: the use of Nginx and other large access to the service load balancing, service cluster, improve the maximum number of concurrent services, to prevent excessive pressure to lead to the collapse of a single service!
8, join the search engine: for SQL often appear like, in and other statements, the use of Lucence or Solr middleware, the necessary, rely on fuzzy search fields and data use the search engine for storage, improve the search speed! # Note: Full data and incremental data for scheduled task updates!
9, use messaging middleware: For data transfer between services, use distributed message queues such as Rabbit MQ, Kafka, etc., asynchronous transmission to prevent synchronous transmission of data blocking and data loss!
10, abandon Tomcat: do Web development, contact with the earliest application server is Tomcat, but the single maximum concurrency of Tomcat is less than 1W! Take netty and other actor model of high performance application server!
11, multi-threading: now the server is multi-core processing mode, if the code uses a single thread, synchronous processing, a great waste of CPU efficiency and execution time!
12. Avoid blocking: Avoid bio, BlockingQueue and other technologies that often cause long blocking, and replace them with asynchronous processing mechanisms such as NIO!
13, CDN acceleration: if the traffic volume is too large, according to the source of the request to use CDN shunt technology, to avoid large traffic to complete the system crash!
Avoid inefficient code: don’t create objects too often, references, use fewer synchronous locks, don’t create lots of threads, and don’t multilayer for loops!
Of course there are more detailed optimization techniques!
, end,
— Writing is not easy, your forwarding is the biggest support for me —
Click on the menu “wechat group” to join the group and communicate with your partners!