CODE4FUN

云主机价格比较 2014-09-19

云主机价格

计费单位为元每月, 使用各服务商官方提供的计算器计算

价格基于以下配置

CPU内存系统盘数据盘线路带宽
1核2G20G100G双线2Mbps

UCloud

CPU内存系统盘数据盘线路带宽
1核2G20G100G双线2Mbps

价格: 162元

青云

CPU内存系统盘数据盘线路带宽
1核2G20G100G未知2Mbps

价格: 251.28元

使用Python的10个常见错误 2014-07-23

10 Most Common Python Mistakes抄来的.

使用 iPython 生成.

#1: 错误的使用表达式做为函数默认值

def foo(a = []):
    a.append('bar')
    return a

foo()
foo()
foo()
foo()

Go 1.3 Release Notes 2014-06-24

6月18日,在Go 1.2发布六个月之后,Go官方宣布正式发布Go 1.3。Go 1.3并没有引入新的语言功能,只是进行了功能改进,并修复了一些bug以及用户的反馈。新的版本开始支持DragonFly BSD、Solaris、Plan 9和Google的NaCl( Native Client),且显著改进了链接器和编译器。低版本的Go语言用户无需更改任何代码即可升级到Go 1.3。

主要改进包括:

读者可以在这里下载Go 1.3。详细的改进说明可以阅读官方文档。不能翻墙的用户可以使用社区提供的镜像来下载

ElasticSearch索引优化速查 2014-05-12

最近做ElasticSearch索引的优化, 发现一篇好文. 转载于此, 有空再翻译.

原文地址: Elasticsearch Indexing Performance Cheatsheet


You plan to index large amounts of data in Elasticsearch? Or you are already trying to do so but it turns out that throughput is too low? Here is a collection of tips and ideas to increase indexing throughput with Elasticsearch. Some of them I have successfully tried myself, others I have only read about and found them reasonable. In any case, I hope you will find them useful.

In order to fit all this into a single article, I have kept the suggestions rather brief. For some of them, you may feel that you need to learn more before putting them into practice. To ease your task a little, I have included links to the relevant sections of the Elasticsearch documentation which you may use as a starting point for further research.

General Performance

Before doing anything more specific, it makes sense to follow the advice given in the Elasticsearch documentation on configuration. In a nutshell:

Docker中遗失的包 2014-04-22

原文 翻译

netlink

我们有一个Netlink的纯Go实现,你可以用在你的项目中。你可以使用这个包来创建veth 接口,桥,设置IP,mtu,和网络接口的其他设置,移动网络接口到不同的Linux命名空间中,等等一堆事情。创建veth pairs和对你的每个docker容器分配一个IP的代码是相同的。

让我们用这个包创建一个桥并设置一个IP:

package main

import (
        "github.com/dotcloud/docker/pkg/netlink"
        "log"
        "net"
)

func main() {
        // create a new bridge
        if err := netlink.CreateBridge("mydocker0", false); err != nil {
                log.Fatal(err)
        }
        // get the bridge
        bridge, err := net.InterfaceByName("mydocker0")
        if err != nil {
                log.Fatal(err)
        }

        ip, ipNet, err := net.ParseCIDR("10.0.41.1/16")
        if err != nil {
                log.Fatal(err)
        }

        // add an ip to the bridge
        if err := netlink.NetworkLinkAddIp(bridge, ip, ipNet); err != nil {
                log.Fatal(err)
        }
        // bring the interface up
        if err := netlink.NetworkLinkUp(bridge); err != nil {
                log.Fatal(err)
        }
}

工程师心里的痛只有工程师才会懂 2014-04-18

工程师心里的痛只有工程师才会懂

ElasticSearch名词解释 2014-04-04

每个cluster由一个或多个节点组成,它们共享同一个集群名.每个cluster有一个被自动选出的master节点,当该master节点挂掉的时候会被自动替换.

node是elasticsearch的运行实例.为了测试,多个node可以在同一台服务器上启动,但是通常一个服务器只放一个node. 系统启动时,node会使用广播(或指定的多播)来发现一个现有的cluster,并且试图加入该cluster.

index有点像关系型数据库中的“database”,包含不同的type的schema映射. 一个index是一个逻辑上的命名空间,具有一个或多个primary shards,可以拥有零个或多个replia shards.

一个shard是一个单独的lucene实例,是被elasticsearch自动管理的底层工作单元.一个索引是包含primary或replia切片的逻辑命名空间. 除了需要定义primary shards和replia shards的数量以外,你不需要直接指定使用的shards,你的代码中只关心index就好. Elasticsearch在集群中分布所有的shards,并且在添加删除节点时,自动重新分配.

Golang调用C 2014-03-31

有时候我们需要在go中调用一些使用C或者C++编写的代码. 而这些代码大多数会被编译成动态链接库的形式存在.

本文就以Mac OS下的Go开发为例, 来测试在GO中调用C.

首先做一个简单的动态链接库.

hello.h

#ifndef HELLO_H
#define HELLO_H

void hello(const char *name);

#endif

hello.c

#include <stdio.h>

void hello(const char *name) {
  printf("Hello %s!\n", name);
}

Go并发模式:管道和取消 2014-03-30

Air on G翻译.

译自[](http://blog.golang.org/pipelines)http://blog.golang.org/pipelines

这是 Go 官方 blog 的一篇文章,介绍了如何使用 Go 来编写并发程序,并按照程序的演化顺序,介绍了不同模式遇到的问题以及解决的问题。主要解释了用管道模式链接不同的线程,以及如何在某个线程取消工作时,保证所有线程以及管道资源的正常回收。

Go 并发模式:管道和取消

作者:Sameer Ajmani,blog.golang.org,写于 2014 年 3 月 13 日。

介绍

Go 本身提供的并发特性,可以轻松构建用于处理流数据的管道,从而高效利用 I/O 和多核 CPU。这篇文章就展示了这种管道的例子,并关注当操作失败时要处理的一些细节,并介绍了如何干净的处理错误的技巧。

什么是管道?

Go 语言里没有明确定义管道,而只是把管道当作一类并发程序。简单来说,管道是一系列由 channel 联通的状态(stage),而每个状态是一组运行相同函数的 Goroutine。每个状态上,Goroutine

Linux 文件 Loop设备 LVM 2014-03-13

不知道标题该怎么取. 本文主要介绍在Linux下怎样将文件挂载成磁盘并且用LVM进行分区管理.

什么是loop设备

loop设备是一种伪设备. 是使用文件来模拟块设备的一种技术. 文件模拟成块设备后, 就像一个磁盘或光盘一样使用. 回环可以理解成回复重用, 在已有设备上建立文件来模拟物理块设备.

关联loop设备

一般在linux中会有8个loop设备. 我们可以将文件关联到这些设备上. 查看所有的loop设备: losetup -a, 输出: /dev/loop0: [0806]:5373954 (/mnt/var/disk/disk0.img) /dev/loop1: [0806]:5373955 (/mnt/var/disk/disk1.img) /dev/loop2: [0806]:5373956 (/mnt/var/disk/disk2.img) /dev/loop3: [0806]:5373957 (/mnt/var/disk/disk3.img)

查看下一个未使用的loop设备: losetup -f, 输出: