Category Archives: design

Dockerfile CMD requires foreground command

Start a docker container with below Dockerfile. Since it has CMD [“nginx”]. The docker container exists after nginx command is finished. It couldn’t be connected even with –detach mode. In order to keep the docker container running, needs the CMD run in foreground. Let it keep running. So it needs a “daemon off” in nginx.conf… Read More »


jenkins start/stop Create Jenkins pipeline with Freestyle project

TPS = connections / latency

If one connection supports 5TP, then 5 connection supports 25TPS. In another word, if a connection supports 5TPS, that means request latency is 200ms. We have: TPS = number_of_connection / request_latency So TPS relates to TPS per connection and number of connection. How to find max TPS? set connection to 1, literally increase TPS from… Read More »

Read-after-write model vs eventually consistency model

Below is the read-after-write model: GET /key-prefix/cool-file.jpg 404 PUT /key-prefix/cool-file.jpg 200 GET /key-prefix/cool-file.jpg 200 As we can see, file doesn’t exist at beginning. As long as PUT is done, GET always return successfully. Below is eventually consistency model: GET /key-prefix/cool-file.jpg 404 PUT /key-prefix/cool-file.jpg 200 GET /key-prefix/cool-file.jpg 404 File doesn’t exist, after PUT is done, GET… Read More »

Proxy Pattern

Instead of interact with direct resource, client interacts with proxy, then proxy interacts with real resources. Reasons could be: cache, security, encapsulation(http). A proxy has same interface as the original class. In this case, the proxy has same behavior as original class. Adaptor changes the interface. Facade enhances the interface. In below graph: RealSubject implements… Read More »

HEAD detached

You may have below after git log: commit f6601f5ae74d5b61303b17f1edcb56a6755c18ea Commit message commit 1e98a15d9a182ba965955bc960fa394a3de5c36a Commit message… git branch shows: 8c85904323f8:AlexaMacawDeciderService lipl$ git branch * (HEAD detached from refs/heads/lipl-branch-name) branch1 branch2 branch3 mainline Also it shows HEAD detached. It is good time to create a branch and specify most recent commit: git branch new-branch-name f6601f5ae74d5b61303b17f1edcb56a6755c18ea Thus, git branch shows… Read More »

Visitor pattern

1. Visitable public interface Visitable { int accept(Visitor visitor); } 2. ConcreteVisitable public class LiquorVisitable implements Visitable { @Override int accept(Visitor visitor) { return visitor.visit(this); } } public class FoodVisitable implements Visitable { @Override int accept(Visitor visitor) { return visitor.visit(this); } } 2. Visitor public interface Visitor { int visit(LiquorVisitable liquorVisitable); int visit(FoodVisitable foodVisitable); }… Read More »

2PC, 3PC

There are two basic distributed transaction protocols: two-phases-commit and three-phases-commit. two-phase-commit Assumption, coordinator and cohorts are never down. If coordinator is down, all other cohorts will be blocking and waiting for its recover. If a cohort is down and when it wakes up, it will get notified by coordinator(commit or rollback). 3-phase-commit For 3PC, coordinators… Read More »

Some feeling about GAE performance

A web service is deployed in GAE(google app engine). This is the loading test on GAE with different core, concurrency combinations. 1 core, 1 thread, 0.3s per reqeust 1 core, 160 threads, 12s per request 1 core, 150 threads, 8s per request 8 core, 50 threads, 5s per request 16 core, 50 threads, 3s per… Read More »

D3MAP example

I came across a project about d3map recently. The idea of the project is to parse the [longitude, latitude] of a location in USA, and show it on the USA map. Here are some example of this techniques: USA county map USA states map Circle Animation USA states with different color