Here

MySQL 快速删除大量数据(千万级别)的几种实践方案——附源码

北城余情 提交于 2020-08-09 17:18:33
笔者最近工作中遇见一个性能瓶颈问题,MySQL表,每天大概新增776万条记录,存储周期为7天,超过7天的数据需要在新增记录前老化。连续运行9天以后,删除一天的数据大概需要3个半小时(环境:128G, 32核,4T硬盘),而这是不能接受的。当然如果要整个表删除,毋庸置疑用 TRUNCATE TABLE 就好。 最初的方案(因为未预料到删除会如此慢),代码如下(最简单和朴素的方法): delete from table_name where cnt_date <= target_date 后经过研究,最终实现了飞一般(1秒左右)的速度删除770多万条数据,单张表总数据量在4600万上下,优化过程的方案层层递进,详细记录如下: 批量删除(每次限定一定数量),然后循环删除直到全部数据删除完毕;同时 key_buffer_size 由默认的8M提高到512M 运行效果: 删除时间大概从3个半小时提高到了3小时 (1)通过 limit (具体size 请酌情设置) 限制一次删除的数据量,然后判断数据是否删除完,附源码如下(Python实现): def delete_expired_data(mysqlconn, day): mysqlcur = mysqlconn.cursor() delete_sql = " DELETE from table_name where cnt_date<='

分布式图数据库 Nebula Graph 的 Index 实践

ぃ、小莉子 提交于 2020-08-09 14:38:17
导读 索引是数据库系统中不可或缺的一个功能,数据库索引好比是书的目录,能加快数据库的查询速度,其实质是数据库管理系统中一个排序的数据结构。不同的数据库系统有不同的排序结构,目前常见的索引实现类型如 B-Tree index、B+-Tree index、B*-Tree index、Hash index、Bitmap index、Inverted index 等等,各种索引类型都有各自的排序算法。 虽然索引可以带来更高的查询性能,但是也存在一些缺点,例如: 创建索引和维护索引要耗费额外的时间,往往是随着数据量的增加而维护成本增大 索引需要占用物理空间 在对数据进行增删改的操作时需要耗费更多的时间,因为索引也要进行同步的维护 Nebula Graph 作为一个高性能的分布式图数据库,对于属性值的高性能查询,同样也实现了索引功能。本文将对 Nebula Graph的索引功能做一个详细介绍。 图数据库 Nebula Graph 术语 开始之前,这里罗列一些可能会使用到的图数据库和 Nebula Graph 专有术语: Tag:点的属性结构,一个 Vertex 可以附加多种 tag,以 TagID 标识。(如果类比 SQL,可以理解为一张点表) Edge:类似于 Tag,EdgeType 是边上的属性结构,以 EdgeType 标识。(如果类比 SQL,可以理解为一张边表) Property

聊聊dubbo-go的metricsFilter

情到浓时终转凉″ 提交于 2020-08-09 13:28:07
序 本文主要研究一下dubbo-go的metricsFilter metricsFilter dubbo-go-v1.4.2/filter/filter_impl/metrics_filter.go const ( metricFilterName = "metrics" ) var ( metricFilterInstance filter.Filter ) // must initialized before using the filter and after loading configuration func init() { extension.SetFilter(metricFilterName, newMetricsFilter) } // metricFilter will calculate the invocation's duration and the report to the reporters // If you want to use this filter to collect the metrics, // Adding this into your configuration file, like: // filter: "metrics" // metrics: // reporter: // - "your reporter" #

为什么文本文件以换行符结尾?

拥有回忆 提交于 2020-08-09 12:44:07
问题: I assume everyone here is familiar with the adage that all text files should end with a newline. 我假设这里的每个人都熟悉所有文本文件应以换行符结尾的格言。 I've known of this "rule" for years but I've always wondered — why? 多年来我一直都知道这个“规则”,但我一直在想 - 为什么? 解决方案: 参考一: https://stackoom.com/question/33pE/为什么文本文件以换行符结尾 参考二: https://oldbug.net/q/33pE/Why-should-text-files-end-with-a-newline 来源: oschina 链接: https://my.oschina.net/u/3797416/blog/4306265

mha 搭建 及注意事项

