积水成渊

xiaode的博客

Welcome Kittens!

Never thought about adopting a cat before util last weekend. Me and Sarah decided to visit the pet rescue. Now five years passed. They become family now.

This is Wade a.k.a Toufu.
Imgur

This is Quentin a.k.a Yolk.
Imgur

Introduction

This small project is the final project for my CSS532 of UW CSS. Health is a significant topic as we always talk about, the foods we eat every day have very important effects on our body health. The refridgerator is the place where most of families store the foods, however, life is so busy that we also forget what we have put into our food store and what time we put them in. Normally, we have wasted the freshness of the good food even have some food gone bad and pollute the whole store. So, to address this, I want to create a smart refridgerator assistant who can take care the problems.

The idea is about recording the foods in your refridgerator and remind you of what we have and when we put them in. To implement a small prototype to make the requirements come true, I need to combine the techniques of IoT, Cloud computing and Machine Learning. With the help of this smart refridgerator assistant, we can avoid forgetting foods in our refridgerators and keep track on the freshness of them. The whole picture looks like that the assistant is going to monitor the refridgerator and send message to IoT hub, the cloud will store the food status and send notification to our mobile phone app and let us know the status of our refridgerator, so I can know what we have in our food store and decide the what to eat next.

Project Presentation

Technique Background

Devices

This project uses two devices, one is Raspberry Pi served as monitor device, the other is an Android mobile phone served as an end device. Two devices are not connected directly, AWS services act as the communication media. The lambda function will control the message flow, and all the messages are over MQTT protocal.

Raspberry Pi

The Raspberry Pi is a series of small single-board computers developed in the United Kingdom by the Raspberry Pi Foundation to promote teaching of basic computer science in schools and in developing countries. The one I use in this project is Raspberry Pi 3 Model B+. The Raspberry Pi is also equiped with a video camera for image capturing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Raspberry Pi 3 Model B+

CPU: Quad core 64-bit processor clocked at 1.4GHz
Memory: 1GB LPDDR2 SRAM
Network: Dual-band 2.4GHz and 5GHz wireless LAN
Bluetooth 4.2 / BLE
Higher speed ethernet up to 300Mbps
Power: Power-over-Ethernet capability (via a separate PoE HAT)
++++++++++++++

The Arducam 5 Megapixels 1080p Sensor

- High-Definition video camera for Raspberry Pi Model A or B, B+, model 2, Raspberry Pi 3,3 B+
- 5MPixel sensor with Omnivision OV5647 sensor in a fixed-focus lens
- Integral IR filter
- Still picture resolution: 2592 x 1944
- Max video resolution: 1080p

Raspberry Pi
Raspberry Pi

The Raspberry Pi device provides all runtime environment for the monitor part of this project, the device is installed with Raspbian and Python environment. The camera driver is provided by the default system.

Android Device (emulator)

As for Android Device, I use the android emulator provided by Google Android Studio for its pure Android OS. The client application will run in the emulator.
Android Device

AWS

AWS provides dozens of services that support our needs. In this project, I mainly use the service of IoT Hub, Dynamodb, Lambda, Cognito and CloudWatch.

IOT Hub

Lambda

Dynamodb

Cognito

CloudWatch

Machine Learning

In this project, the Raspberry Pi runs the recognition code

Image Recognition

Deep Learning

Caffe

System Design

Implementation

Reference

来美国两个月了,一切安好,先挖坑以后填。望笔耕不辍。

update 11/1/2018
肉翻到美帝后直接更换到了imgur.
emmmm, 真香
以下是测试:
Imgur

从注册到使用仅仅用时30s, 每张图片甚至提供生成的各种link, 用户体验极佳.

Imgur


经常写博客遇到插入图片的需求,以前因为 直接塞到到了相对路径下的资源文件里,后来用了一段时间的七牛云对象存储做图床,嫌弃上传文件再导出链接实在太麻烦就放弃了,回归了塞资源文件的老路数。今天偶然看到了推送关于解决图床问题的方法,懒如我也兴起试试。

