Skip to content

Instantly share code, notes, and snippets.

Avatar

Scott Francis csfrancis

View GitHub Profile
View foo.rb
#!/usr/bin/env ruby
NGINX_PID_FILE = "/var/run/nginx.pid"
NGINX_OLD_PID_FILE = "/var/run/nginx.pid.oldbin"
NGINX_CONF_FILE = "/etc/nginx/nginx.conf"
NGINX_BIN = "/usr/sbin/nginx"
LD_OVERRIDES = "/etc/nginx/ld-overrides"
DEFAULT_NGINX_WORKERS = 2
def with_term_color(color, eol: true)
View dns.md

Debugging DNS

This is a story about how I debug things. We're big users of NGINX and Lua at Shopify. Lately, we've been looking at implementing support to add and remove upstream peers to lua-upstream-nginx-module. Step 1 is to get the tests working for the module to make sure the world's in a sane state. I built a development build of NGINX and ran the tests, and this is when the trouble started.

A few of the tests were failing with similar errors:

#   Failed test 'TEST 4: sample in README - response_body - response is expected (req 0)'
#   at /usr/local/share/perl/5.18.2/Test/Nginx/Socket.pm line 1277.
# @@ -1,5 +1,5 @@
#  upstream foo.com:
View strace_init_translations.log
6040 12:07:29.991944 select(16, [14 15], NULL, NULL, {43, 387221} <unfinished ...>
6040 12:07:30.149445 <... select resumed> ) = 1 (in [14], left {43, 229785})
6040 12:07:30.149520 fcntl(14, F_GETFL <unfinished ...>
6040 12:07:30.149534 <... fcntl resumed> ) = 0x802 (flags O_RDWR|O_NONBLOCK)
6040 12:07:30.149551 accept4(14, <unfinished ...>
6040 12:07:30.149566 <... accept4 resumed> {sa_family=AF_INET, sin_port=htons(37964), sin_addr=inet_addr("127.0.0.1")}, [16], SOCK_CLOEXEC) = 26
6040 12:07:30.149630 recvfrom(26, <unfinished ...>
6040 12:07:30.149647 <... recvfrom resumed> "GET /services/ping HTTP/1.0\r\nX-R"..., 16384, MSG_DONTWAIT, NULL, NULL) = 131
6040 12:07:30.150084 write(26, "HTTP", 4 <unfinished ...>
6040 12:07:30.150128 <... write resumed> ) = 4
View current_upstream_name.patch
From 25ec18a4c341955e4e6bd051a06b9d92d09e2d33 Mon Sep 17 00:00:00 2001
From: Justin Li <jli.justinli@gmail.com>
Date: Thu, 4 Feb 2016 23:15:42 +0000
Subject: [PATCH] feature: Add upstream.current_upstream_name() to return the
current proxy target
---
README.md | 27 ++++++++++++
src/ngx_http_lua_upstream_module.c | 44 ++++++++++++++++++++
t/sanity.t | 84 ++++++++++++++++++++++++++++++++++++++
View gist:3b7d348d86b750ad5a99
unbind C-b
set -g prefix C-a
bind a send-prefix
unbind ^C
bind ^C new-window
bind c new-window
unbind ^a
bind C-a last-window
@csfrancis
csfrancis / tsc_timer.lua
Created Jul 6, 2014
Using Luajit's DynAsm to read the timestamp counter using inline assembly in Lua
View tsc_timer.lua
-- A timer that uses the rdtsc instruction to read the CPU timestamp counter.
--
-- Requires DynAsm with Lua mode: https://github.com/luapower/dynasm
--
-- Use it like this:
--
-- local tsc_timer = require('tsc_timer')
-- local t = tsc_timer.start()
-- ... do some things ...
-- t:stop()
@csfrancis
csfrancis / gdb_ruby_backtrace.py
Last active Nov 24, 2020
Dump an MRI call stack from gdb
View gdb_ruby_backtrace.py
# Updated for Ruby 2.3
string_t = None
def get_rstring(addr):
s = addr.cast(string_t.pointer())
if s['basic']['flags'] & (1 << 13):
return s['as']['heap']['ptr'].string()
else:
return s['as']['ary'].string()
@csfrancis
csfrancis / gist:7808541
Created Dec 5, 2013
Python gdb to count number of entries in a memcached item linked list
View gist:7808541
c = 0
v = head = gdb.parse_and_eval('it')
while v.dereference() != None and c < 100:
if c > 0 and v == head:
break
c += 1
v = v.dereference()['h_next']
print c
View ifstat_sys.sh
#!/bin/bash
#
# Show if stats by sampling /sys/.
# Originally stolen from http://unix.stackexchange.com/questions/41346/upload-download-speed-in-tmux-status-line
run_segment() {
sleeptime="0.5"
iface="eth0"
RXB=$(</sys/class/net/"$iface"/statistics/rx_bytes)
TXB=$(</sys/class/net/"$iface"/statistics/tx_bytes)
View tmux.conf
unbind C-b
set -g prefix C-a
bind a send-prefix
unbind ^C
bind ^C new-window
bind c new-window
unbind ^a
bind C-a last-window
You can’t perform that action at this time.