From c8dfd44280fb9616e076e594ee69366ca4dc692b Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Tue, 4 Mar 2014 14:20:31 -0800 Subject: [PATCH] new tiddler: "BuildSystemtap". --- index.html | 17 ++++++++- index.xml | 107 ++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 106 insertions(+), 18 deletions(-) diff --git a/index.html b/index.html index daae4b302..a729d6b35 100755 --- a/index.html +++ b/index.html @@ -600,6 +600,21 @@ Otherwise use an alternative lightweight HTTP load-testing tool [[weighttp|http://redmine.lighttpd.net/projects/weighttp/wiki]] and the invocation {{{weighttp -k -c10 -n10000 'http://127.0.0.1:8080/'}}} for benchmarking. +
+
<<toolbar permalink>>
+{{{
+sudo yum install gcc gcc-c++ -y
+wget https://fedorahosted.org/releases/e/l/elfutils/0.158/elfutils-0.158.tar.bz2
+tar -xvf elfutils-0.158.tar.bz2
+wget https://sourceware.org/systemtap/ftp/releases/systemtap-2.4.tar.gz
+cd systemtap-2.4/
+./configure --prefix=/opt/stap --disable-docs \
+            --disable-publican --disable-refdocs CFLAGS="-g -O2" \
+            --with-elfutils=../elfutils-0.158
+make -j8
+sudo make install
+}}}
+
<<toolbar permalink>>
 ! Stable Release 1.0.4.2 - 9 August 2011
@@ -3164,7 +3179,7 @@
 When used in conjunction with [[LuaNginxModule]], it is recommended to use [[LuaRestyMySQLLibrary]] instead of this one, since it is more flexible and more memory-efficient.
 
-
+
<<toolbar permalink>>
 
 This sample demonstrates how to use Redis to route incoming requests to different HTTP backends based on the requests' {{{User-Agent}}} header.
diff --git a/index.xml b/index.xml
index 4f6198207..e37538d8a 100755
--- a/index.xml
+++ b/index.xml
@@ -5,16 +5,103 @@
 a fast web app server by extending nginx 
 en
 Copyright 2014 YichunZhang
-Sat, 01 Mar 2014 01:01:14 GMT
-Sat, 01 Mar 2014 01:01:14 GMT
+Tue, 04 Mar 2014 22:19:58 GMT
+Tue, 04 Mar 2014 22:19:58 GMT
 http://blogs.law.harvard.edu/tech/rss
 TiddlyWiki 2.6.2
 
+BuildSystemtap
+<a tiddler="BuildSystemtap" commandname="permalink" class="button command_permalink" title="Permalink for this tiddler" href="javascript:;">permalink</a><br><pre>sudo yum install gcc gcc-c++ -y
+wget https://fedorahosted.org/releases/e/l/elfutils/0.158/elfutils-0.158.tar.bz2
+tar -xvf elfutils-0.158.tar.bz2
+wget https://sourceware.org/systemtap/ftp/releases/systemtap-2.4.tar.gz
+cd systemtap-2.4/
+./configure --prefix=/opt/stap --disable-docs \
+            --disable-publican --disable-refdocs CFLAGS="-g -O2" \
+            --with-elfutils=../elfutils-0.158
+make -j8
+sudo make install
+</pre>
+null#BuildSystemtap
+Tue, 04 Mar 2014 22:19:57 GMT
+
+
+
+DynamicRoutingBasedOnRedis
+<a tiddler="DynamicRoutingBasedOnRedis" commandname="permalink" class="button command_permalink" title="Permalink for this tiddler" href="javascript:;">permalink</a><br><br>This sample demonstrates how to use Redis to route incoming requests to different HTTP backends based on the requests' <code>User-Agent</code> header.<br><br>This demo uses the components <a tiddlylink="LuaNginxModule" refresh="link" target="_blank" title="External link to null#LuaNginxModule" href="null#LuaNginxModule" class="externalLink null">LuaNginxModule</a> and <a tiddlylink="LuaRestyRedisLibrary" refresh="link" target="_blank" title="External link to null#LuaRestyRedisLibrary" href="null#LuaRestyRedisLibrary" class="externalLink null">LuaRestyRedisLibrary</a> enabled by default in <a tiddlylink="OpenResty" refresh="link" target="_blank" title="External link to null#OpenResty" href="null#OpenResty" class="externalLink null">OpenResty</a>.<br><br>Here's the complete code listing for our <code>nginx.conf</code>:<br><br><pre>worker_processes  2;
+error_log logs/error.log info;
+
+events {
+    worker_connections 1024;
+}
+
+http {
+    server {
+        listen 8080;
+
+        location / {
+            resolver 8.8.4.4;  # use Google's open DNS server
+
+            set $target '';
+            access_by_lua '
+                local key = ngx.var.http_user_agent
+                if not key then
+                    ngx.log(ngx.ERR, "no user-agent found")
+                    return ngx.exit(400)
+                end
+
+                local redis = require "resty.redis"
+                local red = redis:new()
+
+                red:set_timeout(1000) -- 1 second
+
+                local ok, err = red:connect("127.0.0.1", 6379)
+                if not ok then
+                    ngx.log(ngx.ERR, "failed to connect to redis: ", err)
+                    return ngx.exit(500)
+                end
+
+                local host, err = red:get(key)
+                if not host then
+                    ngx.log(ngx.ERR, "failed to get redis key: ", err)
+                    return ngx.exit(500)
+                end
+
+                if host == ngx.null then
+                    ngx.log(ngx.ERR, "no host found for key ", key)
+                    return ngx.exit(400)
+                end
+
+                ngx.var.target = host
+            ';
+
+            proxy_pass http://$target;
+        }
+    }
+}
+</pre><br>And then let's start the redis server on the localhost:6379:<br><pre>$ ./redis-server  # default port is 6379
+</pre><br>and feed some keys into this using the redis-cli utility:<br><pre>   $ ./redis-cli
+   redis&gt; set foo apache.org
+   OK
+   redis&gt; set bar nginx.org
+   OK
+</pre>And then let's test our nginx app!<br><pre>   $ curl --user-agent foo localhost:8080
+   &lt;apache.org home page goes here&gt;
+
+   $ curl --user-agent bar localhost:8080
+   &lt;nginx.org home page goes here&gt;
+</pre>To further tune the performance, one could enable the connection pool for the redis connections, as documented in <a tiddlylink="LuaRestyRedisLibrary" refresh="link" target="_blank" title="External link to null#LuaRestyRedisLibrary" href="null#LuaRestyRedisLibrary" class="externalLink null">LuaRestyRedisLibrary</a>'s README.<br><br>Before you benchmarking your interface defined here, please ensure that you've raised the error log level to <code>warn</code> or <code>notice</code> in your <code>nginx.conf</code> file, as in<br><pre>error_log logs/error.log warn;
+</pre>because flushing error log is a very expensive operation and can hurt performance a lot.<br>
+null#DynamicRoutingBasedOnRedis
+Tue, 04 Mar 2014 22:19:01 GMT
+
+
+
 Presentations
 <a tiddler="Presentations" commandname="permalink" class="button command_permalink" title="Permalink for this tiddler" href="javascript:;">permalink</a><br><br>Here goes a list of slides that I used in my talks regarding <a tiddlylink="OpenResty" refresh="link" target="_blank" title="External link to null#OpenResty" href="null#OpenResty" class="externalLink null">OpenResty</a>.<br><br>These slides are powered by the <a target="_blank" title="External link to https://github.com/kindy61/slides.htm" href="https://github.com/kindy61/slides.htm" class="externalLink">slides.htm</a> slide-making engine based on AJAX.<br><br><strong><em>Note: Please use the arrow keys or pageup/pagedown keys on your keyboard to switch slides.</em></strong><br><h1> Year 2014</h1><h2> NGINX, Lua, and beyond</h2>This talk was given at NGINX Inc's <a target="_blank" title="External link to https://www.eventbrite.com/e/nginx-user-summit-and-training-tickets-10393173261" href="https://www.eventbrite.com/e/nginx-user-summit-and-training-tickets-10393173261" class="externalLink">NGINX User Summit 2014</a> on 25 February 2014.<br><br>View slides in your web browser: <a target="_blank" title="External link to http://agentzh.org/misc/slides/nginx-user-summit-2014/" href="http://agentzh.org/misc/slides/nginx-user-summit-2014/" class="externalLink">http://agentzh.org/misc/slides/nginx-user-summit-2014/</a><br><br>Download the slides as PDF: <a target="_blank" title="External link to http://agentzh.org/misc/slides/nginx-lua-and-beyond.pdf" href="http://agentzh.org/misc/slides/nginx-lua-and-beyond.pdf" class="externalLink">http://agentzh.org/misc/slides/nginx-lua-and-beyond.pdf</a><br><br><h1> Year 2013</h1><h2> The Way of Optimizing and Troubleshooting Our Lua Waf</h2>This talk was given at CloudFlare's Beer Meeting on 19 April 2013.<br><br>View slides in your web browser: <a target="_blank" title="External link to http://agentzh.org/misc/slides/beer-meeting-2013-04-19/" href="http://agentzh.org/misc/slides/beer-meeting-2013-04-19/" class="externalLink">http://agentzh.org/misc/slides/beer-meeting-2013-04-19/</a><br><br>Download the slides as PDF: <a target="_blank" title="External link to http://agentzh.org/misc/slides/beer-meeting-2013-04-19.pdf" href="http://agentzh.org/misc/slides/beer-meeting-2013-04-19.pdf" class="externalLink">http://agentzh.org/misc/slides/beer-meeting-2013-04-19.pdf</a><br><br><h2> sregex: matching Perl 5 regexes on data streams</h2>This talk was given at <a target="_blank" title="External link to http://www.yapcna.org/yn2013/" href="http://www.yapcna.org/yn2013/" class="externalLink">YAPC::NA 2013</a> in Austin, TX, USA.<br><br>Talk summary: <a target="_blank" title="External link to http://www.yapcna.org/yn2013/talk/4762" href="http://www.yapcna.org/yn2013/talk/4762" class="externalLink">http://www.yapcna.org/yn2013/talk/4762</a><br><br>View slides in your web browser: <a target="_blank" title="External link to http://agentzh.org/misc/slides/yapc-na-2013-sregex/" href="http://agentzh.org/misc/slides/yapc-na-2013-sregex/" class="externalLink">http://agentzh.org/misc/slides/yapc-na-2013-sregex/</a><br><br>Download the slides as PDF: <a target="_blank" title="External link to http://agentzh.org/misc/slides/yapc-na-2013-sregex.pdf" href="http://agentzh.org/misc/slides/yapc-na-2013-sregex.pdf" class="externalLink">http://agentzh.org/misc/slides/yapc-na-2013-sregex.pdf</a><br><br><h2> Flame Graphs for online performance profiling</h2>This talk was given at <a target="_blank" title="External link to http://www.yapcna.org/yn2013/" href="http://www.yapcna.org/yn2013/" class="externalLink">YAPC::NA 2013</a> in Austin, TX, USA.<br><br>Talk summary: <a target="_blank" title="External link to http://www.yapcna.org/yn2013/talk/4579" href="http://www.yapcna.org/yn2013/talk/4579" class="externalLink">http://www.yapcna.org/yn2013/talk/4579</a><br><br>View slides in your web browser: <a target="_blank" title="External link to http://agentzh.org/misc/slides/yapc-na-2013-flame-graphs/" href="http://agentzh.org/misc/slides/yapc-na-2013-flame-graphs/" class="externalLink">http://agentzh.org/misc/slides/yapc-na-2013-flame-graphs/</a><br><br>Download the slides as PDF: <a target="_blank" title="External link to http://agentzh.org/misc/slides/yapc-na-2013-flame-graphs.pdf" href="http://agentzh.org/misc/slides/yapc-na-2013-flame-graphs.pdf" class="externalLink">http://agentzh.org/misc/slides/yapc-na-2013-flame-graphs.pdf</a><br><br><h2> Introduction to off-CPU Time Flame Graphs</h2>This talk was given at the CloudFlare Beer Meeting on 23 August 2013.<br><br>View slides in your web browser: <a target="_blank" title="External link to http://agentzh.org/misc/slides/off-cpu-flame-graphs/" href="http://agentzh.org/misc/slides/off-cpu-flame-graphs/" class="externalLink">http://agentzh.org/misc/slides/off-cpu-flame-graphs/</a><br><br>Download the slides as PDF: <a target="_blank" title="External link to http://agentzh.org/misc/slides/off-cpu-flame-graphs.pdf" href="http://agentzh.org/misc/slides/off-cpu-flame-graphs.pdf" class="externalLink">http://agentzh.org/misc/slides/off-cpu-flame-graphs.pdf</a><br><br><h1> Year 2012</h1><h2> ngx_openresty: an Nginx ecosystem glued by Lua</h2>This talk was given at <a target="_blank" title="External link to http://event.weibo.com/351359" href="http://event.weibo.com/351359" class="externalLink">Tech-Club Technical Salon</a> held in the Xiamen city.<br><br>View slides in your web browser: <a target="_blank" title="External link to http://agentzh.org/misc/slides/ngx-openresty-ecosystem/" href="http://agentzh.org/misc/slides/ngx-openresty-ecosystem/" class="externalLink">http://agentzh.org/misc/slides/ngx-openresty-ecosystem/</a><br><br>Download the slides as PDF: <a target="_blank" title="External link to http://agentzh.org/misc/slides/ngx-openresty-ecosystem.pdf" href="http://agentzh.org/misc/slides/ngx-openresty-ecosystem.pdf" class="externalLink">http://agentzh.org/misc/slides/ngx-openresty-ecosystem.pdf</a><br><br><h2> Scripting libdrizzle with Lua inside Nginx</h2>This presentation was given at <a target="_blank" title="External link to http://www.percona.com/live/mysql-conference-2012/sessions/scripting-mysql-lua-and-libdrizzle-inside-nginx" href="http://www.percona.com/live/mysql-conference-2012/sessions/scripting-mysql-lua-and-libdrizzle-inside-nginx" class="externalLink">Percona Live MySQL Conference 2012</a> held in Santa Clara, CA, USA.<br><br>View slides in your web browser: <a target="_blank" title="External link to http://agentzh.org/misc/slides/libdrizzle-lua-nginx/#2" href="http://agentzh.org/misc/slides/libdrizzle-lua-nginx/#2" class="externalLink">http://agentzh.org/misc/slides/libdrizzle-lua-nginx/#2</a><br><br>Download the slides as PDF: <a target="_blank" title="External link to http://agentzh.org/misc/slides/libdrizzle-lua-nginx.pdf" href="http://agentzh.org/misc/slides/libdrizzle-lua-nginx.pdf" class="externalLink">http://agentzh.org/misc/slides/libdrizzle-lua-nginx.pdf</a><br><br><h1> Year 2011</h1><h2> Applications of ngx_openresty and perl in lz.taobao.com</h2><br>This talk was given at <a target="_blank" title="External link to http://conference.perlchina.org/bjpw2011/talks" href="http://conference.perlchina.org/bjpw2011/talks" class="externalLink">Beijing Perl Workshop 2011</a>.<br><br>Watch the video online: <a target="_blank" title="External link to http://v.ku6.com/show/TY8Vre59guTE_C8o.html" href="http://v.ku6.com/show/TY8Vre59guTE_C8o.html" class="externalLink">http://v.ku6.com/show/TY8Vre59guTE_C8o.html</a><br><br>View slides in your web browser: <a target="_blank" title="External link to http://agentzh.org/misc/slides/perl-lz-apps/" href="http://agentzh.org/misc/slides/perl-lz-apps/" class="externalLink">http://agentzh.org/misc/slides/perl-lz-apps/</a><br><br>Download the slides as PDF: <a target="_blank" title="External link to http://agentzh.org/misc/slides/perl-lz-apps.pdf" href="http://agentzh.org/misc/slides/perl-lz-apps.pdf" class="externalLink">http://agentzh.org/misc/slides/perl-lz-apps.pdf</a><br><br><h1> Year 2010</h1><h2> Introduction to nginx.conf scripting</h2>This talk was given at the <a target="_blank" title="External link to http://conference.perlchina.org" href="http://conference.perlchina.org" class="externalLink">Beijing Perl Workshop</a> 2010 April meeting and the <a target="_blank" title="External link to http://www.beijing-open-party.org/event/2" href="http://www.beijing-open-party.org/event/2" class="externalLink">Beijing OpenParty 2010 June event</a>.<br><br>View slides in your web browser: <a target="_blank" title="External link to http://agentzh.org/misc/slides/nginx-conf-scripting/" href="http://agentzh.org/misc/slides/nginx-conf-scripting/" class="externalLink">http://agentzh.org/misc/slides/nginx-conf-scripting/</a><br><br>Download the slides as PDF: <a target="_blank" title="External link to http://agentzh.org/misc/slides/nginx-conf-scripting.pdf" href="http://agentzh.org/misc/slides/nginx-conf-scripting.pdf" class="externalLink">http://agentzh.org/misc/slides/nginx-conf-scripting.pdf</a><br><br>Please note that ngx_eval module is no longer recommended because we're in more favor of ngx_lua nowadays.<br><br><h2> Recent developments in nginx.conf scripting</h2>This talk was given at the <a target="_blank" title="External link to http://www.beijing-open-party.org/event/2" href="http://www.beijing-open-party.org/event/2" class="externalLink">Beijing OpenParty 2010 June event</a>.<br><br>View slides in your web browser: <a target="_blank" title="External link to http://agentzh.org/misc/slides/recent-dev-nginx-conf/" href="http://agentzh.org/misc/slides/recent-dev-nginx-conf/" class="externalLink">http://agentzh.org/misc/slides/recent-dev-nginx-conf/</a><br><br>Download the slides as PDF: <a target="_blank" title="External link to http://agentzh.org/misc/slides/recent-dev-nginx-conf.pdf" href="http://agentzh.org/misc/slides/recent-dev-nginx-conf.pdf" class="externalLink">http://agentzh.org/misc/slides/recent-dev-nginx-conf.pdf</a><br><br><h2> The state of the art of nginx.conf scripting</h2>This talk was given at the <a target="_blank" title="External link to http://agentzh.org/misc/slides/nginx-state-of-the-art/" href="http://agentzh.org/misc/slides/nginx-state-of-the-art/" class="externalLink">ECUG 2010 event</a>.<br><br>Watch the (Chinese-speech) video online: <a target="_blank" title="External link to http://v.ku6.com/show/D00rqtnRwKzJdIsB.html" href="http://v.ku6.com/show/D00rqtnRwKzJdIsB.html" class="externalLink">http://v.ku6.com/show/D00rqtnRwKzJdIsB.html</a><br><br>View the (English) slides in your web browser: <a target="_blank" title="External link to http://agentzh.org/misc/slides/nginx-state-of-the-art/" href="http://agentzh.org/misc/slides/nginx-state-of-the-art/" class="externalLink">http://agentzh.org/misc/slides/nginx-state-of-the-art/</a><br><br>Download the slides as PDF: <a target="_blank" title="External link to http://agentzh.org/misc/slides/nginx-state-of-the-art.pdf" href="http://agentzh.org/misc/slides/nginx-state-of-the-art.pdf" class="externalLink">http://agentzh.org/misc/slides/nginx-state-of-the-art.pdf</a><br>
 Resources
 null#Presentations
-Sat, 01 Mar 2014 01:01:14 GMT
+Sat, 01 Mar 2014 01:01:00 GMT
 
 
 
@@ -258,20 +345,6 @@ make: *** [.plugin.scan] Error 1
 null#DrizzleNginxModule
 Thu, 17 Oct 2013 23:33:00 GMT
 
-
-
-EchoNginxModule
-<a tiddler="EchoNginxModule" commandname="permalink" class="button command_permalink" title="Permalink for this tiddler" href="javascript:;">permalink</a><br><br>This module wraps lots of Nginx internal APIs for streaming input and output, parallel/sequential subrequests, timers and sleeping, as well as various meta data accessing.<br><br>Basically it provides various utilities that help testing and debugging of other modules by trivially emulating different kinds of faked subrequest locations.<br><br>Documentation: <a target="_blank" title="External link to https://github.com/agentzh/echo-nginx-module#readme" href="https://github.com/agentzh/echo-nginx-module#readme" class="externalLink">https://github.com/agentzh/echo-nginx-module#readme</a><br><br>Project page: <a target="_blank" title="External link to https://github.com/agentzh/echo-nginx-module" href="https://github.com/agentzh/echo-nginx-module" class="externalLink">https://github.com/agentzh/echo-nginx-module</a>
-null#EchoNginxModule
-Thu, 17 Oct 2013 23:33:00 GMT
-
-
-
-Debugging
-<a tiddler="Debugging" commandname="permalink" class="button command_permalink" title="Permalink for this tiddler" href="javascript:;">permalink</a><br><br>You should always check out Nginx's error log file (specified by the <code>error_log</code> directive in <code>nginx.conf</code>) for any errors or warnings.<br><br>If you prefer redirecting common Lua errors to the HTTP response body during Lua development, you can put a Lua <a target="_blank" title="External link to http://www.lua.org/manual/5.1/manual.html#pdf-pcall" href="http://www.lua.org/manual/5.1/manual.html#pdf-pcall" class="externalLink">pcall</a> call on the top level of your Lua code to catch and redirect any Lua exceptions. But keep in mind, not all errors can be captured this way because you could have errors when sending out the response, then it is impossible to put such errors into the response body.<br><br>During Lua code development, you can disable the <a target="_blank" title="External link to http://wiki.nginx.org/HttpLuaModule#lua_code_cache" href="http://wiki.nginx.org/HttpLuaModule#lua_code_cache" class="externalLink">Lua code cache</a> temporarily so that you do not have to reload the Nginx server for your (external) Lua code changes to take effect.<br><br>Also, it is strongly recommended to follow the test-driven development workflow. For example, <a tiddlylink="LuaRestyRedisLibrary" refresh="link" target="_blank" title="External link to null#LuaRestyRedisLibrary" href="null#LuaRestyRedisLibrary" class="externalLink null">LuaRestyRedisLibrary</a> uses the <a target="_blank" title="External link to http://search.cpan.org/perldoc?Test%3A%3ANginx" href="http://search.cpan.org/perldoc?Test%3A%3ANginx" class="externalLink">Test::Nginx</a> test scaffold to drive its (declarative) <a target="_blank" title="External link to https://github.com/agentzh/lua-resty-redis/tree/master/t/" href="https://github.com/agentzh/lua-resty-redis/tree/master/t/" class="externalLink">test suite</a>.<br><br>If you are on Linux, there are quite many real-time analysing tools based on <a target="_blank" title="External link to http://sourceware.org/systemtap/" href="http://sourceware.org/systemtap/" class="externalLink">systemtap</a>, which can be used to inspect a running Nginx worker process in various ways:<br><dl><dd><a target="_blank" title="External link to https://github.com/agentzh/nginx-systemtap-toolkit" href="https://github.com/agentzh/nginx-systemtap-toolkit" class="externalLink">https://github.com/agentzh/nginx-systemtap-toolkit</a></dd></dl>You can find additional tools in the stap++ project:<br><dl><dd><a target="_blank" title="External link to https://github.com/agentzh/stapxx" href="https://github.com/agentzh/stapxx" class="externalLink">https://github.com/agentzh/stapxx</a></dd></dl>These tools can not only debug functional problems, but also profile online servers to find performance bottlenecks.
-null#Debugging
-Sun, 06 Oct 2013 18:24:00 GMT
-
 
 
 
\ No newline at end of file