Nginx Error: Too many open files
About speeding things up. A couple of useful points.
As is well known, browsers limit the number of simultaneous connections per domain while loading a site. Because of this, site elements are loaded sequentially. Every image/js/css file is a separate connection. If there are many such elements on a site's pages, you can speed up loading by moving static assets to subdomains. For example: s1.domain.com, s2.domain.com, and so on. So if the browser has, say, a limit of 5 connections per domain, now you get 5 connections for each subdomain. If you spread everything out correctly, load speed can theoretically increase almost fivefold.
The downside: the number of simultaneous connections to the server also grows. With the same site traffic, the number of connections grows by about 5 times as well (if you have 5 subdomains). If Nginx is the frontend, it has a limit on the number of connections in its config. And since there are now 5 times more connections, it also has to do more work at the same time than before. So with this acceleration we are also pushing Nginx closer to its simultaneous connection limit, and as a result the site may fail to open for the user or some files may simply not be served during loading.
The Nginx logs will show an error like:
"...socket() failed (24: Too many open files) while connecting to upstream..."
To see the current limit from the console:
ulimit -n
To see it nicely formatted like this:
nginx: worker process
Limit Soft Limit Hard Limit Units
Max open files 1024 1048576 files
Currently open files: 945
nginx: master process /usr/sbin/nginx
Limit Soft Limit Hard Limit Units
Max open files 1024 1048576 files
you can run this in the console:
for pid in `pidof nginx`; do echo "$(< /proc/$pid/cmdline)"; egrep 'files|Limit' /proc/$pid/limits; echo "Currently open files: $(ls -1 /proc/$pid/fd | wc -l)"; echo; done
To change the limit:
-
add these lines to /etc/security/limits.conf:
* soft nofile 16384
* hard nofile 16384 -
run as root:
ulimit -n 16384 - restart Nginx, just in case.
They also write that you can simply add this to the Nginx config:
worker_rlimit_nofile 16384
and restart it.
A Useful Thing: Prefix.pch
I discovered a useful thing in iOS development: the Prefix.pch file, a Precompiled Header.
From the description, Precompiled Headers are compiled, cached, and then automatically included into every file being compiled. So if there is some class that is needed everywhere or almost everywhere in a project, you can include that class inside the Prefix.pch file, which is created automatically in a new project, and it will be available everywhere. I really didn't like having to include the same class again and again in every View Controller when it was needed almost everywhere.
2011 in review
Well, time to wrap up two-thousand-and-eleven. I want to remember only the good — that’s what I’ll write about. Or not exactly «good» — but definitely not the bad. And since I took quite a few photos, I’ll use my own. The post turned out huge, but that’s because of the pictures.
Boosting iPhone 4 volume

I have a French iPhone 4. Apple is required to cap headphone volume on phones sold in France — apparently to look after the citizens’ ears. In the metro that cap leaves me short on volume, and besides, headphones vary — some play louder, some have different impedance and play quieter.
The cap can be bypassed. You need to jailbreak the phone, then access the file system and tweak a couple of plist files. There are plenty of options — installing a Terminal via Cydia, mounting the phone as a drive on your computer, etc. I prefer the second route — installed Phone Disk, it mounted the phone as a volume, and from there I just rummaged through the file system.
AllCafe for iPhone 1.1.2
![]()
Released a small AllCafe for iPhone update. The main changes are iPhone 3G support (i.e. support for the entire iOS 4 line) and image compression on the client side when adding reviews. Photos also get uploaded with the correct orientation now (portrait or landscape).
The pleasant surprise: the update was approved in just one day. Looks like reviewers are working at an accelerated pace right now — even iTunes Connect will be closed for the holidays from December 22 to December 29.
Traveling video
This weekend a friend asked me to come down to a studio and help shoot a clip for her university project. The theme — travelling. It’s something like a promo for their exhibition. The original idea didn’t work out, so in the end we just shot whatever was around. The result turned out funny and amusing, and the music was picked on my suggestion. I should shoot more. Result:
Camera: Sergey Armodin
Editing and post: Nadia Silver and Kira Kornienko
Music: Clint Mansell (Moon OST)