魏长东

weichangdong

正在查看: 2017年03月日志归档(第 1 页 / 共 4 篇)

lua和php运行速度

在网上看到一篇文章,同样的功能用集中语言实现,然后执行比较速度。其中有我喜欢的php和正在学习的lua,就把代码搞到自己的机器上运行了,lua比php慢,但是luajit却快了十倍,让我开始喜欢luajit了。我喜欢一个语言,很简单,只需要一个简单的理由。

这是执行时间

php time:17811.112880707ms php5.6

lua time:31530ms lua5.14

luajit time:2790ms

检测你的nginx是否使用了jit

ldd /usr/local/openresty/nginx/sbin/nginx

下面上代码

»»阅读全文

好的测试工具wrk

比ab好,我感觉,在并发数量上,wrk更加优胜。可以用lua脚本加强一些功能。

Nginx 的 Echo 模块 —— echo-nginx-module

 location /hello {
    echo "hello, world!";
  }

  location /hello {
    echo -n "hello, "
    echo "world!";
  }

  location /timed_hello {
    echo_reset_timer;
    echo hello world;
    echo "'hello world' takes about $echo_timer_elapsed sec.";
    echo hiya igor;
    echo "'hiya igor' takes about $echo_timer_elapsed sec.";
  }

  location /echo_with_sleep {
    echo hello;
    echo_flush;  # ensure the client can see previous output immediately
    echo_sleep   2.5;  # in sec
    echo world;
  }

  # in the following example, accessing /echo yields
  #   hello
  #   world
  #   blah
  #   hiya
  #   igor
  location /echo {
      echo_before_body hello;
      echo_before_body world;
      proxy_pass $scheme://127.0.0.1:$server_port$request_uri/more;
      echo_after_body hiya;
      echo_after_body igor;
  }
  location /echo/more {
      echo blah;
  }

  # the output of /main might be
  #   hello
  #   world
  #   took 0.000 sec for total.
  # and the whole request would take about 2 sec to complete.
  location /main {
      echo_reset_timer;
 
      # subrequests in parallel
      echo_location_async /sub1;
      echo_location_async /sub2;
 
      echo "took $echo_timer_elapsed sec for total.";
  }
  location /sub1 {
      echo_sleep 2;
      echo hello;
  }
  location /sub2 {
      echo_sleep 1;
      echo world;
  }

  # the output of /main might be
  #   hello
  #   world
  #   took 3.003 sec for total.
  # and the whole request would take about 3 sec to complete.
  location /main {
      echo_reset_timer;
 
      # subrequests in series (chained by CPS)
      echo_location /sub1;
      echo_location /sub2;
 
      echo "took $echo_timer_elapsed sec for total.";
  }
  location /sub1 {
      echo_sleep 2;
      echo hello;
  }
  location /sub2 {
      echo_sleep 1;
      echo world;
  }

  # Accessing /dup gives
  #   ------ END ------
  location /dup {
    echo_duplicate 3 "--";
    echo_duplicate 1 " END ";
    echo_duplicate 3 "--";
    echo;
  }

  # /bighello will generate 1000,000,000 hello's.
  location /bighello {
    echo_duplicate 1000_000_000 'hello';
  }

  # echo back the client request
  location /echoback {
    echo_duplicate 1 $echo_client_request_headers;
    echo "\r";
 
    echo_read_request_body;
 
    echo_request_body;
  }

  # GET /multi will yields
  #   querystring: foo=Foo
  #   method: POST
  #   body: hi
  #   content length: 2
  #   ///
  #   querystring: bar=Bar
  #   method: PUT
  #   body: hello
  #   content length: 5
  #   ///
  location /multi {
      echo_subrequest_async POST '/sub' -q 'foo=Foo' -b 'hi';
      echo_subrequest_async PUT '/sub' -q 'bar=Bar' -b 'hello';
  }
  location /sub {
      echo "querystring: $query_string";
      echo "method: $echo_request_method";
      echo "body: $echo_request_body";
      echo "content length: $http_content_length";
      echo '///';
  }

  # GET /merge?/foo.js&/bar/blah.js&/yui/baz.js will merge the .js resources together
  location /merge {
      default_type 'text/javascript';
      echo_foreach_split '&' $query_string;
          echo "/* JS File $echo_it */";
          echo_location_async $echo_it;
          echo;
      echo_end;
  }

  # accessing /if?val=abc yields the "hit" output
  # while /if?val=bcd yields "miss":
  location ^~ /if {
      set $res miss;
      if ($arg_val ~* '^a') {
          set $res hit;
          echo $res;
      }
      echo $res;
  }

我的mac 开发机

突然发现我的mac装了好多技术相关的,ide就不列举了。

老本行php:php7,php的yaf框架,composer

数据库:mysql,mongodb,postgresql,redis,elastic search,以及es的插件es head

lua相关:openresty,lua5.14,luarocks,operesty相关的lor框架,operesty相关的lapis框架,基于lor的orange。vanilla香草框架(被我卸载了,感觉不咋喜欢)

版本控制:svn(mac自带的),git

其他对于我比较边缘的:nodejs,npm,go,grunt,ab(自带),wrk,casperjs,phomtonjs,jq,java。

其中好多不是我本意想安装的,比如grunt,casperjs,postgresql,是我在折腾别的东东的时候,需要他就安装了。其实上面好多我都在windows装过了,也折腾过了。

最近没事想折腾go,但是发现go有些恶心的地方,以至于我不想搞了(实在闲的蛋疼的时候,就看看),但是不依赖环境这一点我却非常喜欢。还有就是觉得他适合做一些Linux命令。

还是把主力放到lua上吧,以后lua前段api,php后台,完美胜任各种工作。