2021/03,江端さんの技術メモ

https://www.meti.go.jp/meti_lib/report/H30FY/000677.pdf

 

マイクロトランジッド

 

Chariot (サンフランシスコ周辺など)
• フォードが買収した通勤者向けの乗合バスサービス
• 利用者数に基づく柔軟なルート設定に特徴
• 14人乗りのシャトルバスを利用し、1日当たり100を超える路線
でサービス提供
出所: Tech Crunch, Chariot
Via (ニューヨーク、ワシントン、シカゴ 等)
• 乗客と車両の座席とをリアルタイムに関連づけ、同一ルートで
移動できる乗客をグループ化して配車する乗合バスサービス
• 車両の最適なルートに合わせて、利用者の乗降車スポットを
自動的に指定する仕組み
• テキサス州アーリントン市と提携。市の補助で運賃3ドルで運行

2021/03,江端さんの忘備録

コールバックを作ることは、そんなに難しくないんですよ。同じ言語でしたらね。

It's not that difficult to create a callback. As long as it's in the same language.

でもね、GOとC++の間で共通するトリガーイベントを作る方法が ―― 今日、一日、世界中を探し回ったんですけど ―― 見つけられないんですよ。

But you know, I can't find a way to make trigger events common between GO and C++ -- I've been looking all over the world today -- and I can't find it.

ならば、UDPとかTCPとかで待ち受けすれば良い、と。うん、まあ、それは分かるのですけどね。実際にライブラリも作っちゃったし。

So, why don't I just use UDP or TCP to listen in? Yeah, well, I understand that. I've actually made a library for it.

でもね、稼動オブジェクト1万個を同時に接続するUDPなんぞをやったら、一瞬でソケットリソースが使い尽されてしまうでしょう。実際、先月、これでプログラムを落したし。

But I know, if I do a UDP connection with 10,000 active objects at the same time, I'll run out of socket resources in an instant. In fact, I had a program go down last month because of this.

で、一番いいのが、GOのチャネルを使う方法なんですけど、これを、C++に連携させる方法が ―― ない。

So, the best way to do this is to use the GO channel, but there is no way to link this to C++.

GOのライブラリをリンクしたC++のライブラリをリンクした、GOプログラムを動かせればいいんだけど、昨日の試作では、ことごとく失敗した訳です。

It would be nice to be able to run a GO program with a C++ library linked to the GO library, but yesterday's prototype failed at every step.

もちろん、ポーリングすればいいだけのことですよ。サンプリング1秒でも、大した負荷にはならないでしょう。

Of course, I will use "polling" methods. One second of sampling won't be much of a load.

でも、それって『かっこ悪い』よね?

But that's not 'cool', is it?

プログラムのコールをどう実装しようが、私以外の人は知り得ないことですよ ―― でも、『この私』が納得していないんです。

No one but me can know how to implement the calls in the program -- but 'I' am not convinced.

ここ重要です。

This is important.

-----

という訳で、昨日は、朝から深夜に至るまで、この機能を実現する為に、頭を抱え続けて、そして失敗しました。

So yesterday, from morning till late at night, I kept trying to figure out how to make this work, and I failed.

今日は、仕上げなければならない論文ドラフトがあるので、この問題を考えることは一旦中止します。

I have a draft paper I need to finish today, so I will stop thinking about this issue for now.

悔しいので、メモだけ残しておいて、後日の復讐戦に備えます。

It's frustrating, so I'll just leave a note and prepare for the revenge battle later.

2021/03,江端さんの技術メモ

C 言語から GO 言語の関数を呼ぶ方法

を参考にさせて頂いて、実験中です。

大変申し訳ありませんが、ほぼ丸パクりさせて下さい。これから、頻繁に見る必要があり、万一ページがexpiredされたら青冷めますので。

hoge.goというファイル名のPrintHoge関数を C 言語から呼べるようにします。

  1. Cをインポートする
  2. C 言語から呼びたい関数に//export XXXXを書く (普通、//とするとコメントなんだけどなぁ)
  3. コンパイルする
package main

import (
    "C"
    "fmt"
)

//export PrintHoge
func PrintHoge() {
    fmt.Println("hoge")
}

func main() {}

main関数がないとエラーになるので、空で良いので書いておきます。

-buildmode=c-archiveオプションをつけてgo buildします。

$ go build -buildmode=c-archive hoge.go

すると、hoge.aアーカイブとhoge.hヘッダが生成されます。

生成されたヘッダをインクルードして、Go 言語の関数を呼びます。

#include <stdio.h>
#include "hoge.h"

int main() {
    PrintHoge();
    return 0;    
}

生成されたアーカイブと一緒にコンパイルします。

$ gcc -o hoge hoge.a main.c

ところが、

