2011/08/04

Recent entries from same category

  1. Go 言語プログラミングエッセンスという本を書きました。
  2. errors.Join が入った。
  3. unsafe.StringData、unsafe.String、unsafe.SliceData が入った。
  4. Re: Go言語で画像ファイルか確認してみる
  5. net/url に JoinPath が入った。

最近はクラウドサーバ等、割と色んな所で見かける様になったuWSGIですが...
uWSGI

uWSGI is a fast, self-healing and developer/sysadmin-friendly application container server coded in pure C.

http://projects.unbit.it/uwsgi/
Perlだとhirataraさんが書いた記事や
Hokkaido.pmでuWSGIについてLTした - a geek born in Tomakomai

uWSGI はデフォルトではhttpではなくuwsgiプロトコルを喋るので、uwsgiプロトコルを喋れるフロントエンドを立ち上げます...

http://d.hatena.ne.jp/hiratara/20110718/1310950381
Plack::App::uWSGIが参考になります。
hiratara/p5-Plack-App-uWSGI - GitHub

Plack::App::uWSGI - a PSGI frontend of uwsgi.

https://github.com/hiratara/p5-Plack-App-uWSGI
こちらはuwsgiに付属のpsgiプラグインを使っています。なお、uwsgiのcontribフォルダにはPlack::Handler::Uwsgiが同梱されているので、例えばnginx.confに server {
  listen 8082;
  location / {
    include uwsgi_params;
    uwsgi_pass 127.0.0.1:9999;
  }
}
と書いておき use Plack::Handler::Uwsgi;

my $app = sub {
    return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello World' ] ];
};
Plack::Handler::Uwsgi->new(host=>'127.0.0.1'port=>9999)->run($app)
こんな感じに走らせると、"http://server:8082/" で"Hello World"が表示されます。もちろんフロントエンドであるnginxの設定を弄ればキャッシュやタイムアウトも変更出来るという仕組みです。

ちなみにcontribフォルダにはrubyやjavaのコードも置いてあります。つまりuWSGIプロトコルを実装すれば、言語を問わずフロントエンドをnginxとしたワーカーが作れるって事ですかね。

Go言語も仲間に入れてよ!って事でuWSGIリスナを書いてみました。
mattn/go-uwsgi - GitHub

uwsgi implement for go

https://github.com/mattn/go-uwsgi
あくまでリスナという位置づけなので、unixドメインソケットのファイルや、tcpソケットなど、goでnet.Listenerとして扱える物であれば何でもokです。これを使うとファイルサーバがほんの数行で書けてしまいます。

nginx.confが server {
  listen 8081;
  location / {
    include uwsgi_params;
    uwsgi_pass unix:///var/run/go-uwsgi/socket;
  }
}
であれば package main

import (
    "net"
    "http"
    "github.com/mattn/go-uwsgi"
    "os"
)

func main() {
    s := "/var/run/go-uwsgi/socket"
    os.Remove(s)
    l, e := net.Listen("unix", s)
    if e != nil { panic(e.String()) }
    http.Serve(&uwsgi.Listener{l}, http.FileServer(http.Dir(".")))
}
これだけですね。簡単です。
初めてのPerl 第5版 初めてのPerl 第5版
Randal L. Schwartz, Tom Phoenix, brian d foy, 近藤 嘉雪
オライリージャパン 大型本 / ¥486 (2009年10月26日)
 
発送可能時間:

Posted at by | Edit