Happy Coding, Happy Life

解析微服务架构(一)

| Comments

[请勿转载]

单块架构系统以及其面临的挑战

概述

多年来,我们一直在技术的浪潮中乘风破浪,扬帆奋进,寻找更优秀的方法来构建IT系统,也一直在积极的学习并观察先进的公司如何以不同的架构方式构建或者优化其IT系统,来积极应对市场的变化,迅速做出响应,从而为客户提供更多的价值。

微服务架构模式(Microservice Architect Pattern)是近两年在软件架构模式领域里出现的一个新名词。虽然其诞生的时间不长,但其在各种演讲、文章、书籍上所出现的频率已经让很多人意识到它对软件领域所带来的影响。那到底什么是微服务,当我们谈论微服务时,它代表着一种什么样的含义?微服务适合应用在什么场景下,以及它有什么样的优缺点?微服务和SOA到底有没有区别?在接下来的几部分里,我将为大家揭开微服务的神秘面纱。

基于微服务架构,改造企业核心系统之实践

| Comments

本文已经发表于InfoQ,请参考这里

背景与挑战

随着公司国际化战略的推行以及本土业务的高速发展,后台支撑系统已经不堪重负。

在吞吐量、稳定性以及可扩展性上都无法满足日益增长的业务需求。对于每10万元额度的合同,从销售团队准备材料、与客户签单、递交给合同部门,再到合同生效大概需要3.5人天。随着业务量的快速增长,签订合同的成本急剧增加。

合同管理系统是后台支撑系统中重要的一部分。当前的合同系统是5年前使用.NET,基于SAGE CRM二次开发的产品。 一方面,系统架构过于陈旧,性能、可靠性无法满足现有的需求。另一方面,功能繁杂,结构混乱,定制的代码与SAGE CRM系统耦合度极高。

由于是遗留系统,熟悉该代码的人早已离职多时,新团队对其望而却步,只能做些周边的修补工作。同时,还要承担着边补测试,边整理逻辑的工作。

在无法中断业务处理的情况下,为了解决当前面临的问题,团队制定了如下的策略:

  1. 在现有合同管理系统的外围,构建功能服务接口,将系统核心的功能分离出来。
  2. 利用这些功能服务接口作为代理,解耦原合同系统与其调用者之间的依赖;
  3. 通过不断构建功能服务接口,逐渐将原有系统分解成多个独立的服务。
  4. 摒弃原有的合同管理系统,使用全新构建的(微)服务接口替代。

Java 8 - First Impression of Lambda Expression

| Comments

One of the most prominent and widely used languages in the world has Evolved.

Java ever gave us power on object oriented progrmming and we did the best we could with it.

Now there’s another new elegant way changing the java world-Lambda Expression, that will make our code more expressive, easier to write, less error prone, and easier to parallelize than has been the case with Java.

Lambda Expression

Let’s start from a simple example:

Suppose we’re asked to total the prices greater than $20, discounted by 10%. Let’s do that in the habitual Java way first.

Old way

1
2
3
4
5
6
7
8
9
10
11
final List<BigDecimal> prices = Arrays.asList(
  new BigDecimal("10"), new BigDecimal("30"), new BigDecimal("17"), 
  new BigDecimal("20"), new BigDecimal("15"), new BigDecimal("18"), 
  new BigDecimal("45"), new BigDecimal("12"));

  BigDecimal totalOfDiscountedPrices = BigDecimal.ZERO;   
  for(BigDecimal price : prices) { 
          if(price.compareTo(BigDecimal.valueOf(20)) > 0)
                  totalOfDiscountedPrices = totalOfDiscountedPrices.add(price.multiply(BigDecimal.valueOf(0.9)));
              }
      System.out.println("Total of discounted prices: " + totalOfDiscountedPrices);

A Better way

Now we can do better, a lot better. Our code can resemble the requirement specification. This will help reduce the gap between the business needs and the code that implements it, further reducing the chances of the requirements being misinterpreted.

1
2
3
4
5
6
7
final BigDecimal totalOfDiscountedPrices = 
prices.stream()
  .filter(price -> price.compareTo(BigDecimal.valueOf(20)) > 0)
  .map(price -> price.multiply(BigDecimal.valueOf(0.9)))
  .reduce(BigDecimal.ZERO, BigDecimal::add);
  
System.out.println("Total of discounted prices: " + totalOfDiscountedPrices);

Instead of explicitly iterating through the prices list, we’re using a few special methods:

  • Using filter() to get the record we are interested
  • Using map() to transfer to another result set
  • Using reduce() to compute the total on the result