妖精的绣舞 提交于 2020-08-09 11:05:54
简介: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开发,是一套优秀的作为MySQL高可用性环境下故障切换和主从提升的高可用软件。在MySQL故障切换过程中,MHA能做到在0~30秒之内自动完成数据库的故障切换操作,并且在进行故障切换的过程中,MHA能在最大程度上保证数据的一致性,以达到真正意义上的高可用。 该软件由两部分组成:MHA Manager(管理节点)和MHA Node(数据节点) 。MHA Manager可以单独部署在一台独立的机器上管理多个master-slave集群,也可以部署在一台slave节点上。MHA Node运行在每台MySQL服务器上,MHA Manager会定时探测集群中的master节点,当master出现故障时,它可以自动将最新数据的slave提升为新的master,然后将所有其他的slave重新指向新的master。整个故障转移过程对应用程序完全透明。 在MHA自动故障切换过程中,MHA试图从宕机的主服务器上保存二进制日志,最大程度的保证数据的不丢失,但这并不总是可行的。例如,如果主服务器硬件故障或无法通过ssh访问,MHA没法保存二进制日志,只进行故障转移而丢失了最新的数据。使用MySQL 5.5的半同步复制

2017年12月六级翻译青海湖

末鹿安然 提交于 2020-08-09 10:42:41
青海湖位于海波3205米,青海省省会西宁以西约100公里处。 Qinghai Lake is located at an height above sea level of 3205 meters 青海省省会西宁以西约100公里处。 about 100 kilometers west of Xining, the capital of Qinghai Province. 是中国最大的咸水湖。 It is the largest saltwater lake in China 面积4317平方公里,最深处25.5米。 It covers an area of 4317 square kilometers, with a maximum depth of 25.5 meters。 有23条河注入湖中,其中大部分是季节性的。 There are 23 rivers flowing into the lake, most of which are seasonal. 百分之八十的湖水源于五条的主要河流。 Eighty percent of the lake's water comes from five major rivers 青海湖位于跨越亚洲的几条候鸟迁移路线的交叉处。 Qinghai Lake is located at the intersection of several

Python错误 SyntaxWarning: name &apos;xxx&apos; is assigned to before global declaration

假装没事ソ 提交于 2020-08-09 07:10:00
The most common reason for this error is that you’re using multiple global declarations in the same function. Consider this example: x = 0 def func(a, b, c): if a == b: global x x = 10 elif b == c: global x x = 20 If you run this in a recent version of Python, the compiler will issue a SyntaxWarning pointing to the beginning of the func function. Here’s the right way to write this: x = 0 def func(a, b, c): global x # <- here if a == b: x = 10 elif b == c: x = 20 来源: oschina 链接: https://my.oschina.net/u/4259099/blog/4462810

如何使方法返回类型通用?

。_饼干妹妹 提交于 2020-08-09 06:48:47
问题: Consider this example (typical in OOP books): 考虑以下示例(OOP书籍中的典型示例): I have an Animal class, where each Animal can have many friends. 我有一个 Animal 课,每个 Animal 可以有很多朋友。 And subclasses like Dog , Duck , Mouse etc which add specific behavior like bark() , quack() etc. 还有子类,如 Dog , Duck , Mouse 等,它们添加了特定的行为,如 bark() , quack() 等。 Here's the Animal class: 这是 Animal 类: public class Animal { private Map<String,Animal> friends = new HashMap<>(); public void addFriend(String name, Animal animal){ friends.put(name,animal); } public Animal callFriend(String name){ return friends.get(name); } } And here's

偏移html锚以调整为固定的标头[重复]

北城余情 提交于 2020-08-08 19:25:21
问题: This question already has an answer here: 这个问题已经在这里有了答案: Fixed page header overlaps in-page anchors 32 answers 固定页面标题与页面内定位点重叠 32个答案 I am trying to clean up the way my anchors work. 我正在尝试清理锚点的工作方式。 I have a header that is fixed to the top of the page, so when you link to an anchor elsewhere in the page, the page jumps so the anchor is at the top of the page, leaving the content behind the fixed header (I hope that makes sense). 我有一个固定在页面顶部的标题,因此当您链接到页面其他位置的锚点时,页面会跳转,因此该锚点位于页面顶部,而将内容留在固定的标题后面(我希望那讲得通)。 I need a way to offset the anchor by the 25px from the height of the header.

如何在.NET(特别是C#)中对对象进行深层复制? [重复]

风格不统一 提交于 2020-08-08 19:01:43
问题: This question already has answers here : 这个问题已经在这里有了答案 : Deep cloning objects (45 answers) 深度克隆对象 (45个答案) Closed 5 years ago . 5年前 关闭。 I want a true deep copy. 我想要一个真正的深复制。 In Java, this was easy, but how do you do it in C#? 在Java中,这很容易,但是如何在C#中实现呢? 解决方案: 参考一: https://stackoom.com/question/Xev/如何在-NET-特别是C-中对对象进行深层复制-重复 参考二: https://oldbug.net/q/Xev/How-do-you-do-a-deep-copy-of-an-object-in-NET-C-specifically-duplicate 来源: oschina 链接: https://my.oschina.net/stackoom/blog/4282712