Memo: How to build MySQL

Memorandum for myself.

Install Lubuntu into Netbook(eeePC 1000H) via USB

Lubuntu image

http://lubuntu.net/

Get, build, and test MySQL

Get source code

http://dev.mysql.com/doc/internals/en/getting-source-tree.html

First, I needed to register and set ssh public key.

https://launchpad.net/people/+me/

ssh-keygen -t rsa
# then, copy ~/.ssh/id_rsa.pub to https://launchpad.net/people/+me/
# after that run the following command
bzr launchpad-login <id>

Then got the source code.

bzr init-repo $HOME/mysql-server
cd $HOME/mysql-server
bzr branch lp:mysql-server/5.7 mysql-5.7

"bzr branzh" somehow wasted huge memory, so I increased the memory of VM I worked on as workaround.

How to build

http://dev.mysql.com/doc/internals/en/cmake-howto-quick.html

# first, needed to install some packages
sudo apt-get install g++
sudo apt-get install libncurses5-dev 
sudo apt-get install bison

# then make
cd $HOME/mysql-server/mysql-5.7
mkdir bld
cd bld
# -DDOWNLOAD_BOOST and -DWITH_BOOST were necessary in this mysql-server version.
# And add -DCMAKE_BUILD_TYPE=Debug for debug configuration
cmake .. -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/tmp/boost
make

References

https://dev.mysql.com/doc/internals/en/index.html

Understanding MySQL Internals: Discovering and Improving a Great Database (English Edition)

Understanding MySQL Internals: Discovering and Improving a Great Database (English Edition)

詳解 MySQL

詳解 MySQL

P2P online co-op shooter game with WebRTC

Introduction

I've implemented a Touhou style shooter game. Its special feature is that you can enjoy P2P co-op play with your friend using WebRTC.

I'll introduce you how to connect with your friend. Try and enjoy!

D

How to connect and begin the game

Requirement

The game requires Windows or Android Chrome. Prolly it cannot work on other environment. The game uses WebGL to fast draw, I'll advice you to turn your hardware acceleration on.

Enter the room

Click the link.

http://takahirox.github.io/toho-like-js/index2.html

Then, you'll be in a random room.

Room number is the number follows '?' in the URL. In the above screen shot, the room number is 8147.

Share the link

Share the room URL with your friend whom you'd like to play the game with. For example, the URL is

http://takahirox.github.io/toho-like-js/index2.html?8147

Connect

When your friend enters the room, "connect" button will be available. If you or your friend push the button, the two are connected using WebRTC and "connected" message is displayed.

Note: When three or more people are in the same room, the button will be disabled because of over capacity. In such a case, move to another room, then try again.

Note: Sometimes connection is failed because of the firewall or some other reasons. In such cases, reload and then try again. When you cannot connect with your friend even if you try many times, I'm afraid you need to give up. Be careful that connection fail isn't notified to you yet. I'm gonna support connection fail detect soon.

Begin the game

After you achieve the connection, you can start the co-op game. Both two select "Start" (push Z) and then choose a character, the game will begin.

Connection practice

If you cannot understand how to connect, you can try local to local connection with two tabs, like the screenshot below.

Hint

If the game is very slow because of network latency, you can try "l=num" option, like this. ("l" is lowercase "L")

http://takahirox.github.io/toho-like-js/index2.html?8147&l=5

"l" controls input lag. "l" is greater, the game can work faster because of input lag hides the network latency (though input lag is bigger). "l" accepts from 1 to 20. The default number is 1. When both you set each "l", the greater "l" will be chosen.

Conclusion

I introduced you how to connect with your friend on my game. Let me know if you achieve the connection and how fast it worked. I need samples.

I'm afraid the game still have some bugs and unimplemented functionalities. desync, no-disconnection-detect, and so on. I'm gonna fix and implement them soon.

BTW, this is the link for single play. Enjoy sole play as well!

http://takahirox.github.io/toho-like-js/index.html

WebRTC performance test on 2D shooter game

I'm making WebRTC performance test on 2D shooter game. Ask me how to use it if you're interested in it because its interface and functionality are not straightforward yet.

http://takahirox.github.io/toho-like-js/webrtc_test.html


I reused WebGL benchmark test on 2D shooter game which I introduced you before.

http://d.hatena.ne.jp/takahirox/20140518/1400388214


And this is the book which I've been reading to master WebRTC.

Real-Time Communication with WebRTC: Peer-to-Peer in the Browser (English Edition)

Real-Time Communication with WebRTC: Peer-to-Peer in the Browser (English Edition)


I wanna make coop play shooter game or something other game, so I've been learning WebRTC and evaluating the performance. Eventually the test began to work, but still wondering how to sync correctly and how to recover from packet loss.

Unfortunately WebGL began not to work on the laptop for development all of sudden prolly due to Chrome update. So the recent progress isn't good, *SIGH* Time to purchase a new laptop now?

JavaScript performance technique experiment 2

calling a bound function and bind() itself is slow

test code. I ran it on Windows chrome.

/* the prototype to compare with */
function A() {
  this.val = 1;
};

A.prototype.func = function() {
  return this.val;
};


/* B is callee and C is caller */
function B(callback) {
  this.callback = callback;
};

B.prototype.func = function() {
  this.callback();
};

/* bind once */
function C() {
  this.b = new B(this.callbackForB.bind(this));
};

C.prototype.func = function() {
  this.b.func();
};

C.prototype.callbackForB = function() {
};