Summary

It’s a whole new world in Java. We can now program in an elegant and fluent functional style, with higher-order functions. This can lead to concise code that has fewer errors and is easier to understand, maintain, and parallelize.

Asgard - Handy Tool for AWS Management & Deployment

| Comments

Asgard is named for the home of the Norse god of thunder and lightning. As the words described, it is closely relevant to the management and control in cloud.

Netflix build a tool named Asgard, which is used to control and manage their AWS cloud. In 2012, Netflix announced that Asgard was open-sourced.

Then…… it is time to start the story.

What is Asgard

Asgard is a web-based tool for managing cloud-based applications and infrastructure.

  • Built on the top of grails.
  • By introducing Application and Cluster terminology, enable users understand their cloud objets clearly.
  • Keep track cloud objects from the view of one application

Splunk - Receive Logs From Distributed Windows Machine

| Comments

Why do I need Splunk

Recently, our team is moving several legacy components running in Windows server from data-center to AWS. The transformation itself is not hard, but the eco-system like monitoring, alerting, troubleshooting is most important before getting started the transofrmation.

The article would talk about how to setup and config Splunk Universal Forwarder in Windows machine where the component is running.

Bying using SUF, Splunk central server can easily collect logs from different distributed machines, so that the OPS guy can query and analyze the logs from one portal rather than login on different distributed machines.

How to Setup Mongo Shard

| Comments

To simulate the process of production deployment of MongoDB, I used Vagrant to create a couples of VMs, and exprienced the journey of deployment mongo step by step as follow mentioned.

Mongo Shard Concepts

Before dived into the code, we can review the concepts related to Mongo Shard, it needs 3 components logically at least.

a) Config Server

The config server processes are mongod instances that store the cluster’s metadata. You designate a mongod as a config server using the –configsvr option. Each config server stores a complete copy of the cluster’s metadata.

b) Query Server

The query server are lightweight mongos instances and do not require data directories. You can run a mongos instance on a system that runs other cluster components, such as on an application server or a server running a mongod process. By default, a mongos instance runs on port 27017.

How to Setup Mongo repliSet

| Comments

Create one mongo repliSet

mkdir -p /srv/mongodb/rs0-0 /srv/mongodb/rs0-1 /srv/mongodb/rs0-2

Run instances

mongod --port 27017 --dbpath /srv/mongodb/rs0-0 --replSet rs0 --smallfiles --oplogSize 128
mongod --port 27018 --dbpath /srv/mongodb/rs0-1 --replSet rs0 --smallfiles --oplogSize 128
mongod --port 27019 --dbpath /srv/mongodb/rs0-2 --replSet rs0 --smallfiles --oplogSize 128

Enable replicaSet

mongo --port 27017
rs.initiate()
rs.conf()
rs.status()

Dora诞生记

| Comments

趁着在墨尔本和西安Office上Hackday获奖的喜悦劲,赶紧来一篇Dora诞生记。
提醒偶记住这个特殊的日子,同时也感谢在过去两个月,牺牲个人时间,奋斗在Dora(X-Robot)上的Casa的兄弟姐妹们。

-2013年10月20

和Charley午餐的时候,无意间谈论起了各自想做但没时间做的idea。

幸运乎,找到一个我俩都认为不错但又没被完全实现的一个想法<<公交来了>>(旨在帮助等车族们准确的掌握公交将来的时间,为既不想迟到又想多赖几分钟在床上的兄弟提供福音)。

WebRTC - Understand the PeerConnection

| Comments

在上篇文章里,我们已经了解了MediaStream。那么这篇文章里,我们就来重点了解RTCPeerConnection。

RTCPeerConnection表示浏览器之间点对点的连接。只有当连接建立后,浏览器的两端才能真正完成流媒体数据的传输。

还记得之前讨论过的WebRTC架构图吗? 实际上,虽然RTCPeerConnection是一个暴露的连接接口, 但其内部封装了大量WebRTC编解码和协议处理的工作,因此使浏览器之间点到点的即时通讯变得简单。

WebRTC - Understand the MediaStream

| Comments

WebRTC从设计之初,目的就是为开发人员提供更加简便的方式构建基于Web的视频、音频应用。对于任何的WebRTC应用程序,只需要做如下几件事情:

  • 1)获取本地媒体流(音频、视频)。
  • 2)与对端建立连接(包括防火墙和NAT的穿透)。
  • 3)初始化双方通信信道。
  • 4)交换通信元数据信息,比如分辨率、编解码方案、网络地址等。
  • 5)开始音频,视频或数据的通信。