2015-01-21

Ruby 2.1.5 vs 2.2.0 Performance Benchmark

Ruby 2.2.0 released last christmas (yea, I give you my heart~), and I ain't got any news about it (thanks to Google Alert) -_-|||, ok then let's do the benchmark, yay! :3

Benchmark FileInput Sizeruby-2.1.5 p273ruby-2.2.0 p0Performance Increase
macro-benchmarks/bm_gzip.rb1005.4418007875.529919291-1.62%
macro-benchmarks/bm_hilbert_matrix.rb100.0015066440.001508498-0.12%
macro-benchmarks/bm_hilbert_matrix.rb200.0180345140.019916750-10.44%
macro-benchmarks/bm_hilbert_matrix.rb300.0840658660.088421611-5.18%
macro-benchmarks/bm_hilbert_matrix.rb400.2433687390.257345416-5.74%
macro-benchmarks/bm_hilbert_matrix.rb500.6566729310.665158535-1.29%
macro-benchmarks/bm_hilbert_matrix.rb601.4833529251.499879964-1.11%
macro-benchmarks/bm_mpart.rb3000.0210451940.01858062311.71%
macro-benchmarks/bm_norvig_spelling.rb504.1056013593.8381815196.51%
macro-benchmarks/bm_parse_log.rb1000.5243118240.534461600-1.94%
macro-benchmarks/bm_rcs.rb1000.1673491930.167786871-0.26%
macro-benchmarks/bm_sudoku.rb11.3785271921.3097690034.99%
micro-benchmarks/bm_app_factorial.rb50000.0183778520.01631250311.24%
micro-benchmarks/bm_app_fib.rb300.1547457890.1451332626.21%
micro-benchmarks/bm_app_fib.rb351.7230136991.6511991024.17%
micro-benchmarks/bm_app_mandelbrot.rb10.1508939670.1480295441.90%
micro-benchmarks/bm_app_pentomino.rb120.91605014720.2193213553.33%
micro-benchmarks/bm_app_tak.rb70.1142748990.1081841895.33%
micro-benchmarks/bm_app_tak.rb80.3326020740.3119493296.21%
micro-benchmarks/bm_app_tak.rb90.8925922960.8139617978.81%
micro-benchmarks/bm_app_tarai.rb30.4186696320.3779541919.72%
micro-benchmarks/bm_app_tarai.rb40.5015455500.44657437710.96%
micro-benchmarks/bm_app_tarai.rb50.5704040660.5461785304.25%
micro-benchmarks/bm_binary_trees.rb17.6094919177.742826158-1.75%
micro-benchmarks/bm_cal.rb5000.0411283820.0409776420.37%
micro-benchmarks/bm_count_multithreaded.rb10.0043246640.005010469-15.86%
micro-benchmarks/bm_count_multithreaded.rb20.0091488980.010368676-13.33%
micro-benchmarks/bm_count_multithreaded.rb40.0217645230.01927901811.42%
micro-benchmarks/bm_count_multithreaded.rb80.0456799360.0413018249.58%
micro-benchmarks/bm_count_multithreaded.rb160.0792680710.091182084-15.03%
micro-benchmarks/bm_count_shared_thread.rb10.0404284740.042236155-4.47%
micro-benchmarks/bm_count_shared_thread.rb20.0454026220.0433190784.59%
micro-benchmarks/bm_count_shared_thread.rb40.0463385460.0459357780.87%
micro-benchmarks/bm_count_shared_thread.rb80.0594895940.05279723111.25%
micro-benchmarks/bm_count_shared_thread.rb160.0555088970.062376136-12.37%
micro-benchmarks/bm_dirp.rb100001.0411283391.069316017-2.71%
micro-benchmarks/bm_eval.rb10000006.4859326266.937864716-6.97%
micro-benchmarks/bm_fannkuch.rb60.0012134660.001289357-6.25%
micro-benchmarks/bm_fannkuch.rb80.0914047020.095585812-4.57%
micro-benchmarks/bm_fannkuch.rb1011.69747586712.100328001-3.44%
micro-benchmarks/bm_fasta.rb10000008.5766513358.3082399763.13%
micro-benchmarks/bm_ffi_printf.rb1000000.516967724LoadError
micro-benchmarks/bm_fiber_ring.rb100.0003083440.000332843-7.95%
micro-benchmarks/bm_fiber_ring.rb1000.0133686380.01180348011.71%
micro-benchmarks/bm_fiber_ring.rb10001.9420498531.50377529822.57%
micro-benchmarks/bm_fractal.rb50.5897041520.5393404538.54%
micro-benchmarks/bm_gc_array.rb113.64690203811.94584665612.46%
micro-benchmarks/bm_gc_mb.rb5000000.1384165340.09915606028.36%
micro-benchmarks/bm_gc_mb.rb10000000.2456715630.18143441026.15%
micro-benchmarks/bm_gc_mb.rb30000000.7683781830.66810086213.05%
micro-benchmarks/bm_gc_string.rb12.6184946072.5567723182.36%
micro-benchmarks/bm_knucleotide.rb10.5236778310.5175812411.16%
micro-benchmarks/bm_list.rb10000.0241720780.01986159917.83%
micro-benchmarks/bm_list.rb100000.9060837710.8696842404.02%
micro-benchmarks/bm_lucas_lehmer.rb96890.5232258070.5186681210.87%
micro-benchmarks/bm_lucas_lehmer.rb99410.5623396360.5538516051.51%
micro-benchmarks/bm_lucas_lehmer.rb112130.7501384740.7363778081.83%
micro-benchmarks/bm_lucas_lehmer.rb199372.9216229092.9178080620.13%
micro-benchmarks/bm_mandelbrot.rb17.5683576167.2822736563.78%
micro-benchmarks/bm_mbari_bogus1.rb10.0197005590.020653362-4.84%
micro-benchmarks/bm_mergesort.rb10.4296423510.4041294115.94%
micro-benchmarks/bm_mergesort_hongli.rb30000.6768509260.6738260030.45%
micro-benchmarks/bm_meteor_contest.rb13.8052915023.6300699594.60%
micro-benchmarks/bm_monte_carlo_pi.rb100000002.3594493022.1969672686.89%
micro-benchmarks/bm_nbody.rb1000000.8981084690.8978282680.03%
micro-benchmarks/bm_nsieve.rb92.1775391002.0563559065.57%
micro-benchmarks/bm_observ.rb1000000.3006297050.26813425210.81%
micro-benchmarks/bm_open_many_files.rb500000.2342404970.20007004614.59%
micro-benchmarks/bm_partial_sums.rb25000003.1756247892.9666651196.58%
micro-benchmarks/bm_pathname.rb10028.86605365629.000798768-0.47%
micro-benchmarks/bm_pi.rb10000.0318166700.0288376499.36%
micro-benchmarks/bm_pi.rb100002.7938742242.7282088132.35%
micro-benchmarks/bm_primes.rb30000.0008841000.0008343775.62%
micro-benchmarks/bm_primes.rb300000.0079500270.008346128-4.98%
micro-benchmarks/bm_primes.rb3000000.0770198550.078940931-2.49%
micro-benchmarks/bm_primes.rb30000000.7747306950.7652326571.23%
micro-benchmarks/bm_quicksort.rb10.9757187231.005529795-3.06%
micro-benchmarks/bm_read_large.rb1001.4458229041.4336912850.84%
micro-benchmarks/bm_regex_dna.rb201.6647405851.49271018010.33%
micro-benchmarks/bm_reverse_complement.rb12.2604946862.2190666741.83%
micro-benchmarks/bm_simple_connect.rb10.0001322510.00011614112.18%
micro-benchmarks/bm_simple_connect.rb1000.0033113020.0030900826.68%
micro-benchmarks/bm_simple_connect.rb5000.0163389400.0150205408.07%
micro-benchmarks/bm_simple_server.rb10.0001335030.000155542-16.51%
micro-benchmarks/bm_simple_server.rb1000.0009697070.00084697812.66%
micro-benchmarks/bm_simple_server.rb1000000.7293019840.6584448439.72%
micro-benchmarks/bm_so_ackermann.rb70.0405418650.0385931474.81%
micro-benchmarks/bm_so_ackermann.rb90.6496864580.6085772796.33%
micro-benchmarks/bm_so_array.rb90000.9828212220.9470421153.64%
micro-benchmarks/bm_so_count_words.rb1001.8701930481.7483349466.52%
micro-benchmarks/bm_so_exception.rb5000001.2383128231.1495423517.17%
micro-benchmarks/bm_so_lists.rb10002.1986860972.1147091633.82%
micro-benchmarks/bm_so_lists_small.rb10000.4533135950.4328647674.51%
micro-benchmarks/bm_so_matrix.rb600.3105549940.3086623030.61%
micro-benchmarks/bm_so_object.rb5000000.2440545830.254701496-4.36%
micro-benchmarks/bm_so_object.rb10000000.5101605330.523120809-2.54%
micro-benchmarks/bm_so_object.rb15000000.7860081950.787754481-0.22%
micro-benchmarks/bm_so_sieve.rb40004.9262801424.6936439554.72%
micro-benchmarks/bm_socket_transfer_1mb.rb100000.1383465710.07739996744.05%
micro-benchmarks/bm_socket_transfer_1mb.rb10000000.1382636570.07823478943.42%
micro-benchmarks/bm_socket_transfer_1mb_noblock.rb100000.1441793790.07864516845.45%
micro-benchmarks/bm_socket_transfer_1mb_noblock.rb10000000.1365246790.07641993144.02%
micro-benchmarks/bm_spectral_norm.rb1000.0875579860.0869018450.75%
micro-benchmarks/bm_string_concat.rb100000001.5728247591.39673948511.20%
micro-benchmarks/bm_sum_file.rb1002.4838524442.512043986-1.13%
micro-benchmarks/bm_word_anagrams.rb12.2992337622.2148209323.67%
micro-benchmarks/bm_write_large.rb1000.0947763400.0853874689.91%
rdoc/bm_rdoc_against_itself_darkfish.rb15.1562843784.49292330612.87%
rdoc/bm_rdoc_against_itself_ri.rb14.3977001244.0107925758.80%

