Online提高了信息流、资金流、物流的效率,消除了信息不对称,提高了交易的效率,提高用户的消费体验和感受

商业/贸易
贩卖优质产品,让顾客体验出色服务

  • Offline to Online
  • Online to Offline : baidu, Tecent, JD, Alibaba,
  • 融合
    在移动互联网时代,线上线下相互融合,提升消费的新商业模式
    线上的便利性与线下的体验功能融合

example:
出境服务的APP“四万公里”: 创始人仇志强说,他们本来是想做一个交易平台,但思考过后决定从工具入手。最初的办法就是通过“最笨”的人力“扫街”,把国外城市的餐馆收录起来,再从各社交网站扫点评。就这样,他们现在拥有近300万POI、1700多万图片、过亿条点评,已经具备一个海外版“大众点评”的雏形。和大众点评相比,后者不可能在海外放太多资源,因为美团和糯米在一边盯着呢。和携程去哪儿相比,他们要靠出境产品或机酒赚钱,不会刻意去盯吃或玩的单品。

顾客细分

老年人: 养老问题? 痛点?

Idea from Traditional existings?

store:
neighboor, nextdoor :

mongodbjs vs mongoosejs

comparison

mongodbjs

  • the native mongodb driver
  • performance better than mongoose
  • no schema fixed, e.g. two product, t-shirt vs digital camera
    different kind of products have different property sets, which require flexible document model

mongoosejs

  • higher level interface to MongoDB, it actually uses mongodb.js
  • fixed schema, like order, account,
  • coding level, schema can be easily changed
  • ODM, object document modeling tool
  • schema&model instantiate the same object whenever you need to create and save something
  • development faster than mongodbjs

it’s better to use the mongoDB native drivers while still using mongoose for the good stuff.

Secondary Index

mostly applied to Cassandra, HBase , mongoDB
二级索引的叶节点存储的是主键值,而不是行指针,
这是为了减少当出现行移动或数据页分裂时二级索引的维护工作,但会让二级索引占用更多的空间

MySQL

MySQL Sample

  • InnoDB, clustered table
    聚簇索引表,表数据是和主键一起存储的,主键索引的叶结点存储行数据,二级索引的叶结点存储行的主键值
  • MyISAM, non-clustered table
    堆组织表,表数据和索引是分开存储的,主键索引和二级索引存储上没有任何区别

聚簇索引表最大限度地提高了I/O密集型应用的性能,但它也有以下几个限制:

  1. 插入速度严重依赖于插入顺序,按照主键的顺序插入是最快的方式,否则将会出现页分裂,严重影响性能。因此,对于InnoDB表,我们一般都会定义一个自增的ID列为主键。
  2. 更新主键的代价很高,因为将会导致被更新的行移动。因此,对于InnoDB表,我们一般定义主键为不可更新。
  3. 二级索引访问需要两次索引查找,第一次找到主键值,第二次根据主键值找到行数据。
    二级索引的叶节点存储的是主键值,而不是行指针,这是为了减少当出现行移动或数据页分裂时二级索引的维护工作,但会让二级索引占用更多的空间。

HBase的二级索引

华为方案要点:

  1. 保证主表和索引表在同一个regionserver上(通过自定义的balancer实现)
  2. 使用coprocessor(触发器)实现索引表的创建和插入

I have idea about what Vagrant is because a training used it providing a environment long time ago, but thinking how to play it now, the bad is that my memory is empty, now i try to recover those basic things, and step into a little bit with others.

Vagrant

Create and configure lightweight, reproducible, and portable development environments
Written in Ruby, a computer software that creates and configures virtual development environments
It can be seen as a higher-level wrapper around virtualization software such as

  • VirtualBox
  • VMware
  • KVM
  • Linux Containers (LXC)

and around configuration management software such as

  • Ansible
  • Chef
  • Salt
  • Puppet

supports server environments like Amazon EC2 , Natively support Docker containers.
Refer

Act on

  • for Dev, unify development environment for team
  • for Ops, standardize same server environment

common commands

1
2
3
4
5
6
7
8
$ vagrant init		// initialize 
$ vagrant up // start vm
$ vagrant halt // stop vm
$ vagrant reload // restart vm
$ vagrant ssh // access vm by ssh
$ vagrant status // check vm status
$ vagrant destroy // destory current vm
$ vagrant package // package.box can be distributed

