Q4M is a message queue implemented as a pluggable storage engine of MySQL.
Thanks to the helps from @laysakura; and @kamipo I have finally added to Q4M support for MySQL 5.5 / 5.6 in 0.9.8.
After releasing 0.9.8 I have noticed that a bug was introduced in 0.9.7 that may cause crashes and/or data losses when accessing tables created under previous versions of Q4M.
If you are using either 0.9.7 or 0.9.8 (that were upgraded from any previous version of Q4M), I recommend you to run the queue_compact(tbl_name) function against all existing Q4M tables to avoid the issue. Sorry for the inconvenience.
If you are an existing user of 0.9.6 or an earlier version, please upgrade directly to 0.9.9.
--- Japanese Translation (in brief) ---
Q4M 0.9.7 と 0.9.8 には、それら以前のバージョンで作成されたテーブルデータにアクセスが発生した場合に、クラッシュあるいはデータロスが発生する可能性をもつバグが存在します。
このバグは、queue_compact(tbl_name) 関数を全ての Q4M テーブルに対し適用することで回避できますので、いずれかのバージョンをアップグレードとしてインストールした場合は、そうされることを推奨します。
また、0.9.6 以前をお使いの方がアップグレードされる際には、0.9.9 以降へ一気にアップグレードすることをお勧めします。
ご不便をおかけし申し訳ありません。
Kazuho's Weblog
Wednesday, March 27, 2013
Friday, February 15, 2013
Wednesday, January 30, 2013
Writing fast, processor-independent code using C++ and LLVM bitcode
Using inline assembly along with C/C++ code has long been the best choice for developers writing optimized code. However the approach had its shortcomings:
- the need to write assembly for each architecture
- the use of inline assembly hinders certain compiler optimizations (such as register allocation)
But thanks to LLVM it is now possible to write processor-independent assembly functions using its bitcode, and use its link-time optimizer to get the function expanded in-line into C/C++ code.
I have created an example that shows how to implement fast integer arithmetics (with overflow detection) in C++, which is available at github.com/kazuho/add_with_overflow.
It uses a bitcode-level intrinsic called "llvm.sadd.with.overflow.i32" (that gets inlined) to implement integer addition with overflow check.
With the example, the source code
As can be seen, the generated code is highly optimized. Not only does it use the JNO instruction, the source operand of ADDL is placed on stack (which would be faster than on register since the value is never again being referred to). Such kind of an optimization has been impossible with inline assembly of GCC (that requires the arguments to be loaded on registers).
Since the output (after inline expansion) is a .s file (processor dependent assembly), it is possible to link the optimized code using other linkers as well.
Note: the work is based on Fast integer overflow detection - Xi Wang, and I would like to thank the author for his excellent work.
Note 2: Since the bitcode instructions might change in the future, it might be a good idea to limit the length of the functions written in bitcode as short as possible.
- the need to write assembly for each architecture
- the use of inline assembly hinders certain compiler optimizations (such as register allocation)
But thanks to LLVM it is now possible to write processor-independent assembly functions using its bitcode, and use its link-time optimizer to get the function expanded in-line into C/C++ code.
I have created an example that shows how to implement fast integer arithmetics (with overflow detection) in C++, which is available at github.com/kazuho/add_with_overflow.
It uses a bitcode-level intrinsic called "llvm.sadd.with.overflow.i32" (that gets inlined) to implement integer addition with overflow check.
With the example, the source code
if (! add_with_overflow(&ret, x, y))gets compiled into
addl 8(%rsp), %esi jno LBB1_4
As can be seen, the generated code is highly optimized. Not only does it use the JNO instruction, the source operand of ADDL is placed on stack (which would be faster than on register since the value is never again being referred to). Such kind of an optimization has been impossible with inline assembly of GCC (that requires the arguments to be loaded on registers).
Since the output (after inline expansion) is a .s file (processor dependent assembly), it is possible to link the optimized code using other linkers as well.
Note: the work is based on Fast integer overflow detection - Xi Wang, and I would like to thank the author for his excellent work.
Note 2: Since the bitcode instructions might change in the future, it might be a good idea to limit the length of the functions written in bitcode as short as possible.
ラベル:
C++,
in English
Thursday, July 5, 2012
エンジニアは「NoSQL万歳」と言う前に「Webエンジニアのための データベース技術[実践]入門」を読むべき (献本御礼)
しょっぱなから話がずれますが、最近「[翻訳]MVCは死んだ。MOVEするときがきた - きしだのはてな」という記事が話題になっています。一方で、この記事に対しては、
MVCへの不適切な理解から導き出されたずれた認識に見えます。MVCを否定する理由にはとてもあたらないどころか、この人が学んだMVCはMVCではなく、MVCフレームワークの使い方であった事がよく解る
MOVEは望まれなかった子 - the sea of fertility
といった批判もなされています。
僕は、結果としていいものが作られるなら無知でもいいじゃない、と思うのですが、まあこのような知識不足による誤解というのは良くあることです。
実際、「RDBMSは死んだ。NoSQLの時代がきた」と主張する人に耳を傾けてみると、その人が知っているのはRDBMSではなく、MySQL(しかも古いバージョン)の使い方だった、なんてこともあります。
逆に、なにかを主張してみたら、実はそれが僕の知識不足による誤った意見だった、ということもあります。
そのような無駄を、どう省くか。
各分野の、いい教科書を読む、というのが良い解だと思います。
たとえば、以前、前職のブログで言及(「Kazuho@Cybozu Labs: REST におけるトランザクションについて (Re: Web を支える技術)」)した「Webを支える技術」は、HTTP, REST 分野での教科書的な一冊だと思います。
MySQL の専門家である松信氏によって書かれた同書は、リレーショナルデータベースの理論から始まり、MySQLの実装に関する議論を経て、ビッグデータ時代にデータベースがどのように変化していくかまでをカバーしており、我々現場で働くウェブエンジニアにとって、とても良い教科書になっていると思います。
氏は自書を紹介するにあたり、
小手先のツールが使えようが何だろうが、基本を知らん奴はトラブルの現場では何もできやしない、ということで、データベース技術の歴史を振り返り基礎をおさえたい方におすすめです。
Open database life: 新著「Webエンジニアのための データベース技術[実践]入門」
と書かれていますが、これは上に述べたように「トラブルの現場」に限らず「発明の現場」においても同様だと思います。
このような優れた教科書を読み、知識を共有することで、我々ウェブエンジニアは、より生産的な議論と開発に関わることができるようになるはずです。
PS. あなたのオススメの教科書はありますか? よかったら教えて下さい
このエントリは @naoya_ito さんの tweet にインスパイヤされています
Saturday, February 4, 2012
Re: 縁故採用の良し悪しと岩波書店の英断
「縁故採用の良し悪しと岩波書店の英断 - 雑種路線でいこう」を読んで違和感を感じたのでメモ。
傍論かもしれませんが、企業が淘汰されるから採用基準が自由でいい(あるいは公的機関において縁故採用がダメなのは企業間競争がないから)という論理はおかしいんじゃないか。
労働関連の法律があるのは、雇用者との関係で弱者の立場になりがちな労働者を保護するためじゃないか。そして、労働者の中でも弱者になるのが「世の中の仕事で特別に高い能力を発揮することが求めら」れない仕事をする労働者。
法定労働時間にしても最低賃金にしても、そういう労働者を保護するためのものでしょう。
次に、採用における慣行を公表するのがいいかどうかについて。
たとえば児童労働の禁止。小学生が親の八百屋を手伝っていても誰も文句を言わないけど、マクドナルドの店頭に「小学生雇います」ってポスターが貼ってあったら問題になるでしょう。
あるいは、男女雇用機会均等法。現実問題として、性別をみて採用不採用はあるけど、それでも建前として雇用機会の均等がなければ、ここまで女性の社会進出は進まなかったのでは?
つまり何が言いたいかというと、社会としての建前と個人の本音を使い分けることで、社会が前に進んできている面もあるということ(そして社会的影響の大きな企業ほど、建前を大切にしてきた)。
以上より、岩波書店の一件については公言した以上、労働者保護の観点からどうなの?という質問は出るべきだと思うし、そういう問題意識をぶつけた記者さんはGJだと思いました。
ラベル:
その他
Saturday, October 15, 2011
Unix Programming with Perl 2 (my slides at YAPC::Asia 2011)
Today's slides are here:
Unix Programming with Perl 2
View more presentations from kazuho.
Last year's slides are here:
Unix Programming with Perl
View more presentations from kazuho
ラベル:
in English,
perl
Tuesday, September 27, 2011
mysql_json - a MySQL UDF for parsing JSON
Somewhat related to (or rather not related to) やったーJavaScriptの動くMySQLできたよー - 愛と勇気と缶ビール, I have written a MySQL UDF that parses JSON strings.
The UDF introduces one function: json_get, that parses a JSON object or an array and returns one of the properties.
SELECT json_get('{"a":1}', 'a') => 1
SELECT json_get('{"a":1}', 'b') => NULL
SELECT json_get('[1,2,3]', 2) => 3
SELECT json_get('{"a":[2]}', 'a', 0) => 2
By using to the UDF it is possible to write queries accessing the properties of JSON objects stored in MySQL.
SELECT json_get(data,'title') FROM message WHERE id=1;
SELECT id,data FROM message WHERE json_get('data','from')='hidek';
Source code of the UDF can be found at github.com/kazuho/mysql_json. The installation process may vary, but I did the following for my ubuntu server.
% g++ -shared -fPIC -Wall -g mysql_json.cc -o mysql_json.so % sudo cp mysql_json.so /usr/lib/mysql/plugin % mysql -u root mysql> create function json_get returns string soname 'mysql_json.so';
ラベル:
in English,
mysql
Subscribe to:
Posts (Atom)