高性能 MySQL
译者序MySQL 最初是放在 LAMP 里一起讨论。
淘宝网最初使用 LAMP 架构,使用 MySQL 4.0。03 年底改用 IOE,从 08 年开始又筹划去 IOE。09 年的时候 MySQL 的架构也从垂直拆分改成水平拆分。2012 年 MySQL 的单库已经有了 6.5 万的 QPS。
本书是 mysqlperformanceblog.com 的几个专家(同样也是 percona 的创始人)的作品,对于 InnoDB/XtraDB 等存储引擎的性能优化和诊断方法有很深入和详细的介绍。
推荐序作者在性能优化领域工作多年,这本书诞生于 MySQL 还没有什么可扩展性和可测量性的时代,直到现在这些方面已经有了长足的进步。说到合理的方法,他们简直把这件事当成了科学,首先定义需要解决的问题,然后通过合理的猜测和精确的测量来解决问题。
性能优化 = 定义问题 + 猜测 + 测量
要关注:
吞吐量
响应时间
吞吐量 = 线程数/响应时间
追求新技能,如排队理论对性能的影响。
MySQL 的架构和历史MySQL 能够应用的场景:
嵌入到应用程序中
数据仓库
内容索引
部署软件
高可用的冗 ...
Spring IOC
总体的类图spring-Ioc
Bean 工厂提供 IOC 基本功能,Context 是全功能的 BeanFactory,是应用程序的全部上下文。
扩展点和生命周期钩子Spring的扩展点.xmind
加载顺序:
获取工厂
准备工厂
后处理工厂
InstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation,返回 object。
构造器
InstantiationAwareBeanPostProcessor.postProcessAfterInstantiation,返回布尔值。
populateBean(注入 @Autowired,类内第一个方法),实际上调用的是 InstantiationAwareBeanPostProcessor.postProcessProperties
InitializingBean:
各类 aware 方法注入
BeanPostProcessor.postProcessBeforeInitialization 的后处理器(@PostConsstruct)
afterPropertie ...
Spring 与数据库
Java 执行事务的过程
1.获取连接 Connection con = DriverManager.getConnection()2.开启事务con.setAutoCommit(true/false); 在 Spring 事务里(如 DataSourceTransactionManager 的 doBegin 方法)里,总是会显式地 con.setAutoCommit(false);(不然哪有事务可言)。3.执行CRUD4.提交事务/回滚事务 con.commit() / con.rollback();5.关闭连接 conn.close();
本文涉及到的类型的类图
Spring 的事务管理核心类型和流程DataSource不同的数据源诞生不同的 DataSource。默认的 TransactionManager 本身是期待一个名叫“datasource”的数据源的。
FactoryBean不同的 DataSource 装入不同的 FactoryBean,比如 JPA 的 EntityManagerFactory。
PlatformTransactionManager桥接模式的实 ...
软件方法
建模带来竞争优势。
前言
“唱曲的名家,唱到极快处,吐字依然干净利落”。
不能站在别人的肩膀上看得更远,只是摘抄别人的观点,无意义。要有足够的积累,和深度的思考。
涉众(stakeholder)往往会做而不会定义,把不同类型的涉众放在一起访谈时,只会剩下在场军衔最高那个人的意见。
需求变更的时候,要注意涉众利益角度分析。
项目的流程步骤:
寻找老大
揣摩愿景
业务建模
系统用例
需求规约
分析模型
设计开发
只有一个领域(核心域)的知识是系统能在市场上生存的理由。
拿来主义要摒除门户之见,不关注流派和风格,着力于细节和应用。
建模与 uml利润 = 需求 - 设计需求:提升销售设计:降低开发维护成本
几种弊习:
从需求直接映射设计,会得到大量的重复代码。
从设计出发来定义需求,会得到一堆假的“需求”。
从涉众视角对系统功能分包会得到需求包。子系统是基于内部视角根据系统部件的耦合和内聚情况进行切割。
需求
设计
卖的视角
做的视角
具体
抽象
产品当项目做
项目当产品做
设计源于需求,高于需求
建模工作流
业务建模:描述组织内部各系统如何写作 ...
FatJar 问题
什么是 FatJarFatJar 又叫 uber-jar。uber 不是打车的 uber,而是德语里面的 uber,意思是英语里面的 over-勉强可以翻译为超越。
FatJar 是一个 all-in-one 的 jar,它可以让部署和运行更加便利,它让最终部署和运行的环境不依赖于任何 maven 或者 lib 的 classpath。
FarJar 的三种具体类型非遮蔽的(Unshaded)依赖于maven-assembly-plugin。
12345678910111213141516171819<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>CHOOSE LATEST VERSION HERE</version> <configuration> <descriptorRefs ...
交易系统模型设计
交易系统.xmind
Spring 概览
Spring 起源于 2003 年,它作为 Java EE 平台规范的补充,而不是完全拥抱 specification。
Spring 可以指的是 entire family of projects。也可以单指 Spring Framework(换言之,Spring Framework 本身也只是 family 的一部分)。
Spring Framework 被模块化了,它的核心只包括 core container(主要解决依赖注入问题)。但是针对不同的应用架构,它提供不同的支持,包括 messaging、transactionl、persistence 和 web。这些模块原本命名为 “spring-core” 和 “spring-context”,在 Java 9 的 jigsaw 项目来临之时,也开始支持 module path,生成“自动模块名”清单项,并且定义语言级别的模块名,如”spring.core”、”spring.context”。
Spring 支持的 JSR 有:
Servlet API (JSR 340)
WebSocket API (JSR 356)
Con ...
Maven 全局配置文件settings.xml
xml 小知识
xmlns:xsi
xmlns:即为别名
12345678910<settings <!-- xml 名字空间 -->xmlns="http://maven.apache.org/SETTINGS/1.0.0"<!-- 该文件语法说明 使用了XMLSchema-instance -->xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<!-- schema 的位置 -->xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0http://maven.apache.org/xsd/settings-1.0.0.xsd"<!-- 使用了一个 xsd -->>
settings.xml 的功能settings.xml 是maven的全局配置文件。而pom.xml文件是所在项目的局部配置。Settings.xml中包含:
本地仓储位置
修 ...
Spark SQL 原理
Spark SQL的发展历程为了给熟悉的 RDBMS 但又不理解 MapReduce 的技术人员提供快速上手的工具,Hive 应运而生,他是当时唯一运行在 Hadoop 上的SQL-On-Hadoop 工具。 但是 MapReduce 计算过程中大量的中间磁盘落地过程消耗了大量的 I/O,降低的运行效率,为了提高 SQL 的执行效率,大量的 SQL-On-Hadoop工具开始产生,而 Shark 是其中一个表现较为突出的项目。
Shark是伯克利实验室 Spark 生态环境的组件之一,它主要修改了内存管理,物理计划和执行三个模块,值得它能运行在 Spark 的引擎上,从而提高 SQL 查询的效率。
但是随着 Spark 的发展,Shark 对 Hive 过多的依赖制约了 Spark 的设计理念和各个组件之间的相互继承,所以 Spark 团队停止了对 Shark 的开发,提出了 SparkSQL 项目。 因为摆脱了Hive 的过度依赖,Spark SQL在数据兼容性,性能优化和组件扩展等各个方面都得到了极大的方便和发展。
提出了 SparkSQL 项目之后,SQL On Spark 发展 ...
gradle 总结
gradle.xmind
基本概念gradle 是一个自动化构建工具(build automation,而不是像 maven 一样标榜自己是个 project management 工具),通过组织一系列 task 来最终完成自动化构建,所以 task 是 gradle 里最重要的概念之一, 以打包生成apk 为例,整个过程要经过资源的处理,javac 编译,dex 打包,apk 打包,签名等等步骤,每个步骤就对应到 gradle 里的一个 task。因为这些 task 是 gradle 的生命周期里特有的,所以 gradle 的插件应该不能移植到其他构建工具里。
每一个插件新增在 gradle 脚本里,都会带来新的 tasks。gradle 的 build 会触发很多的任务,包括但不限于构建和测试。我们常见的 build 文件夹就是 gradle 会频繁使用的东西。
gradle 可以使用 Groovy 或者 Kotlin DSL编写,这里我们涉及一个概念DSL ,DSL 也就是 Domain Specific Language 的简称,相对应的是 GPL (General-Pur ...