Step by Step

1
2
3
4
5
6
7
8
9
10
11
12
// create vagrantfile
$ vagrant init // create a box image file on current directory
// add vagrant image
$ vagrant box add hashicorp/precise64 // download from vagrant cloud, Ubuntu OS
// configure vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
end
// launch vagrant
$ vagrant up
// access virtual machine by ssh
$ vagrant ssh // directory sychronized ( /vagrant of VM <> current directory Vagrantfile located)

Automated Provisioning

automatically install softwares required

step 1

create a Bash script(bootstrap.sh) at directory Vagrantfile located

1
2
3
4
5
//#!/usr/bin/env bash
apt-get update
apt-get install -y apache2
rm -rf /var/www
ln -fs /vagrant /var/www

step 2

configure Vagrant

1
2
3
4
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.provision : shell, path: "bootstrap.sh" //vagrant use shell provisioner
end

Vagrant network

allow Host machine access the Vagrant VM
forwarded_port map host’s port 4567 to guest’s (VM) port 80.

1
2
3
4
5
6
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.provision :shell, path: "bootstrap.sh"
config.vm.network :forwarded_port, host: 4567, guest: 80
// or > config.vm.network : private_network, ip:"192.168.1.101"
end

visit http://127.0.0.1:4567 , access VM after it restarts // http://192.168.1.101

1
$vagrant reload // restart VM

docker vs vagrant

comparison 1
comparison 2
comparison 3

  • Vagrant

for development stage, allow you to install all you need to develop your application in an easy and simple way
a virtual machine manager, it allows you to script the virtual machine configuration as well as the provisioning. However, it is still a virtual machine depending on Virtual Box (or others) with a huge overhead. It requires you to have a hard drive file that can be huge, it takes a lot of ram, and performance can be not very good.

  • Docker

for production stage, a technology that allows you to run self-contained applications eliminating worries about dependencies and libraries
uses kernel cgroup and namespacing via lxc. It means that you are using the same kernel as the host and the same file system. You can use Dockerfile with the docker build command in order to handle the provisioning and configuration of your container. You have example at docs.docker.com on how to make your Dockerfile, it is very intuitive.

The only reason you could want to use vagrant is if you need to do BSD, Windows or other non-linux development on your ubuntu box. Otherwise, go for Docker.

docker & vagrant complementing each other

  1. Install a Vagrant virtual machine in your computer containing the same OS you will have in your server ( normally Ubuntu Linux 12.04 LTS 64 bits). This means that you can program in any OS you want and still expect your program will run in your server.
  2. Install your Docker packages to create Docker containers inside your virtual machine created for Vagrant. This step is better if you can install them through an script.
  3. Inside your containers put your applications ( Nginx, Memcached, MongoDB, etc)
  4. Configure a shell script, Puppet or Chef script to install Docker and run your Docker containers each time Vagrant begins.
  5. Test your containers in your Vagrant VM inside your computer.
  6. Thanks to providers now you can take the same file ( your Vagrant file ) and just type vagrant up —provider=“provider” where the provider is your next host and Vagrant will take care of everything. For example, if you choose AWS then Vagrant will: Connect to your AMI in AWS, install the same OS you used in your computer, install Docker, launch your Docker containers and give you a ssh session.
  7. Test your containers in AWS and look that they behave exactly as you expect.

something about,
embedded documents
atomicity and transaction
$isolated operator

two-phase commit

only transaction-like for multiple document
multi-document transaction, rollback-like functionality, not really an all or nothing transaction

  • atomicity, rollback previous state
  • consistency, consistent state recovery
    intermediate data presentation

concurrency control : two approach, unique index, update if current

Update if current pattern

an approach to currency control for multiple clients operate the same data

version pattern

variant : version pattern , similar to Update if current pattern
to add an version field to document schema, application/client need increment the version field upon each update operation to a specific document.
version field can be set 1 as default value for a document creation / insert operation.

it need ensure client application query data including the version field.

version can be implemented by “auto-incrementing sequence” field

SQL2Mongo

SQL2Mongo : tool to migrate all schema and data from MSSQL to mongodb,