Category Archives: develope

Use recv() instead of read() for socket

When we use read() to read data from a socket like:

the read() may return ‘ret’ which is small than sizeof(struct msg) even the socket is not O_NONBLOCKING. The correct way is:

Then, recv() will wait util all sizeof(struct msg) be read out.

A example of Mesos Python Framework to calculate Pi

I have written an example of Mesos Framework by python. It simply calculate “Pi” by using Mento-Carlo algorithm The whole source code is at https://github.com/RobinDong/mesos-python-examples/tree/master/calculate_pi At beginning, I use python threading in “launchTask()”:

But I found out that the executors only spend a small part of CPU resource in… Read more »

Override the __init__ of BaseHTTPRequestHandler in python

Currently, I am writing some python program for the front of our storage system. By using ‘BaseHTTPRequestHandler’ and ‘ThreadedHTTPServer’, we could implement a simple multi-thread http server quickly. But after add ‘__init__()’ for our ‘MyHandler’, it doesn’t work correctly now:

Then I found this statement in python docs:

Read more »

128bit atomic operation in arm64

In x86_64 architecture, we could use cmpxchg16b to compare and exchange a 128bit value in one atomic operation. But how to operate a 128bit value in aarch64 architecture (arm64) machine ? The answer is __atomic_compare_exchange(). As below code:

use “gcc test.c -o test” to compile code, but it reports:… Read more »

Run aarch64 binary on x86_64 machines

If we use qemu-arm64-system directly, it will cost too much time on IO and systemcalls.So I try to use SuSE’s userpsace mode qemu, which only reinterprets the arm64 instructions to x86_64 but processes all systemcalls to local host. This installation manual for user-mode qemu-arm64 has tested on debian-7.7.0 Step 1,… Read more »

Running Django in docker

      4 Comments on Running Django in docker

I am trying to learn Django (a python framework for developing web) in docker container recently. After running the docker with port redirect

The output of Django server is

Then I use command sudo docker ps to find out the port number for host machine:

but when… Read more »