原文链接在此

总结一下基本方法有

1
2
3
4
公共图床: 微博,Imgur,SM.MS(很奇怪的名字)
自建图床(云服务): 七牛云,又拍云,阿里云OSS
自建图床(开源方案): Lychee,树洞外链

方法殊途同归,使用图床的目的还是希望文章的图片资源能有更好的加载速度和稳定的显示效果。最终还是回归了使用图床的日子。另外强推Mac上一款图片上传工具iPic,直接解决了我之前使用图床的痛点,支持七牛又拍等多个图床,方便上传和使用外链。

Recently I have been assigned to build some online services for my Lab such as official wiki, code repository, Piazza… I have physical server machine inmy hand with pretty good hardwares and I want to build and configure these services on the bare machine at first. But the configurations for each service really annoy me and I decide to establish the whole services in another way – Docker.

My OS info is as listed below:

1
2
3
4
5
6
7
8
9
sdic@SDIC:~$ uname -a
Linux SDIC 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
sdic@SDIC:~$ sudo lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu Artful Aardvark (development branch)
Release: 17.10
Codename: artful

It is said:

Docker - Build, Ship, and Run Any App, Anywhere

So I make a list, and build these services step by step.

step 0

Of course the first step must be installing the docker in physical machine. I follow the official guides. However, my networking state seems to be not as good as others(F**K GFW), and it comes up with some problems when I use the docker official repository. After adding the official GPG key, I get 404 connect error after I run apt update, and I have no idea how to deal with it. So I turn to other solution and get the docker installed on my machine.

step 1

Requirement Analysis: The total requirements are as followed:

  1. A website for Lab basic info, like Wiki
  2. A code repository for team collaboration
  3. A forum for students who enroll the courses provided by our Lab (Piazza).
  4. A tool for managing the services’ lifetime, resource, version, backups and so on.

So I explore the docker hub to look for services matched my need. Through carefully comparing, I get another list:

step 2

Decided which services to install, here comes another question: How to manage my docker cluster? This question indicates numbers of aspects in operation and maintenance.

Backup & Recovery

As we know, the docker images run as instances on the machine, each image has its own version. When we want to update the image, how do we deal with the data in the instances? If we just force updating the image and restart the container, all data will be erased. At this point, we need to further understand the docker. Based on my konwledge, the running instance owns a special directory called data volume. It can bypass UFS and

  • shared among the containers
  • mofified immediately
  • isolated from the image
  • persisted even the container being deleted

According to the function of data volume, we can easily create or mount the volume to the container

Start & Stop

Monitoring & Logging

setp 3

Install these services on the machine and configure them. That is least important part, cuz I just refer to the official guidence and follow some advices from the commentary. I still post them out for convenience.

DokuWiki

GitLab

Forum

#使用ionic框架开发hybrid应用

什么是ionic?

Start building high-quality mobile apps with the tech you know and love.

根据官方的介绍结合本人的理解,ionic是cordova(phoneGap)加上一套移动端适配的样式和开发套件。

每个手机就像电脑一样,都带着自己的操作系统。如果你愿意,你可以从头写一个浏览器,把浏览地址隐藏了,这就像你的一个app了,对吧。当然,我们自己写浏览器,这也太难了,所以我们肯定不是这么做的。其实,我们只是基于各种手机上Web浏览器内核去做手脚,而Js是Web开发的最佳语言,至于如何封装成一个Web app?说实话,我也没有真正去探究过是如何去做的,通过一些移动开发框架,你只需要专注于写你的前端代码,然后通过一个开发框架的黑盒的操作,编译后就成了一个可以安装的App了。

什么是cordova(PhoneGap)?

一些背景小故事:

