2015年终总结

2015年转眼就过去了,是时候总结一下了:
1.今年是我2008年正式工作以来,工作上最动荡的一年。之前在M和A公司,工作上几乎很平淡,就是一个版本一个版本地做feature。而今年工作上发生了太多的事,估计可以拍成一部电影。等将来找个时间,再细细描述这段经历。
2.生活上没有太多变化,分别去天津和南京旅游了一趟,仅此而已。
3.chinadtrace网站和英文博客都坚持下来了。中文博客并没有发表太多有价值的文章,更多地是记录了工作上的一些笔记。
4.阅读了一些自己感兴趣的书。
5.见到了自己的偶像,自由斗士——RMS先生。
6.为一些公益网站和项目捐了一点钱,尽管不是很多,一点心意。
7.做了自己的第一件T恤衫。
8.儿时的好友们难得的来了一次大聚会。
9.做了Using DTrace stories这个开源项目。

Mesos笔记 (5)—— 资源

本文参考Building Applications on Mesos

Mesos Slave提供的通用资源包含:CPUsmemorydiskports。需要注意的是CPUs的值定义:

Capture

Slave提供资源的例子:

Capture Slave本身属性的定义:

Capture

Slave为不同的role预留资源有两种方式:
静态方式:在命令行指定不同的role获得不同的资源:

Capture

动态方式:从0.25版本开始,支持通过JSON配置文件和HTTP API方式动态预留资源。

获取资源的函数:

namespace mesos {
namespace internal {
namespace slave {

// TODO(idownes): Move this to the Containerizer interface to complete
// the delegation of containerization, i.e., external containerizers should be
// able to report the resources they can isolate.
Try<Resources> Containerizer::resources(const Flags& flags)
{
  Try<Resources> parsed = Resources::parse(
      flags.resources.getOrElse(""), flags.default_role);

  if (parsed.isError()) {
    return Error(parsed.error());
  }

  Resources resources = parsed.get();

  // NOTE: We need to check for the "cpus" string within the flag
  // because once Resources are parsed, we cannot distinguish between
  //  (1) "cpus:0", and
  //  (2) no cpus specified.
  // We only auto-detect cpus in case (2).
  // The same logic applies for the other resources!
  if (!strings::contains(flags.resources.getOrElse(""), "cpus")) {
    // No CPU specified so probe OS or resort to DEFAULT_CPUS.
    double cpus;
    Try<long> cpus_ = os::cpus();
    if (!cpus_.isSome()) {
      LOG(WARNING) << "Failed to auto-detect the number of cpus to use: '"
                   << cpus_.error()
                   << "'; defaulting to " << DEFAULT_CPUS;
      cpus = DEFAULT_CPUS;
    } else {
      cpus = cpus_.get();
    }

    resources += Resources::parse(
        "cpus",
        stringify(cpus),
        flags.default_role).get();
  }

  // Memory resource.
  ......
}

举个例子:启动Slave时参数为--resources=gpgpus:1,则Resources::parse函数会解析gpgpus资源;由于命令行没有提供CPUmemory之类的参数,需要调用os::cpus()等方法来获得。

 

Kubernetes笔记(7)—— 搭建”k8s on Mesos”注意事项

在本地搭建k8s on Mesos项目时,Mesos client脚本要以root身份运行。另外如果本地环境用到了proxy,一定要注意可能(不确定是否有例外,比如也许取决于你所使用的proxy或操作系统)需要把k8s或者MesosIP地址加入到no-proxy/NO_PROXY环境变量中。具体可参见下列issues
The kubernetes on Mesos can’t run successfully on the same machine
Why does “km controller-manager” think it is an invalid event?
The “km controller-manager” command doesn’t work successfully behind proxy.

 

Go语言的new函数

以下摘自The Go Programming Language

Each call to new returns a distinct variable with a unique address:
p := new(int)
q := new(int)
fmt.Println(p == q) // “false”
There is one exception to this rule: two variables whose type carries no information and is therefore of size zero, such as struct{} or [0]int, may, depending on the implementation, have the same address.
The new function is relatively rarely used because the most common unnamed variables are of struct types, for which the struct literal syntax is more flexible.

Since new is a predeclared function, not a keyword, it’s possible to redefine the name for something else within a function, for example:
func delta(old, new int) int { return new – old }
Of course, within delta, the built-in new function is unavailable.

 

Mesos笔记 (2)—— 启动Slave脚本时注意事项

启动Mesos slave脚本时,要使用root权限。如果和Mesos Master运行在不同Server上,要指定所在机器的IP

$ sudo ./bin/mesos-slave.sh --master=10.100.3.50:5050 --ip=10.100.3.39

下文引自Building Applications on Mesos

Since the slaves need to be able to launch containers and ensure that the executors are run as specific users, the slave process typically runs as root , so that it can create containers and run different executors as different users.

 

Go语言的变量定义

以下摘自The Go Programming Language

A var declaration creates a variable of a particular type, attaches a name to it, and sets its initial value. Each declaration has the general form
var name type = expression
Either the type or the = expression part may be omitted, but not both. If the type is omitted, it is determined by the initializer expression. If the expression is omitted, the initial value is the zero value for the type, which is 0 for numbers, false for booleans, “” for strings, and nil for interfaces and reference types (slice, pointer, map, channel, function). The zero value of an aggregate type like an array or a struct has the zero value of all of its elements or fields.

short variable declarations are used to declare and initialize the majority of local variables. A var declaration tends to be reserved for local variables that need an explicit type that differs from that of the initializer expression, or for when the variable will be assigned a value later and its initial value is unimportant:
i := 100 // an int
var boiling float64 = 100 // a float64
var names []string
var err error
var p Point

关于“A var declaration tends to be reserved for local variables that need an explicit type that differs from that of the initializer expression,”的理解:var boiling float64 = 100如果使用i := 100的形式来定义,则会认为iint,而不是float