@h12.io

A Manager's FAQ

3 July 2016

This is an insightful list from Henry Ward:

  • How do I get employees to perform better? Tell them what they are doing well.
  • How do I give negative feedback? By being curious.
  • How do I decide what to delegate? Delegate the work you want to do.
  • How should I prioritize? Fix problems. Then prevent problems.
  • How should I grade employees? Don’t. Teach them to self-evaluate.
  • When do I fire somebody? When you know they can’t succeed.
  • How do I fire somebody? By apologizing for our failures.
  • Why can’t I just tell people what to do? Because the more responsibility you have, the less authority you have.
  • How do I know if I am a good manager? Employees ask you for advice.
  • How do I know if I have good management team? Shit rolls uphill.

On Reliable Persistence

2 July 2016

A short investigation on reliable persistence:

  • Crash consistency is hard but possible at a huge performance cost

  • Data safty must rely on distributed solution

  • Perhaps we should just give up manual fsync and rely on

    • OS background flush
    • corruption detection & correction at startup
    • replication

Note on OpenWRT

27 February 2016

Obtain OpenWRT

  • Find the device model at the Table of Hardware (Huawei HG556a C)
  • Open Device Techdata for Firmware OpenWrt Install URL
  • Open Device Page for Installation instructions

Computer - Cable - Router

Connect the computer to the router with a cable.

Install OpenWRT

Follow the instructions to install OpenWRT.

SSH

First login:

telnet 192.168.1.1

Change password to enable SSH:

passwd
exit

For public key authentication, add the public key:

ssh-copy-id [email protected]
ssh [email protected]
mv ~/.ssh/authorized_keys /etc/dropbear
exit

WiFi

In /etc/config/wireless:

config wifi-device  radio0
	......
	# REMOVE THIS LINE TO ENABLE WIFI:
	# option disabled 1

config wifi-iface
	option device     radio0
	option network    lan
	option mode       ap
	option encryption psk2
	option hidden     1
	option ssid       [SSID]
	option key        [WiFi password]
	option macaddr    [00:0A:4B:3C:6D:02]

Execute:

wifi

Computer - WiFi - Router

Disconnect the cable to the router. Try SSH via WiFi.

Internet

In /etc/config/network:

It is better to change the lan address so that it will not be conflicted with the upstream address.

config interface 'lan'
	option ipaddr '192.168.2.1'
# lan switch
config switch_vlan
	option device 	eth0
	option vlan 	1
	option ports 	"1 2 5t"

# wan switch
config switch_vlan
	option device 	eth0
	option vlan 	2
	option ports 	"0 5t"

For DHCP wan:

config interface wan
	option ifname eth0.2
	option proto  dhcp

For PPPOE wan:

config interface wan
	option ifname   eth0.2
	option proto    pppoe
	option username [PPPOE user name]
	option password [password]

Computer - WiFi - Router - Cable - Internet

Connect the internet cable to the router, reboot the router.

About Pretty Printing

1 February 2016

JSON

cat xxx.json | jq .

XML

cat xxx.xml | xmllint --format -

Sending Email from Gmail using Go

31 January 2016
  1. Turn on “2-Step Verification” so that an “App password” can be generated

  2. go get gopkg.in/gomail.v2

  3. Send your Email like the example below:

package main

import (
	"gopkg.in/gomail.v2"
)

func main() {
	m := gomail.NewMessage()
	m.SetHeader("From", "[email protected]")
	m.SetAddressHeader("To", "[email protected]", "to_name")
	m.SetAddressHeader("Cc", "[email protected]", "cc_name")
	m.SetHeader("Subject", "Hello! TEST!")
	m.SetBody("text/html", "Hello! <b>TEST</b>!")

	d := gomail.NewPlainDialer("smtp.gmail.com", 587, "[email protected]", "the App password")

	if err := d.DialAndSend(m); err != nil {
		panic(err)
	}
}

SSH Resources in Go

31 January 2016
  • golang.org/x/crypto/ssh
  • github.com/YuriyNasretdinov/GoSSHa

Articles:

SEJ: Message Queue Based on Segmented Journals

14 November 2015

h12.io/sej provides composable components of distributed, persisted message queue and allows trading off between reliablilty, latency and throughput with minimal devops overhead.

Package Organization

  • h12.io/sej: writer, scanner and offset
    • shard: sharding
    • hub: copying across machines
    • cmd/sej: command line tool

SEJ Directory

[root-dir]/
    [sej-dir]/
        jnl.lck
        jnl/
            0000000000000000.jnl
            000000001f9e521e.jnl
            ......
        ofs/
            reader1.ofs
            reader1.lck
            reader2.ofs
            reader2.lck
            ......

Journal File format

segment_file = { message }                          .
message      = offset timestamp type key value size .
offset       = uint64                               .
timestamp    = int64                                .
type         = uint8                                .
key          = key_size { uint8 }                   .
key_size     = int8                                 .
value        = value_size { uint8 }                 .
value_size   = int32                                .
size         = int32                                .

All integers are written in the big endian format.

name description
offset the position of the message in the queue
timestamp the timestamp represented in nanoseconds since Unix Epoch
type an int8 value that could be used to indicate the type of the message
key the encoded key
value the encoded value
size the size of the whole message including itself, allowing reading backward

Writer

  • Append from the last offset in segmented journal files
  • File lock to prevent other writers from opening the journal files
  • Startup corruption detection & truncation

Scanner

  • Read from an offset in segmented journal files
  • Change monitoring
    • directory
    • file append
  • Handle incomplete last message
  • Truncation detection & fail fast
  • Timeout

Offset

  • First/last offset
  • Offset persistence

Sharding

[root-dir]/
    [shard0]/
    [shard1]/
    ......

Each shard directory is a SEJ directory with a name in the form of [prefix].[shard-bit].[shard-index].

  • prefix must satisfy [a-zA-Z0-9_-]*
  • when prefix is empty, [prefix]. including the dot is omitted
  • shard-bit: 1, 2, …, 9, a
  • shard-index: 000, 001, …, 3ff

Hub

[root-dir]/
    [client-id0].[shard0]/
    [client-id1].[shard0]/
    ......

client-dir is the SEJ directory name belonging to a client.