/* D is callee and E is caller */
function D() {
};

D.prototype.func = function(callback) {
  callback();
};


function E() {
  this.d = new D();
};

/* bind for each calling */
E.prototype.func = function() {
  this.d.func(this.callbackForD.bind(this));
};

E.prototype.callbackForD = function() {
};


/* F is callee and G is caller */
function F(caller, callbackFunc) {
  this.caller = caller;
  this.callbackFunc = callbackFunc
};

/* use call() */
F.prototype.func = function() {
  this.callbackFunc.call(this.caller);
};


function G() {
  this.f = new F(this, this.callback);
};

G.prototype.func = function() {
  this.f.func();
};

G.prototype.callback = function() {
};


/* H is callee and I is caller */
function H(id, caller) {
  this.id = id;
  this.caller = caller;
};

/* notify I when be called, like Observer pattern */
H.prototype.func = function() {
  this.caller.notify(this.id);
};


function I() {
  this.h = new H(this._ID_H, this);
};
I.prototype._ID_H = 0;

I.prototype.func = function() {
  this.h.func();
};

I.prototype.notify = function(id) {
  switch(id) {
    case this._ID_H:
      this.funcForH();
      break;

    default:
      break;
  }
};

I.prototype.funcForH = function() {
};


function test(inst) {
  var oldTime, newTime;
  var time;
  var loop = 0x8000000;

  oldTime = Date.now();
  for(var i = 0; i < loop; i++) {
    inst.func();
  }
  newTime = Date.now();
  time = newTime - oldTime;

  console.log(time);
};


var a = new A();
var c = new C();
var e = new E();
var g = new G();
var i = new I();

test(a);
test(c);
test(e);
test(g);
test(i);

result

220
45974
386676
2201
894 

JavaScript performance technique experiment

Introduction

I've been developing some JavaScript applications. Lately I faced with the performance problem.

So, I began to read "High Performance JavaScript" and some useful websites, and decided to optimize the code with some JavaScript performance techniques.

High Performance JavaScript: Build Faster Web Application Interfaces

High Performance JavaScript: Build Faster Web Application Interfaces


First of all, I experimented some techniques. I'll share them here. I ran them on Windows Chrome. You know, the result depends on your environment.

Parent's method call

test code

function __inherit(child, parent) {
  var getPrototype = function(p) {
    if(Object.create) {
      return Object.create(p);
    }
    function f() {};
    f.prototype = p;
    return new f();
  };
  child.prototype = getPrototype(parent.prototype);
  child.prototype.constructor = child;
};


/* the prototype to compare with */
function A() {
  this.val = 1;
};

A.prototype.func = function() {
  return this.val;
};


/* the way I use now */
function B() {
  this.parent = A;
  this.parent.call(this);
};
__inherit(B, A);

B.prototype.func = function() {
  return this.parent.prototype.func.call(this);
};


/* I should use this */
function C() {
  this.parent = A;
  this.parent.call(this);
  this.val = 10;
};
__inherit(C, A);

/* copy the parent method and explicitly call it */
C.prototype.AFunc = A.prototype.func;
C.prototype.func = function() {
  return this.AFunc(this);
};



function test(inst) {
  var oldTime, newTime;
  var time;
  var loop = 0x10000000;

  oldTime = Date.now();
  for(var i = 0; i < loop; i++) {
    inst.func();
  }
  newTime = Date.now();
  time = newTime - oldTime;

  console.log(time);
};

var a = new A();
var b = new B();
var c = new C();

test(a);
test(b);
test(c);

result

967
6150
1284 

Global variable vs local variable

test code

/* the way I use now */
function A() {
  this.val = 1;
};
A.PI = Math.PI;

A.prototype.func = function() {
  return this.val * A.PI;
};


/* I should use this way or */
function B() {
  this.val = 1;
  this.pi = Math.PI;
};

B.prototype.func = function() {
  return this.val * this.pi;
};


/* this way */
function C() {
  this.val = 1;
};
C.prototype.PI = Math.PI;

C.prototype.func = function() {
  return this.val * this.PI;
};


function test(inst) {
  var oldTime, newTime;
  var time;
  var loop = 0x100000;

  oldTime = Date.now();
  for(var i = 0; i < loop; i++) {
    inst.func();
  }
  newTime = Date.now();
  time = newTime - oldTime;

  console.log(time);
};

var a = new A();
var b = new B();
var c = new C();

test(a);
test(b);
test(c);

result

496
7
7

Push vs index

test code

function test() {
  var oldTime, newTime;
  var time;
  var loop = 0x1000000;
  var val, val2;

  var array = [];
  var array2 = [];

  oldTime = Date.now();
  for(var i = 0; i < loop; i++) {
    array.push(i);
  }
  newTime = Date.now();
  time = newTime - oldTime;
  console.log(time);

  oldTime = Date.now();
  for(var i = 0; i < loop; i++) {
    array2[i] = i;
  }
  newTime = Date.now();
  time = newTime - oldTime;
  console.log(time);
};

test();

result

2430
686

Conclusion

I showed three techniques which improves performance about 4-70x. I have some guesses why they improve(for example, reduce the scope chain traversing), but I mention it after I certainly learn JavaScript specification and JavaScript engines.

Anyways, I'm very annoyed because I realized that I need to modify almost all my codes to improve the performance. Hahaha.... Nahhhh

BTW, my NES emu with JavaScript began to work. Enjoy!

https://github.com/takahirox/nes-js