Łukasz Wieczorek's blog A slice of programmer's life

uWSGI maximum scoket connections

Were you ever wondering why are you getting HTTP 502 responses from your uWSGI on high connection count?

Setting net.core.somaxconn might help.

Temporarily:

$ cat /proc/sys/net/core/somaxconn
# echo 4096 > /proc/sys/net/core/somaxconn

Temporarily with sysctl:

# sysctl -w net.core.somaxconn=1024
# echo 'net.core.somaxconn=1024' >> /etc/sysctl.conf

Reload kernel parameters after changes:

# sysctl -p

Change uWSGI settings for vassal:

cat /etc/uwsgi/vassals/vassal.ini
echo 'listen = 1024' >> /etc/uwsgi/vassals/vassal.ini

Restart uwsgi:

service uwsgi restart

Debugging Django code

Ever tried debugging Django code in the CLI offered by manage.py shell or shell_plus?

It gets nasty when you need to write more than few lines of code to run something.

Here’s what you can do instead:

import os

import django


os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
django.setup()


def main():
    print 'Hello world!'


if __name__ == '__main__':
    main()

Cleaning up old remote branches in Git

This time in fish.

git fetch origin --prune
git fetch --all
for branch in (git branch --remote | egrep -v 'develop|master|\*' | tr -d ' ' | sed 's/origin\///'); git push origin ":$branch"; end