实践MySQL主从复制(Master-Slave)的操作流程!

对于发展很小的公司来说,单台服务器支撑整个公司的运转是常见的事情。但是随着用户量的增加,随之而来的数据量也会跟着增加,这就导致更多地用户会使用查询select我们的数据库,从而导致性能急剧的下降。例如,查询缓慢,用户等待时间长等等,高并发,大数据,负载均衡甚至是集群,这些方案都是小公司不会采用的,一方面成本极高,需要运维维护,这已经抵n个程序猿的工资了,所以一般不会采用这种模式。

仔细的分析一下,这种情况,其实更多地是来源于数据库mysql的承受能力变大,一方面需要读操作,另一方面有需要增删改操作,那么多人同时请求肯定受不了啦!
有人说使用缓存,但是再想想mysql的缓存是有限制的,并不是一味的去缓存就可以,又有人说使用redis缓存,存储在内存中,然而事实上运转的时候redis缓存并不能全部给你缓存,有些数据需要实时的查看,而且redis缓存过多,导致cpu直接上涨,严重的话,机器直接运转停止。

Read more

Slick 3 代码生成实战

Slick的全称是"Scala Language-Integrated Connection Kit",它是类型安全的函数式关系型映射库,简称FRM - Functional Relational Mapping。专门用于Scala对关系型数据库的操作。它带来了函数式语言的便利性,可以通过Scala的丰富集合对数据库转换。Slick适用基于PlayAkka 框架的功能实现。

Slick底层实现了DBIO的响应式设计,它是一个Reactive Stream的实现,因此有一下一些特性:

  • Clean separation of I/O and CPU-intensive code: Isolating I/O allows you to keep your main thread pool busy with CPU-intensive parts of the application while waiting for I/O in the background.
  • Resilience under load(负荷回弹): When a database cannot keep up with the load of your application, Slick will not create more and more threads (thus making the situation worse) or lock out all kinds of I/O. Back-pressure is controlled efficiently through a queue (of configurable size) for database I/O actions, allowing a certain number of requests to build up with very little resource usage and failing immediately once this limit has been reached.
  • Reactive Streams for asynchronous streaming.
  • Efficient utilization of database resources: Slick can be tuned easily and precisely for the parallelism (number of concurrent active jobs) and resource ussage (number of currently suspended database sessions) of your database server.
Read more

Type_Level Programming in Scala

最近在研究的Shapeless框架,需要我们从新认识Scala的类型系统编程,另外Scala的宏编译也是我们需要关注的部分。

动机,混合集合类型(Heterogeneous collection types, HList, Harray)。

1
2
3
val l1 = 42 :: "foo" :: Some(1.0) :: "bar" :: HNil
val i: Int = l1.head
val s: String = l1.tail.head
Read more

Gentoo+Gnome+Systemd 安装记录

Gentoo Linux(发音为/ˈdʒɛntuː/)是一种Linux操作系统,基于Portage包管理系统,而拥有几乎无限制的适应性特性,被官方称作元发行版(meta-distribution)[2],支持多达10种以上的计算机系统结构平台。此项目和它的产品以巴布亚企鹅命名。Gentoo包管理系统的设计是模块化、可移植、易维护、灵活以及针对用户机器优化的。软件包从源代码构建,这延续了ports的传统。但是为了方便,也提供一些大型软件包在多种架构的预编译二进制文件,用户亦可自建或使用第三方二进制包镜像来直接安装二进制包。

Read more