业务型创业公司的技术发展

来到业务型创业公司将近一年半了,最初的激情过后,总有些淡淡的隐忧。创业成功毕竟是我们选择创业的目标,但是技术的衰减也是我们不希望看到的,无论是职业生涯还是技术生涯,Hoffman的ABZ理论,是一个毕竟好的指导准则,创业的Plan A如果失败了,我们技术的Plan B如何

Distributed systems for fun and profit读书笔记

这两天读了一个比较有意思的系列文章,Distributed systems for fun and profit,简单的做下读书笔记。

文章目的有二:

  • 梳理一些关键概念
  • 总结梳理分布式里的一些细节思想

在作者看来,分布式编程就是用来关注

  • 信息以光速传递
  • 不相干的个体不相关连的失败

换句话说,其核心就是处理distance,并且不止一个。希望读过该文章之后,能够对distance, time,consistency models三者之间的相互影响,有个比较感性的认识。

###Distributed systems at a high level

Distributed programming is the art of solving the same problem that you can solve on a single computer using multiple computers.

任何计算机系统,需要完成两个任务:

  • 存储 (Storage)
  • 计算 (Computation)

Cluster size

performance gap. 机器的增长带来的性能增长是非线性的

希望达到的目标:Scalability

is the ability of a system, network, or process, to handle a growing amount of work in a capable manner or its ability to be enlarged to accommodate that growth.

关注的三点:

  • Size scalability
  • Geographic scalability
  • Administrative scalability:

A scalable system is one that continues to meet the needs of its users as scale increases. There are two particularly relevant aspects - performance and availability - which can be measured in various ways.

一个扩展性很强的系统,就是可以持续的满足其用户的大规模增长。这里有两个特殊的相关概念,performance,availability,他们可以从多种方式来度量

Performance (and latency)

Performance is characterized by the amount of useful work accomplished by a computer system compared to the time and resources used.

体现在:

  • 低延迟 Short response time/low latency for a given piece of work
  • 高吞度 High throughput (rate of processing work)
  • 低资源利用率 Low utilization of computing resource(s)

Latency The state of being latent; delay, a period between the initiation of something and the occurrence.

Availability (and fault tolerance)

the proportion of time a system is in a functioning condition. If a user cannot access the system, it is said to be unavailable.

Availability = uptime / (uptime + downtime)

Availability % How much downtime is allowed per year?
90% (“one nine”) More than a month
99% (“two nines”) Less than 4 days
99.9% (“three nines”) Less than 9 hours
99.99% (“four nines”) Less than an hour
99.999% (“five nines”) ~ 5 minutes
99.9999% (“six nines”) ~ 31 seconds

高效使用Xcode[译]

翻译来源Supercharging Your Xcode Efficiency

You’ve all seen the all-star Hollywood programmer hacking through the mainframe, fingers racing on the keyboard while terminals fly across the screen. If you’ve ever wanted to be like that, you’re in the right place!
This tutorial will teach you how to be more like that programmer, in Xcode. Call it what you like — magic, mad skillz, pure luck or hacks, there is no doubt you’ll feel much cooler (and have improved Xcode efficiency) after following along this tutorial, and maybe even save the world from destruction with your newly found prowess.
你曾经在电影里看到一些伟大的黑客程序员操作大型机,手指扫过键盘,屏幕里的终端便飞驰而过,如果你也希望像他们那样,今天你来对地方了!

Learn some cool Xcode Tricks!

MySQL批量写入

MySQL批量写入,通常可以使用JDBCTemplate的batchUpdate

1
2
3
       public int [] batchUpdate (String sql, final BatchPreparedStatementSetter pss) throws DataAccessException {

}

使用后,针对批量操作,jdbc driver会render成批量语句发送给MySQL。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Log log = logs.get(i);
ps.setLong(1,log.getKeyid());
ps.setLong(2,log.getUserid());
ps.setLong(3,log.getPlanid());
ps.setLong(4,log.getUnitid());
ps.setLong(5,log.getLevel());
ps.setInt(6,log.getType());
}
@Override
public int getBatchSize() {
return logs.size();
}
});

今天一个线上case排查中发现,最终没有生效,SQL仍然是一条一条的发送出去,整体的性能下降明显。

查阅资料发现,原来MySQL默认是不支持batch的,jdbc driver虽然提供了batch接口,但是默认并没有开启,需要给JDBC Connection增加配置参数rewriteBatchedStatements=true,示例配置:

jdbc:mysql://10.10.10.38:5858?characterEncoding=gbk&rewriteBatchedStatements=true

PrepareStatement在执行executeBatch的时候,会对该参数进行判断,来进行批量操作。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public int[] executeBatch() throws SQLException {
synchronized (checkClosed().getConnectionMutex()) {

if (this.connection.isReadOnly()) {
throw new SQLException(Messages.getString("PreparedStatement.25") //$NON-NLS-1$
+ Messages.getString("PreparedStatement.26"), //$NON-NLS-1$
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}

if (this.batchedArgs == null || this.batchedArgs.size() == 0) {
return new int[0];
}

// we timeout the entire batch, not individual statements
int batchTimeout = this.timeoutInMillis;
this.timeoutInMillis = 0;

resetCancelledState();

try {
statementBegins();

clearWarnings();

if (!this.batchHasPlainStatements
&& this.connection.getRewriteBatchedStatements()) {


if (canRewriteAsMultiValueInsertAtSqlLevel()) {
return executeBatchedInserts(batchTimeout);
}

if (this.connection.versionMeetsMinimum(4, 1, 0)
&& !this.batchHasPlainStatements
&& this.batchedArgs != null
&& this.batchedArgs.size() > 3 /* cost of option setting rt-wise */) {
return executePreparedBatchAsMultiStatement(batchTimeout);
}
}

return executeBatchSerially(batchTimeout);
} finally {
this.statementExecuting.set(false);

clearBatch();
}
}
}

需要指出的时,该参数在JDBC 5.1.8开始才开始支持,5.1.17进行了优化,如果采用该机制,期望采用5.1.17+的版本。

搭建博客环境

今天在Mac下搭建了Hexo环境,先说说搭建环境方面的问题。

###环境准备


Mac环境下最好先安装homeblew,避免后续的各种麻烦,安装过程非常简单:

1
$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

然后用blew安装Node.js环境。

1
$ blew install node

接下来进行hexo的安装

1
$ npm install -g hexo

简单的等待后,一切就绪,然后可以进行相关目录,初始化博客目录。

1
2
3
$ hexo init github-blog
$ cd github-blog
$ npm install

接下来就可以对_config.yml等文件进行配置,进行博客撰写了。

###博客发布


配置github信息

deploy:
  type: github
  repository: https://github.com/home3k/home3k.github.io.git
  branch: master

接下来进行发布即可。

1
$ hexo deploy --generate

起步

有一段时间,经常会写写东西。不过,如梭带来了浮躁,浮躁带来的懒惰,慢慢地,文字就停了。

从今天开始,采用Markdown+hexo写自己的独立博客。之前的博客内容,也全部迁移过来。技术博客托管在Github上,生活博客托管在Gitcafe上。

希望自己能够坚持写下去,加油!

1
$ blog start