MySQL百万级高并发网站实战攻略_MySQL
在一开始接触PHP接触MYSQL的时候就听不少人说:“MySQL就跑跑一天几十万IP的小站还可以,要是几百万IP就不行了”,原话不记得了,大体就是这个意思。一直也没有好的机会去验证这个说法,一是从没有接手过这么大流量的网站,二是平时工作也比较忙,懒得去管这些,反正现在用不着,抱着这个想法把这个问题一直留到了最近,才把这个问题搞明白。
就在前几天公司旗下一网站(由于这是公司的商业内容我就不说是那个网站了)以下简称A站,这A站在年后流量猛增从一天的七八十万猛跑到了好几百万的IP,一天下来接近一千万的PV让整个服务器在高压下超负荷的工作着,时不时的服务就出现宕机。
最首先反映出情况的是数据统计,一天下来一个数据也没有统计上,原来是MySQL停止工作了。
本文就围绕这个问题来讲讲我们公司几个技术人员的解决方案。
1. MySQL服务器集群
由于是小公司在资金和成本上都有所限制,而且在技术上也没有几个技术员接触过,所以这个方法自然就让大伙否决了。
这里说说我个人的理解!做集群不但添加资费的开销,而且在技术上也有很大的挑战,对于我们公司目前的情况是不大现实的。集群无非就是把一台服务器的压力转接到两台或是多台服务器上,我是这么理解的,也许我理解有误,还请大家指教。
2. 分而治之
这个方法和集群差不多,不过是把统计的代码放在不同的服务器上跑,由于公司有不少配置低的服务器跑几万到几十万IP还是没有问题的,我们可以把几百万流量分成十来个几十万的量分而统计。
优点:充分的利用了现在的资源,解决了目前的问题。
缺点:这样的方法不是长久之计,迟早还是会出问题的。而且在统计数据的时候比较麻烦。
3. 统计代码的修改
由于之前采用的是在插入数据之前加以判断,这个IP是否存在,来路等的处理,无形中增加了服务器的压力,所以大伙把统计代码改成来一个就插入数据库,不管三七二十一等以后在处理。
这个方法基本上把当天的数据保留下来了,可是在处理的时候由于数据量的庞大,来来回回还是把服务器跑死了,而且在插入的时候由于当时设计数据结构的时候留有的索引,也大大的消耗了不少的服务器资源。
那么把索引去掉到最后处理的时候又是老慢的,得不偿失。
4. 统计方式的修改
最后这一个方法,效果非常的明显。那是什么方法呢!
这里就主要介绍这个方法:
A、 保留原用的数据结构不变,并把所有的数据按一定的结构存入文件
结构:可以是xml,json,也可以是你自己想的任何有规律的数据排放。
例如:
1 221.2.70.52,http://www.baidu.com,windowxprn
2 221.2.70.52,http://www.baidu.com,windowxprn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Websites for learning C language: 1. C Language Chinese Website; 2. Rookie Tutorial; 3. C Language Forum; 4. C Language Empire; 5. Script House; 6. Tianji.com; 7. Red and Black Alliance; 8, 51 Self-study network; 9. Likou; 10. C Programming. Detailed introduction: 1. C language Chinese website, which is a website dedicated to providing C language learning materials for beginners. It is rich in content, including basic grammar, pointers, arrays, functions, structures and other modules; 2. Rookie tutorials, This is a comprehensive programming learning website and more.

Do you frequently visit the same website at about the same time every day? This can lead to spending a lot of time with multiple browser tabs open and cluttering the browser while performing daily tasks. Well, how about opening it without having to launch the browser manually? It's very simple and doesn't require you to download any third-party apps, as shown below. How do I set up Task Scheduler to open a website? Press the key, type Task Scheduler in the search box, and then click Open. Windows On the right sidebar, click on the Create Basic Task option. In the Name field, enter the name of the website you want to open and click Next. Next, under Triggers, click Time Frequency and click Next. Select how long you want the event to repeat and click Next. Select enable

In macOS Sonoma and Safari 17, you can turn websites into "web apps," which can sit in your Mac's dock and be accessed like any other app without opening a browser. Read on to learn how it works. Thanks to a new option in Apple's Safari browser, it's now possible to turn any website on the internet you frequently visit into a standalone "web app" that lives in your Mac's dock and is ready for you to access at any time. The web app works with Mission Control and Stage Manager like any app, and can also be opened via Launchpad or SpotlightSearch. How to turn any website into

Sometimes, we want to block certain websites on Microsoft Edge for many reasons, whether it is for parental control, time management, content filtering, or even security concerns. A common motivation is to be more productive and stay focused. By blocking distracting websites, people can create a conducive environment for working or studying, minimizing potential distractions. Finally, content filtering is important to maintaining a safe and respectful online environment. Blocking websites that contain explicit, offensive or objectionable content is particularly important in educational or professional settings where upholding appropriate standards and values is crucial. If you can relate to this situation, this article is for you. Here’s how to block access to the Internet in Edge

By default, most iPhone users use Safari browser on their iPhone. They browse and visit different types of websites on Safari browser. Some iPhone users have reported that they are tired of seeing frequently visited websites on the splash screen after launching Safari on their iPhone. In order to change the appearance of the splash screen, you should edit it. If you wish to remove frequently visited websites from Safari, we are here with some simple steps explaining how to do it easily. How to Delete Frequently Visited Websites from Safari on iPhone Step 1: You should first launch the Safari browser on your iPhone. 2nd

To solve the problem of Python website access speed, use database optimization methods such as indexing and caching. In the process of developing and maintaining Python websites, we often encounter the problem of slow website access speed. In order to improve the response speed of the website, we can use some database optimization methods, such as indexing and caching. This article will introduce how to use these methods to solve Python website access speed problems, and provide corresponding code examples for reference. 1. Use indexes to optimize database queries. Indexes are a fast search structure for data in the database, which can greatly

PHP website: 1. Facebook, one of the largest social media platforms in the world; 2. WordPress, an open source content management system for quickly creating and managing various types of websites; 3. Magento, a powerful e-commerce platform , used to create and manage online stores; 4. Joomla, a popular open source content management system used to build various types of websites; 5. Wikipedia, a free online encyclopedia that provides knowledge and information on various topics; 6. Digg, social news sites and more.

Methods to check dead links on a website include using online link tools, using webmaster tools, using robots.txt files, and using browser developer tools. Detailed introduction: 1. Use online link tools. There are many online dead link detection tools, such as LinkDeath, LinkDefender and Xenu. These tools can automatically detect dead links in the website; 2. Use webmaster tools. Most webmasters Tools, such as Google's Webmaster Tools, Baidu's Webmaster Tools, etc., all provide dead link detection functions and so on.