08年一次ios开发者大会上来自Nitobi软件公司的几个家伙突发奇想,提出一个想法,想做一个工具来弥补web 和ios开发之间的不足,并提出 Bridging the gap between the web and the iPhone sdk
09年他们推出android adk和blackberry sdk,成了移动开发者的福音,就连ibm也加入进来。phonegap继续成长,在2011年10月,整个Nitobi团队被adobe收购,PhoneGap的项目主管Brian LeRoux指出开源PhoneGap的决定在Adobe收购Nitobi之前就做出了,由于Adobe现在拥有PhoneGap商标,他们不得不换个名字,第一个选中的名字是Callback,毫无创意,因此再改一次,产品现在叫Apache Cordova。随后adobe把 phonegap送给了apache软件基金会,接着apache把phonegap改名为cordova,cordova是Nitobi团队当时坐落的街道名称,用此名来纪念Nitobi团队的贡献。

Cordova 框架图(图床挂了)

为什么要使用ionic?

为了web程序员可以抢移动端程序猿的饭碗。。。开个玩笑
为了更敏捷!!! _write once run everywhere_!
原来的移动客户端开发—周期长,适配麻烦。为了覆盖iOS和android两个平台,不得不招两波程序员整天在公司互相鄙视,UI和产品要根据两种平台不同的设计语言来设计两套交互和原型,浪费人力物力。(扁平化 or Material)

关于移动端开发环境的搭建

0

比较关键的几个组件:

  • JDK
  • Android SDK
  • Node.js
  • Ionic, Cordova

Android

首先看一下官方教程,主要是一些环境变量配置:

然后是IDE,首选的IDE当然是Google的AS

配置完毕后可以使用adb命令检查android SDK路径是否配置正确

举个栗子(图床挂了)

因为身在墙内,各位同学在更新SDK时肯定会遇到各种问题,可参考以下解决方案:

如何打包?

当然可以直接使用内置脚手架工具来打包啦:

1
2
3
4
# Android
ionic run android --prod --release
# or
ionic build android --prod --release

iOS

苹果配置相对Android比较简单,相对麻烦的是开发者者账号和签名,我们可以使用自己的私有账号给应用签名发布在自己的手机上进行调适。

Cordova官方配置教程

如何打包?

参考官方 iOS打包发布

各平台如何调试?

如何调适?

以下为个人推荐:

  • Android 使用Chrome的inspect工具

  • iPhone 建议使用Mac Xcode的iPhone模拟器来调适

TypeScript与JavaScript的区别在哪里?

1
2
3
4
TypeScript是ES6的超集。至于需不需要使用,在于你所需要的场景。比如在Angular2中,用TypeScript明显好于ES6。
-- 某网友

TypeScript的开发者c#之父,所以这个TypeScript的很多语言特性是从c#中移过来的。TypeScript大概是ES7的实现,所以从语法角度来讲,是具有很大优势。TypeScript可选择编译成ES5或ES3,ts文件编译成js文件,并且ts文件可直接在浏览器中调试。TypeScript还有一大优势是配合宇宙最强编译器VS,开发效率非常高。唯一的不足只是用TypeScript开发的人太少。

什么是ECMA?

1
2
ECMAScript 6.0(以下简称ES6)是JavaScript语言的下一代标准,已经在2015年6月正式发布了。它的目标,是使得JavaScript语言可以用来编写复杂的大型应用程序,成为企业级开发语言。
--阮一峰

ECMAScript和JavaScript的关系?

由于JavaScript的创造者Netscae公司的版权问题吧,ECMAScript不能叫Javascript。总之,ECMAScript和JavaScript的关系是,前者是后者的规格,后者是前者的一种实现(另外的ECMAScript方言还有Jscript和ActionScript)。

angularJS和第一问中两者的关系是什么?

AngularJS是一款优秀的前端JS框架
AngularJS2是基于typescript来开发的。

在2014年底,Google宣布Angular 2将会对AngularJS进行完全地重写,他们甚至还创建了一门新的语言,名为“AtScript”,他们本来希望使用这门语言来编写Angular 2应用。

