Archive for the ‘程式設計’ Category

最近很熱門的資料庫 cassandra

星期四, 四月 29th, 2010

雖然go目前還沒有cassandra的connection library,不過已經有相關討論了。
(不管寫什麼都要置入性行銷一下go)

http://cassandra.apache.org/

cassandra 是Apache Top level Project之一,facebook,Digg 跟 Twitter 都有採用它作為一部分的資料庫.
cassandra 是一個cluster database 就像 BigTable 一樣,但他們還是不同的。
從CAP理論(http://devblog.streamy.com/2009/08/24/cap-theorem/)的角度來看
一致性(Consistency): “Is the data I’m looking at now the same if I look at it somewhere else?”
系統可用性(Availability): “What happens if my database goes down?”
分散容錯(Partition tolerance): “What if my data is on different networks?”

BigTable偏向於CA, 而cassandra則是AP。

Cassandra的API應用也相當廣泛. php, perl, python, ruby 甚至連haskell都有支援.

目前我只試過兩套python的api, lazyboy跟pycassa

簡單執行

git clone http://giturl
sudo python setup.py install

就可以安裝這兩套library了.

以下是lazyboy的example code.

from lazyboy import *
from lazyboy.key import Key

import time;

# Define your cluster(s)
begin = 0;
btime = time.time();
connection.add_pool('Keyspace1', ['192.168.23.168:9160', '192.168.23.169:9160','192.168.23.172:9160'])

for i in xrange(begin, begin + 500000):
if i!=begin and (i % 10000) == 0:
print time.time() - btime;
btime = time.time();

rc = record.Record({'value': i, 'text': "ruslan text"})
rc.key = Key("Keyspace1", "Standard1", str(i));
rc.save(0);

print time.time() - btime;

pycassa也是很nice

import pycassa
client = pycassa.connect(['192.168.23.168:9160', '192.168.23.169:9160'])

cf = pycassa.ColumnFamily(client, 'Keyspace1', 'Standard1')
cf.insert('foo', {'column1': 'val1'})
cf.get('foo')
print(cf.get('foo')['column1'])

nodetool

kevin@Office:~$ nodetool -host 192.168.23.168 -port 8080 ring
Address Status Load Range Ring
103440706267102512524414743070503313038
192.168.23.169Up 143.96 MB 10179247206633247959723284233859042110 |<--|
192.168.23.172Up 143.97 MB 24715272519024223240814048623324812800 | |
192.168.23.168Up 144.02 MB 103440706267102512524414743070503313038 |-->|
kevin@Office:~$ nodetool -host 192.168.23.168 -port 8080 info
103440706267102512524414743070503313038
Load : 144.02 MB
Generation No : 1272273320
Uptime (seconds) : 72795
Heap Memory (MB) : 128.90 / 1016.13

個人還是比較喜歡劍魂中的遊戲人物 cassandra :D

Go blog新上線

星期二, 三月 23rd, 2010

golang-logo
official Go blog
Go官方的Blog跟這星期的Go一起正式Release囉。

Go主要是希望透過這個Blog將最新的訊息帶給使用Go的開發者們,在Go Blog的第一篇文章中 Go: What’s New in March 2010 ( Btw: 這標題都超沒誠意的 『Go: 2010年三月的新消息』 )
將介紹從去年11月一直到現在Go的世界發生了什麼事。

new command: goinstall

星期三, 三月 17th, 2010

golang
http://golang.org/cmd/goinstall/

各位太太小姐,您是否每次安裝library都要下10行command呢?還記不清是先pull還是先up?

upgrade 時老忘記這個library是在下git還是hg?還是前面兩種都試完才發現是svn?

體貼各位開發者的辛苦,美國加力佛尼亞的g公司最新科技登場…
每次裝library要手動一步一步來的時代已經過去了。

現在裝Go-MySQL-Client-Library就是這麼簡單
goinstall -dashboard=true github.com/thoj/Go-MySQL-Client-Library

程式中要使用它,直接import library在goroot/pkg/$arch/下的路徑即可。
import (mysql "github.com/thoj/Go-MySQL-Client-Library")

這個cmd是Russ Cox上個月底加的
主要是簡單安裝第三方library. 目前goinstall支援git, hg, svn 三種。

Go Wiki!

星期三, 三月 17th, 2010

http://code.google.com/p/go/wiki/WikiIndex
其實這一兩天已經從golang-dev嗅到一點wiki的味道了,go wiki正式上線。

不過要參與編輯的話必須要成為contributer,需照以下方法確保你的貢獻會採用Google版的BSD Style License。
Contributor License Agreement: http://golang.org/doc/contribute.html#copyright

我個人不是很喜歡這種作法。

上課囉,Go語言在羅徹斯特理工學院(RIT)開課了。

星期一, 三月 15th, 2010

http://www.cs.rit.edu/~ats/

null

Go, Concurrent and Systems Programming (in mycourses)
4003-561-70, 4005-714-70 MW 6:00-7:50 pm, 70-3560

這堂課從2010年春季開始講授。

相關資料跟note可以參考

http://www.cs.rit.edu/~ats/go-2009-3/index.xml

Go出書了?Go for Dummies

星期五, 三月 12th, 2010

golang

還差的遠呢… Go每週Release一次,平均每兩到三個星期就會有一次語言上的修正。
這種書怎麼寫啊?

不過現在 Toni Mikael Korpela 整理了一份給笨蛋的Go入門資料(Go for Dummies)。
如果你還沒入門,可以參考看看。

http://docs.google.com/Doc?docid=0Abeqw3xBUqsUZGY2YnM5Z2tfN3NzNWJ0NGdk&hl=en

Go in Google AI Challenge

星期五, 三月 12th, 2010

Go在Google AI Challenge貪吃蛇大賽中表現亮眼。

http://csclub.uwaterloo.ca/contest/index.php



其中使用Go語言的shinobi贏得整個賽事第29名,排名他在之前的程式都是由 C++, Common Lisp, 和 C# 所撰寫的。

http://csclub.uwaterloo.ca/contest/language_profile.php?lang=Go

http://csclub.uwaterloo.ca/contest/rankings.php?page=1

RANK USERNAME COUNTRY ORGANIZATION LANGUAGE ELO SCORE
1 (29) shinobi Other Go 2570

new package: websocket

星期五, 三月 12th, 2010

http://golang.org/pkg/websocket/

websocket

websocket是html5中WebServer跟Browser交換資料的新方法。

http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-74

不仰賴 XMLHttpRequest or iframe s 這些傳統的作法,也不用開啟多個HTTP connections就可以進行資料交換。

是一個很有趣的東西。

Petar Maymounkov加入golang的開發?

星期二, 一月 19th, 2010

今天看到r新增了這個討論串,才想起這個名子好像再哪聽過…

Google了一下才發現是Bittorrent DHT(Distributed Hash Table)網路所使用的Kademlia演算法的發明人之一。

目前他主要的貢獻是在golang中改良http package。go的http package還在初期規劃階段,一般遇到最大的問題是他把http.send列為私有的function。

Russ cox認為如果在沒有規劃好http package就開放http.send的話,會導致之後的很多相容性問題。所以目前部份軟體(ex. ed2kcrawler)是另外實做http.send的,在Petar Maymounkov加入後或許會有更讚的http package吧。

Package Document鬼打牆

星期一, 一月 18th, 2010

在irc討論function時發現Document裡的一件趣事。

11:44 < happy> anyone know what function converts a string to an int?
11:48 < kevinwatt> happy: http://golang.org/pkg/strconv/#Atof64
11:49 < happy> ty
11:49 < happy> lol
11:51 < happy> Atoi is like Atoi64 but returns its result as an int; Atoi64 is
like Atoui64 but allows signed numbers and returns its result in
an int64.; Atoui is like Atoui64 but returns its result as a
uint.
11:51 < happy> does it go on forever? They are in reverse order :-\
11:51 < happy> the one at the top says refer to the next one which says refer to the next one…

文件中一直請你參照別的function,就像鬼打牆一樣繞不出去。
Atoi這種其實只要簡單的一行說明就好了,沒有說明卻一直附上參考實在是頗有趣…

Package Link
Screenshot-2