$ gcc -o hoge hoge.a main.c
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w6
4-mingw32/bin/ld.exe: C:\Users\ebata\AppData\Local\Temp\cc1F3Mbe.o:main.c:(.text
+0xe): undefined reference to `PrintHoge'
collect2.exe: error: ld returned 1 exit status

が出てきて、「変だなー」と思いつつ、色々調べてみたのですが、hoge.aを一番最後にしたら、動きました。

$ gcc -o hoge main.c hoge.a
$ ./hoge
hoge
以上

2021/03,江端さんの技術メモ

■外部から強制的に書き込もうとすると失敗します

ubuntu@ip-172-26-7-19:~/codes/xxxxxxx_ride_hailing_go$ docker ps

095fe60f02cc nginx:1.15-alpine "nginx -g 'daemon of…" 8 weeks ago Up 22 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp xxxxxxx_ride_hailing_go_nginx_1

でもって、

ubuntu@ip-172-26-7-19:~/codes/xxxxx_ride_hailing_go$ sudo docker cp fullchain.pem 095fe60f02cc://etc/nginx/conf.d/

Error response from daemon: Error processing tar file(exit status 1): unlinkat /etc/nginx/conf.d/fullchain.pem: device or resource busy (失敗します)

しかし、dockerの中に入って、

ubuntu@ip-172-26-7-19:~/codes/xxxxxx_ride_hailing_go$ docker exec -i -t xxxxx_ride_hailing_go_nginx_1 sh

で内側から、killすると、dockerごとダウンして、なんとも悩ましい、にわとりと卵の関係になってしまいます。

■解決方法

ubuntu@ip-172-26-7-19:~/codes/xxxxxxx_ride_hailing_go$ sudo docker cp fullchain.pem 095fe60f02cc://etc/nginx/conf.d/fullchain.pem.new

ubuntu@ip-172-26-7-19:~/codes/xxxxxxx_ride_hailing_go$ sudo docker cp privkey.pem 095fe60f02cc://etc/nginx/conf.d/privkey.pem.new

でもって、 (今後は、new2, new3, new4 とか、どんどん増やしていく)

ubuntu@ip-172-26-7-19:~/codes/xxxxxxx_ride_hailing_go$ vi nginx.conf

をして、

———————————————————

ssl_certificate /etc/nginx/conf.d/fullchain.pem.new;

ssl_certificate_key /etc/nginx/conf.d/privkey.pem.new;

———————————————————

と書き換える。

さらに、

docker-compose.yml の最後の行に、

volumes:

- "./nginx.conf:/etc/nginx/conf.d/default.conf"

- "./fullchain.pem:/etc/nginx/conf.d/fullchain.pem.new"

- "./privkey.pem:/etc/nginx/conf.d/privkey.pem.new"

も変える。

でもって、 docker-compose stop; docker-compose start をすれば、新しい鍵で動き出します。不細工ではありますが、プログラムは動くようになります。

■ところで今思いついたんだけど、いい方法がありました。

現在は、fullchain.pem.new と、privkey.pem.new で動いているのだから、fullchain.pem と、privkey.pemは、rm できるはず。

で、cp fullchain.pem.new fullchain.pem, cp privkey.pem.new privkey.pem として、さらに、nginx.confの設定を元に戻せば、fullchain.pem と、privkey.pem の名前を使えるはずです

(まあ、動いているので、今は、このままにしています)

■もっと、いい方法がありました。

docker-compose.yml の最後の行に、

volumes:

- "./nginx.conf:/etc/nginx/conf.d/default.conf"

- "./fullchain.pem:/etc/nginx/conf.d/fullchain.pem"

- "./privkey.pem:/etc/nginx/conf.d/privkey.pem"

の3行を加えれば、Dockerの外側に、最新の"fullchain.pem"と、"privkey.pem"を置いておけば、自動的にDockerコンテナの中に取り込まれます(今、そうなっている)

2021/03,江端さんの技術メモ

Go言語をVSCodeを使ってデバッグをしようとするとすると以下のメッセージが出てきて、困っていました。

"Failed to continue: Check the debug console for details."

が消えなくて、困っていたのですが、

// +build ignore
package main

の "// +build ignore"を消したら、消えました。

 

 

2021/03,江端さんの忘備録

BS世界のドキュメンタリー「ヒトラーの子どもたち」を見ました。

I watched the BS World Documentary "Hitler's Children".

一言で言えば、「特定人種(アーリア民族)の子ども量産計画」です。

In a word, it is a "plan to mass-produce children of a specific race (Aryan race).

かの独裁者の理念『第三帝国の千年王国』に基づく(特定民族の絶滅計画と同時に実施された)計画の一つです。

This is one of the plans (implemented at the same time as the plan for the extermination of certain ethnic groups) based on the dictator's idea of the "Thousand Year Kingdom of the Third Reich.

-----

かなり前に、このようなイラストを描きましたが、その番組では、本当にこのイラストそっくりの映像が出てきて、軽い嘔吐感を覚えました。

A long time ago, I drew an illustration like this one, and in that program, I really saw an image that looked exactly like this illustration, which made me feel mildly nauseous.

もちろん、1940年の当時は、「試験管ベイビー」も「クローン」の技術もありませんでした。

Of course, back in 1940, there were no "test tube babies" or "cloning" technology.

ですので、、生身の男女を生殖させる場所「レーベンスボルン(生命の泉)」をドイツ国内、そしてフランスに設けて、子どもを「生産」していました。

Therefore, "Ravensborn" (fountain of life) were established in Germany and France to "produce" children, where reproduction took place between living men and women.

-----

日本でも、戦前・戦中の出産数は多いです。

In Japan, the number of births before and during the war is also high.

衛生、社会インフラ、医療技術で死亡リスクが高く、また、「富国強兵」の観点から、出産が「産めよ、殖やせよ」と国策的に奨励されていたことが要因です。

This was due to the high risk of mortality in terms of sanitation, social infrastructure, and medical technology, as well as the fact that childbirth was encouraged by national policy to "give birth and reproduce" from the perspective of a "wealthy nation with a strong military.

『平均5児以上をもうける』("平均"というところが凄い)

"Have an average of five or more children" (the "average" part is amazing)

という、現在では「夢物語か?」というようなことが政策として組込まれ、そして、律儀な日本国民は、これを達成していました。

"Is this a pipe dream?" of today, was incorporated as a policy, and the Japanese people, who were disciplined, had accomplished this.

そして、当時の政府は、多子家庭に対しての優遇策を、無子家庭や独身者には冷遇策を課していました。

And the government at that time imposed preferential treatment for families with many children, and cold treatment for families with no children and single people.

-----

正直、「レーベンスボルン(生命の泉)」も「産めよ、殖やせよ」も、私はゴメンです。

To be honest, I like neither "Ravensborn" (the fountain of life) nor "Give birth, breed.

「国家権力の圧力で、子どもを量産する社会」なんぞを目にするくらいなら ――

I don't want to see a society that mass-produces children under the pressure of state power.

「個人の自由意志で、少子高齢化で朽ちていく国家」に立合い続ける方が、私はいいです。

I would rather continue to watch the nation decay with declining birthrates and aging population at the free will of individuals.

2021/03,江端さんの忘備録

今日は、長女の卒業式ですが、保護者は会場に入れませんでしたので、近くの公園で写真撮影をしました。

Today is my senior daughter's graduation ceremony, but parents were not allowed in the hall, so we took pictures at a nearby park.

次女が、袴で装った長女とその家族を写した枚数は、現時点で確認されているだけで、251枚です。

The junior daughter took 251 photos of the senior daughter dressed in hakama and her family dressed as of now.

-----

私が、30年前に、20日間、中国大陸を放浪した時の写真は、フイルム6巻、合計 96枚

When I wandered around mainland China for 20 days 30 years ago, I took 6 rolls of film with a total of 96 photos.

15日間、ネパールとインドを移動していた時の枚数も、ほぼ同数でした。

The number of picture during the 15 days I was traveling between Nepal and India was almost the same.

私の35日間分の写真枚数(約200枚)を、次女は、1時間弱で軽く越えました。

In less than an hour, my junior daughter took more photos than I did in 35 days (about 200).

-----

空港のセキュリティチェックでX線によってフィルムが感光するのを防ぐために、これらのフィルムは鉛入りの袋に入れて運びました。

In order to prevent the film from being sensitized by x-ray rays at airport security checks, these films were packed in leaded bags and transported.

当時の中国では、写真撮影をする場所(軍事施設の近くとか)にも、随分気を使ったものです(今も、かもしれませんが)

In China at that time, I was very careful about where I took photos (near military facilities, etc.) (although this may still be the case).

-----

今では、膨大な写真の中から、手元に残す「ベストショット」を選ぶ作業が大変そうです(特に、嫁さんが)

Nowadays, it seems to be a difficult task to choose the "best shot" to keep in hand from the huge number of photos (especially for my wife).

2021/03,江端さんの忘備録

TVアニメ「ホリミヤ」は、次女が絶賛のアニメです。

The TV anime "Horimiya" is an anime that my second daughter is raving about.

私は、アニメだけでなく、エンディングの3DCG(Three Dimensional Computer Graphics)も気に入っています(注 Youtubeにリンクします)。

I like not only the animation but also the 3DCG (Three Dimensional Computer Graphics) of the ending.

-----

3D技術については、Unidyとか、WebGLとか、私もそこそこその技術については知っていますし使ってもいますが、

As for 3D technology, I know and use Unidy, WebGL, and other technologies.

―― "3DCG"を、サイドエフェクトではなくて、メインコンテンツとした作品

As "a work that uses 3DCG as the main content, not as a side effect"

として、「いいなー」と思っています。

I think it's good.

-----

私は、高校の文化祭や、大学の学祭で、この程度の楽曲と映像のメディアミックスの作品が、普通に展示される日を待っています。

I'm waiting for the day when this kind of media mix of music and video will be displayed at high school festivals and university festivals.

―― というか、そのくらい、やってくれよ、若人。

"Why not do that, younth!"

私は、現在の学生演劇が、30年も前と全く変らないワークフレームで演じられていることに、ショックを受けています。

I am shocked to find that student theater today is performed with a work frame that is exactly the same as it was 30 years ago.

今や、メディアミックスなんか、当たり前に取り入れていると思っていましたが、学生演劇が、驚くほど保守的(後進的)なことに驚いています。

I was surprised at how conservative (backward) the student theater scene is, although I thought media mixes were commonplace nowadays.