但是,随后Microsoft同意在它们的TypeScript语言(JavaScript的一个严格超集)上添加对装饰符(decorator)的支持,所以,它就成为了开发Angular 2框架本身所使用的语言,并且还是使用AngularJS框架开发应用的推荐语言。

另外,我们还可以使用JavaScript(ECMAScript 5和6均可)和Dart来编写Angular 2应用。

除此之外,Angular团队还集成了Microsoft的另外一个产品到Angular 2框架之中,这就是反应型JavaScript扩展(reactive JavaScript extension)的RxJS库。

Angular 2并不是一个MVC框架,而是基于组件(component)的框架。在Angular 2中,应用是松耦合组件所组成的树。

JS的特性有哪些?

过去的2016和来到的2017

难免落入窠臼写一些年终总结的陈词滥调,但是真正开始动笔的时候又有了写下去的欲望,可见人是多么矛盾的存在。

这一年过得十分安逸,继续躲在大学的象牙塔里,没了两年前刚入学的血气方刚,手中的笔一丢就是一年多,现在捡起来写这一两个字,竟觉得力有不逮,果然温水煮青蛙是会把青蛙弄死的。

16年这一年的主题是所谓“科研”,上半年在跟着别人合伙科研,下半年在带着别人合伙科研,可一年后回头看,自己只不过打着科研的名号四处乱撞罢了。本想着搞那么一两个大新闻,认清了自己too young的现实情况下,还是为了毕业写写文章灌灌水吧。

一年12月,大部分情况下是异国,时差和距离不是问题,我惶恐的是时间。看着周围的人在结婚生子,总会下意识地给自己订一个时间表,留给自己的时间真心不多了。17年恰逢本命,掰着手指一算25岁才能毕业,越成长来自各方的压力就越大,爱人不想辜负,亲人想要陪伴,自己又有前方未知的事业。说是迷茫,哪敢迷茫,奋然前行,路在何方?

上半年还有课,且上且珍惜的度过了自己可能是学生生涯的最后一个学期,总体平稳,除了最后一门课考试掉了链子,影响到了自己的成绩,总归还是没有拿到奖学金,心里还是有丝丝不爽的。年中,丫头从美帝回来过暑假,陪读了两个多月,期间去了一趟北京参与了社会实践活动,收获还算是不少的,至少拓宽了眼界。对于帝都,依旧是爱不起来,索性就断了去北京的念头。家人在长三角,以后也会考虑定居在这边,毕竟家中独子,冷暖自知。

下半年过得很快,快到一眨眼什么还没看清楚就翻到了17年。十一的时候幼稚的想要开始写论文,还给自己立了flag说12月底要写完,结果又扇了自己的脸,这都到来年的1月了,连草稿都没打完,果然是执行力极弱的人啊。反思!反思!反思!执行力和毅力,这两样东西曾经我以为我有,但是现在看来,我都缺乏的可怜。今年列的计划,健身,读书,写代码,一事无成。可怜!可悲!可叹!十一因为一次意外的手指受伤停止了健身的步伐,因为所谓的“科研”很忙,没有静下心来完整的读一本好书,自以为自己代码能力不错,却在长久的自大中逐渐生疏。年岁增长未必为人师长,因为所得不及所失。12月又去了北京参与了一次GNTC的会议,感受下工业界大牛们的

吐槽了自己的2016这么久,是希望2017能不再重蹈覆辙。我知道这一年对我来说的重要性,更明白对于当下的我来说,时间是最宝贵的资源,所以今年的反思我会常常翻出来看,日日鞭笞自己,激励自己。
简单列个计划吧,省得过两天又抛到脑后去了。

List
1
2
3
4
5
6
健身:身体是承载一切理想的基础
专业技能:业务能力和熟练程度
学术论文:总结问题能力和表达能力
读50本有营养的书
学习日语,复习英语
好好爱小羽

这篇总结和计划我会再明年的年终总结中引用,希望明年的总结不会继续想今年这样打脸,也希望本命年一切顺遂,小羽能找到心仪的工作,叔叔阿姨爸爸妈妈各位亲人身体健康。