So, as we could see, ruby-2.2.0 does bring new performance increase, especially in Socket and GCs.

2014-12-18

Benchmark of Go's (Current) Best Router/Mux

Yesterday I stumbled upon a benchmark by euforic. So today I sort all the benchmark, remove all with high memory usages, and ones with worst performance and end up with this spreadsheet visualization (oh before I forgot, LibreOffice Calc conditional formatting is freakin' buggy).


And if you asked me, what's the best for all case? Just search for one that have the most green. Denco seems to have consistent performance, and FYI the older benchmark favors to HttpRouter.

2014-11-28

How to Remotely Run Command on Windows PC from Linux

So, sometimes the server uses Windows instead of Linux or BSD, and we need to execute certain command on the server, because the web interface not suffice, for example, exporting 1.2GB of data from MySQL using PHPMyAdmin? timeout! :3
We could use a tool called winexe, to install it, type:

yaourt -S winexe

Then just execute:

winexe -U USERNAME //IPADDRESS cmd.exe

Voila~ :3

2014-11-27

How to use Go-Couchbase

Today I will try to use Go-Couchbase, to insert, fetch, update and delete from database. To install go-couchbase, type this commands:

go get -u -v github.com/couchbaselabs/go-couchbase

Then just create an example source code and run it:

package main

import (
"fmt"

"github.com/couchbaselabs/go-couchbase"
//"github.com/davecgh/go-spew/spew"
"encoding/json"

"github.com/kr/pretty"
//"reflect"
"errors"
"runtime"
"strings"
)

var FILE_PATH string
var CB *couchbase.Bucket

// initialize file path
func init() {
_, file, _, _ := runtime.Caller(1)
FILE_PATH = file[:4+strings.Index(file, "/src/")]
err := errors.New("no error")
CB, err = couchbase.GetBucket("http://127.0.0.1:8091/", "default", "default")
Panic(err, "Error connection, getting pool or bucket:  %v")
}

// print warning message
func Check(err error, msg string, args ...interface{}) error {
if err != nil {
_, file, line, _ := runtime.Caller(1)
str := fmt.Sprintf("%s:%d: ", file[len(FILE_PATH):], line)
fmt.Errorf(str+msg, args...)
res := pretty.Formatter(err)
fmt.Errorf("%# v\n", res)
}
return err
}

// print error message and exit program
func Panic(err error, msg string, args ...interface{}) {
if Check(err, msg, args...) != nil {
panic(err)
}
}

// describe a variable
func Explain(args ...interface{}) {
_, file, line, _ := runtime.Caller(1)
//res, _ := json.MarshalIndent(variable, "   ", "  ")
for _, arg := range args {
res := pretty.Formatter(arg)
fmt.Printf("%s:%d: %# v\n", file[len(FILE_PATH):], line, res)
}
//spew.Dump(variable)
}

func main() {

var err error

// save values (upsert)
err = CB.Set("someKey", 0, []string{"an", "example", "list"})
Check(err, "failed to set somekey")

err = CB.Set("primaryKey", 0, 1)
Check(err, "failed to set primaryKey")

// fetch one value
var rv interface{}
err = CB.Get("someKey", &rv)
Check(err, "failed to get someKey")
Explain(rv)

// fetch with CheckAndSet id
cas := uint64(0)
err = CB.Gets("primaryKey", &rv, &cas)
Check(err, "failed to get primaryKey")
Explain(cas, rv)

// fetch multivalue
rows, err := CB.GetBulk([]string{"someKey", "primaryKey", "nothingKey"})
Check(err, "failed to get someKey or primaryKey or nothingKey")
Explain(rows)

jsonStr := rows["someKey"].Body
Explain(string(jsonStr))

stringList := []string{}
err = json.Unmarshal(jsonStr, &stringList)
Check(err, "failed to convert back to json")
Explain(stringList)

// increment value, returns new value
nv, err := CB.Incr("primaryKey", 1, 1, 0)
Check(err, "failed to increment primaryKey")
Explain(nv)

// increment value, defaults to 1 if not exists
nv, err = CB.Incr("key3", 1, 1, 60)
Check(err, "failed to increment primaryKey")
Explain(nv)

}

This would give an output:

/test.go:92: []interface {}{
    "an",
    "example",
    "list",
}
/test.go:98: uint64(0x13aa8b32b9f7f091)
/test.go:98: float64(1)
/test.go:103: map[string]*gomemcached.MCResponse{
    "primaryKey": &gomemcached.MCResponse{
        Opcode: 0x0,
        Status: 0x0,
        Opaque: 0x0,
        Cas:    0x13aa8b32b9f7f091,
        Extras: {0x0, 0x0, 0x0, 0x0},
        Key:    {},
        Body:   {0x31},
        Fatal:  false,
    },
    "someKey": &gomemcached.MCResponse{
        Opcode: 0x0,
        Status: 0x0,
        Opaque: 0x0,
        Cas:    0x13aa8b32b9e4690f,
        Extras: {0x0, 0x0, 0x0, 0x0},
        Key:    {},
        Body:   {0x5b, 0x22, 0x61, 0x6e, 0x22, 0x2c, 0x22, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x22, 0x2c, 0x22, 0x6c, 0x69, 0x73, 0x74, 0x22, 0x5d},
        Fatal:  false,
    },
}
/test.go:106: "[\"an\",\"example\",\"list\"]"
/test.go:111: []string{"an", "example", "list"}
/test.go:116: uint64(0x2)
/test.go:121: uint64(0x4)

How to install Couchbase on ArchLinux

Couchbase is NoSQL database with the best performance AFAIK. To install Couchbase, we need git and repo tool, that could be installed using this command:

sudo pacman -S git libtool gcc libevent make gperftools sqlite erlangautomake autoconf make curl dmidecode
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod +x ~/bin/repo

Change first line from python to python2.7, then initialize and start fetch the Couchbase repository:

mkdir couchbase
cd couchbase
repo init -u git://github.com/couchbase/manifest.git -m released/3.0.1.xml
repo snyc

To prevent failure when building python-based programs, symlink your python to the older one:

sudo ln -sf python2.7 /usr/bin/python

Install older version of v8 (3.21.17 or less), using this command:

yaourt -S v8-3.15
V8PKG=v8-3.19.18.4-1-x86_64.pkg.tar.xz
wget http://seblu.net/a/arm/packages/v/v8/$V8PKG
sudo pacman -U $V8PKG

Then compile the Couchbase:

make

Note if this step failed clean the couchbase first using make clean, then compile the v8 on the v8 folder in the couchbase directory. If you're using latest version of GCC, remove all werror string from build/standalone.gypi and build/toolchain.gpyi file:

make dependencies
export PYTHON=python2
  find build/ test/ tools/ src/ -type f \
    -exec sed -e 's_^#!/usr/bin/env python$_&2_' \
              -e 's_^\(#!/usr/bin/python2\).[45]$_\1_' \
              -e 's_^#!/usr/bin/python$_&2_' \
              -e "s_'python'_'python2'_" -i {} \;
  sed -i 's/python /python2 /' Makefile
sed -i 's/-Werror//' build/standalone.gypi build/common.gypi
make x64.release library=shared console=readline

Alternatively use this modified PKGBUILD file:

wget http://goo.gl/miEmFt -O PKGBUILD
makepkg
sudo pacman -U v8-3.21-3.21.17-1-x86_64.pkg.tar.xz

Don't forget to increase the default number of files:

echo '
*               soft    nofile          65536
*               hard    nofile          65536
' | sudo tee -a /etc/security/limits.conf

And last, start the server:

./install/bin/couchbase-server

Then just visit the web interface to setup the cluster http://localhost:8091/

That's it, that's how you install Couchbase on ArchLinux from source.

2014-11-26

How to start Martini Golang Project

Martini is another Golang web framework, that the design similar to Sinatra, to install it, just type this command:

go get -u -v github.com/go-martini/martini

Then, just create new source code, for example main.go:

package main
import "github.com/go-martini/martini"
func main() {
  m := martini.Classic()
  m.Get("/", func() string {
    return "Hello world!"
  })
  m.Run()
}

To run the website, just type:

go run main.go

Then visit http://localhost:3000/

We must recompile the source everytime the source code changed, that quite annoying and time consuming, to overcome that problem we could use a tool called gin, this program automatically run a program everytime there are code changed. To install this tool, type:

go get -u -v github.com/codegangsta/gin

Then run it using this command:

gin go run main.go

That command would create a proxy, if there are compilation errors, it would also show on the page.

How to install Goclipse and Golang IDEA plugin

Warning: current master version of these plugins (2014-11-25) are not good enough for daily coding, don't bother to try them for now.
Edit: latest alpha version of Golang IDEA plugin for IntelliJ are the best plugin for now.

Goclipse is another IDE for golang, that based on the infamous Eclipse platform. To install Eclipse, just type:

pacman -S eclipse

To install Goclipse, you must first clone the repository, for example using this command:

git clone --depth 1 https://github.com/GoClipse/goclipse.git

Then you must download all dependencies and start building:

cd goclipse
mvn clean integration-test
ant -f releng/ CreateProjectSite
ant -f releng/ PublishProjectSite

Last command would fail when not supplied with correct DprojectSiteGitURL parameter, but the required jars still resides in bin-maven/projectSite/, just use any webserver to serve the files as Eclipse update site, for example using php:

cd bin-maven/projectSite/
php -S localhost:9009

To install Goclipse, open Eclipse, Help > Install New Software..,  just add http://localhost:9009/releases

Then select Goclipse, next, accept the license, and finish.

Now the bad parts: bad coloring (for example, the operator color is not configurable), gocode doesn't work (even when GOPATH and GOROOT already configured on settings page and restarted), and autocomplete doesn't work at all.

Next we'll try IntelliJ with Golang IDEA plugin, first you must clone the repository:

git clone --depth 1 https://github.com/go-lang-plugin-org/go-lang-idea-plugin.git

Then place (or symlink) the IntelliJ program directory inside that folder that created by git, with name idea-IC, then just run:

ant -f build-package.xml

That command would produce a file named: google-go-language.jar, just install that plugin normally using on IntelliJ.

Now the bad parts: member autocomplete doesn't work at all (even when GOROOT and GOPATH configured on settings page and restarted).



2014-11-25

Wide: Web-based IDE for Go

Wide is one new web-based IDE, it has a lot of potential, for now, it has autocomplete and one that have working "go to definition".

To install Wide, type:

go get -u -v github.com/88250/ide_stub
go get -u -v github.com/nsf/gocode
go get -u -v github.com/b3log/wide

To start the program, type:

cd $GOPATH/src/github.com/b3log/wide/
wide

Then visit using your browser on http://your_ip_address:7070


There are some other web-based IDE such as GoDev (lags when showing godoc), LimeText, Carpo, Atom (aur/atom-editor-bin), Brackets.io, and Conception-go (this one not a web-based :3 it's OpenGL)
Btw, I make a list on GoogleDocs to list all Go IDEs, you can contribute/edit it if you want..

2014-11-24

Database GUI for MongoDB

There are many database GUI for MongoDB, today I will review about GenghisApp, Humongous, and RoboMongo.

You could install the Ruby-based one using this command:

gem install humongous
gem install genghisapp bson_ext

to start it, use this command:

humongous # visit http://localhost:9000
genghisapp # visit http://localhost:8000
php -S localhost:8000 genghis.php # php version

to stop it, use this command:

humongous -K
genghisapp --kill

I don't know why but when I tried both, they are not running at all, just stopped after showing "trying port xxxx", those programs closes immediately after that, the program doesn't show up on ps and netstat.

The next in line is RoboMongo, first, you must download using this command:

wget -c http://robomongo.org/files/linux/robomongo-0.8.4-x86_64.tar.gz

Extract it, then run the robomongo.sh shell script on the bin/ folder, set the connection, then it would show up something like this:


This one quote good, it shows the command line when doing any action, but as usual, Java-based app doesn't work well with dark GTK+ theme.

There are some other GUI for MongoDB that support live-monitoring, for example MongoBird and MongOwl, but don't forget, there are also built-in web monitoring on port 28017.

2014-11-15

How to Prevent ISP's DNS Poisoning

The case was, my fourth ISP redirect every DNS request to their own DNS servers, and the poison certain domain names (for example: Manga sites) to their own server (114.127.223.16). How to prevent this? first of all you'll need to install dnscrypt, this program could encrypt DNS requests, so it's become harder to poison.

pacman -Sy dnscrpyt-proxy

then you'll need to start the service:

sudo systemctl enable dnscrypt-proxy
sudo systemctl start dnscrypt-proxy

then, change your /etc/resolv.conf to localhost:

nameserver 127.0.0.1

voila, now your DNS resolving not poisoned anymore :3 yayy~