The popular open-source contract for web professionals by Stuff & Nonsense
- Originally published: 23rd December 2008
- Revised date: March 15th 2016
- Original post
http://robots.thoughtbot.com/post/47202759358/using-gdb-to-inspect-a-running-ruby-process
That’s not a great thing to have to say, is it? However, I bet you’ve said it before and may not have immediately know why.
With liberal use of puts and maybe pry, you can figure out what a problem might be next time you run it, but sometimes you need to figure out what that problem is right now.
As it turns out, and I know this is a shocker, Ruby processes are just regular processes. They can be debugged with gdb.
Having recently had the need to find out why a job of mine was running particularly slowly, I found out about this lovely tool the hard way: frantic googling. I found some very useful functions for gdb in a blog post by Rasmus on Ruby callstacks.
| <% | |
| DEFAULT_DB = 'myapp_development' | |
| DB_BRANCHES = %w[ t79 ] | |
| branch = `git symbolic-ref HEAD 2> /dev/null`.chomp.split('/').last | |
| dev_db = DB_BRANCHES.include?(branch) ? branch.gsub(/[^a-zA-Z0-9_]/, '') : DEFAULT_DB | |
| puts "Using dev database: #{dev_db.inspect}" | |
| %> | |
| development: | |
| database: <%= dev_db %> |
| ## From a post on the ML, apropos this: | |
| ## http://lowlatencyweb.wordpress.com/2012/03/20/500000-requestssec-modern-http-servers-are-fast. | |
| ## For sysctl.conf | |
| net.ipv4.tcp_slow_start_after_idle = 0 | |
| echo "2048 64512" > /proc/sys/net/ipv4/ip_local_port_range | |
| echo "1" > /proc/sys/net/ipv4/tcp_tw_recycle | |
| echo "1" > /proc/sys/net/ipv4/tcp_tw_reuse |
| # Keep delayed job workers running using systemd on ubuntu | |
| # Usage | |
| # Start "sudo systemctl start delayed_job@{0..3}" to start 4 worker instances | |
| # Enable "sudo systemctl enable delayed_job@{0..3}" to enable 4 worker instances | |
| # Restart "sudo systemctl restart delayed_job@{0..3}" to restart 4 worker instances | |
| # Disable "sudo systemctl disable delayed_job@{0..3}" to disable 4 worker instances | |
| # Stop "sudo systemctl stop delayed_job@{0..3}" to stop 4 worker instances | |
| [Unit] | |
| Description=Delayed Job Worker %i |
| <?php | |
| namespace H57\Util; | |
| class Serializor { | |
| /** | |
| * Converts the Doctrine Entity into a JSON Representation | |
| * | |
| * @param object $object The Object (Typically a Doctrine Entity) to convert to an array |
| /* Adapted from Tom Cunningham's 'Data Warehousing with MySql' (www.meansandends.com/mysql-data-warehouse) */ | |
| ###### small-numbers table | |
| DROP TABLE IF EXISTS numbers_small; | |
| CREATE TABLE numbers_small (number INT); | |
| INSERT INTO numbers_small VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); | |
| ###### main numbers table | |
| DROP TABLE IF EXISTS numbers; | |
| CREATE TABLE numbers (number BIGINT); |
| alert(([][[]]+[])[!+[]+!![]+!![]+!![]]+([] | |
| [[]]+[])[+[]]+(!![]+[])[+[]]+([][[]]+[]) | |
| [+[]]+([]+{})[!+[]+!![]]+([][[]]+[])[! | |
| +[]+!![]+!![]+!![]+!![]]+(![]+[])[!+[]+!! | |
| []]+([][[]]+[])[!+[]+!![]+!![]]+([][[]]+[]) | |
| [!+[]+!![]+!![]]+(!![]+[])[+[]]) |