NUMA基础模型参数测量方案

实验目的

本实验是为测量在具体平台下IONUMA模型的各项具体参数数值和分布,以此项数据作为参考来建立考虑IO访问下的新NUMA模型,填充相应的矩阵,以此来形成我们通过实验所测得经验模型。

实验原理

通过不同类型的Benchmark来分别测量:

CPU-内存距离使用@Stream,这是一个经典的内存访问带宽的测量工具;CPU-网卡距离可以使用iPerf,使用@iPerf可以指定buffer size,当我们使用较小的buffer size时,memory trunk会被cpu缓存,所以Intel的处理器会使用DCA技术直接写缓存,从而给出了一个与内存无关的访问场景

网卡-内存距离,可以使用经典的@netperf来测量。当使用netperf测量网络性能时,其主要过程在与由网卡buffer通过DMA操作写内存,故与该线程的CPU相对无关。

在实验中,我们使用@numactl来绑定所运行的cpu和memory,从而达到控制实验变量的目的。

相关工具

iPerf

  • iPerf2 features currently supported by iPerf3 :
    TCP and UDP tests
    Set port (-p)
    Setting TCP options: No delay, MSS, etc.
    Setting UDP bandwidth (-b)
    Setting socket buffer size (-w)
    Reporting intervals (-i)
    Setting the iPerf buffer (-l)
    Bind to specific interfaces (-B)
    IPv6 tests (-6)
    Number of bytes to transmit (-n)
    Length of test (-t)
    Parallel streams (-P)
    Setting DSCP/TOS bit vectors (-S)
    Change number output format (-f)

  • New Features in iPerf 3.0 :
    Dynamic server (client/server parameter exchange) – Most server options from iPerf2 can now be dynamically set by the client
    Client/server results exchange
    A iPerf3 server accepts a single client simultaneously (multiple clients simultaneously for iPerf2)
    iPerf API (libiperf) – Provides an easy way to use, customize and extend iPerf functionality
    -R, Reverse test mode – Server sends, client receives
    -O, –omit N : omit the first n seconds (to ignore TCP slowstart)
    -b, –bandwidth n[KM] for TCP (only UDP for IPERF 2): Set target bandwidth to n bits/sec (default 1 Mbit/sec for UDP, unlimited for TCP).
    -V, –verbose : more detailed output than before
    -J, –json : output in JSON format
    -Z, –zerocopy : use a ‘zero copy’ sendfile() method of sending data. This uses much less CPU.
    -T, –title str : prefix every output line with this string
    -F, –file name : xmit/recv the specified file
    -A, –affinity n/n,m : set CPU affinity (cores are numbered from 0 - Linux and FreeBSD only)
    -k, –blockcount #[KMG] : number of blocks (packets) to transmit (instead of -t or -n)
    -4, –version4 : only use IPv4
    -6, –version6 : only use IPv6
    -L, –flowlabel : set IPv6 flow label (Linux only)
    -C, –linux-congestion : set congestion control algorithm (Linux and FreeBSD only) (-Z in iPerf2)
    -d, –debug : emit debugging output. Primarily (perhaps exclusively) of use to developers.
    -s, –server : iPerf2 can handle multiple client requests. iPerf3 will only allow one iperf connection at a time.

  • Features in iPerf 3.1 :
    -I, –pidfile file write a file with the process ID, most useful when running as a daemon.
    –cport : Specify the client-side port.
    –sctp use SCTP rather than TCP (Linux, FreeBSD and Solaris).
    –udp-counters-64bit : Support very long-running UDP tests, which could cause a counter to overflow
    –logfile file : send output to a log file.

  • iPerf2 Features Not Supported by iPerf3 :
    Bidirectional testing (-d / -r)
    Data transmitted from stdin (-I)
    TTL : time-to-live, for multicast (-T)
    Exclude C(connection) D(data) M(multicast) S(settings) V(server) reports (-x)
    Report as a Comma-Separated Values (-y)
    Compatibility mode allows for use with older version of iPerf (-C)

Stream

Netperf

numactl

  • useage:
    numactl [ –interleave nodes ] [ –preferred node ] [ –membind nodes ] [ –cpunodebind nodes ] [ –physcpubind cpus ] [ –localalloc ] [–] command {arguments …}
    numactl –show
    numactl –hardware
    numactl [ –huge ] [ –offset offset ] [ –shmmode shmmode ] [ –length length ] [ –strict ]
    [ –shmid id ] –shm shmkeyfile | –file tmpfsfile
    [ –touch ] [ –dump ] [ –dump-nodes ] memory policy

本试验中应当使用的命令如下:

1
numactl --membind= --cpubind=

NUMA模型

Platform相关信息:

C-M Citrix
该矩阵记录该NUMA架构下,每个物理CPU访问不同区域内存的具体带宽信息

N-M Citrix
该矩阵记录了网卡访问不同区域内存的平均距离,因为是CPU无关,我们考虑在这种情况的平均情况以防误差

C-N Vector
网卡到CPU的距离有该向量记录,以同一个node中的CPU的平均值来表征。

实验内容

CPU-内存距离

C-M

C\M Node0 Node1 Node2 Node3
cpu0~7
cpu8~15
cpu16~24
cpu25~31

网卡-内存距离

N\M Node0 Node1 Node2 Node3
Distance(cpu 0~7)
Distance(cpu 8~15)
Distance(cpu 16~23)
Distance(cpu 24~31)
Avg

CPU-网卡距离

C\N Node0(cpu 0-7) Node1(cpu 8-15) Node2 (cpu 16-23) Node3 (cpu 24-31)
Bandwith(avg)

实验步骤

  • CPU-内存距离测量
    使用numactl工具将Stream线程的运行CPU和内存绑定在固定位置运行,从而测出带宽值,实验中我们将根据Stream的Arraysize设为100M,大于机器L3 cache的总和64M(16M*4)以防其使用cache加速

  • 网卡-内存距离测量

  • CPU-网卡距离测量

实验结果

一点背景

近期在做一些NFV方向的研究,算是新兵蛋子一个. NFV和SDN的具体内容不在这里赘述,具体背景是想重现Intel ONP的平台来观测NFV在OpenStack平台上跑起来的性能如何。官方给了不少文档,但是由于所需的软件栈过于庞大,入手门槛还是挺高的。需要的软件如下:

  • OpenStack — Manages and orchestrates applications running on network nodes 中文社区
  • Opendaylight — Enables programmability of networks of any size and scale
  • DPDK — Accelerates packet processing on general-purpose processors
  • Open vSwitch — Performs virtual, multilayer network switching
  • Linux/KVM — Provides operating system and hypervisor support

看到这么多东西是不是已经晕了,别怕,我来简单梳理一下这些软件的使用结构:

  1. OpenStack是为我们提供云管理平台的组件,使用OpenStack我们可以动态的可靠的创建并维护我们的虚拟机,这个平台将云计算中的各项功能模块化并分拆开来,模块之间通过Http协议异步的进行通信,从而维持一个高可用的管理平台。其组件包括Nova,Neutron,Keystone,Swift,Cinder等等。
  2. Opendaylight是架设在云平台上用来管理并实现SDN/NFV的另一个开源项目,其目的是为了提供一个 Data plane/ Control plane 相分离的虚拟机拓扑结构,并与Open vSwitch结合,实现性能的提升。
  3. DPDK是Intel官方出的数据面开发工具集,个人理解是intel利用其硬件基础实现的网络IO性能提升,主要包括的是协议栈offline和“零拷贝”(0 copy),将原来在内核的硬件驱动(网卡)功能解耦,并实现用户态程序直接获得数据包的功能。
  4. KVM,这个就不多说了,直接看论文去吧. paper

具体过程

建议和思考

踩过的坑(updating)

0%