I'm creating a web chat service for my company product which is a local social network serving a lot of concurrent connections from online users. Long-polling is used together with Tornado over Python. However, when there's a lot of inactive long-polling connections (receiving no incoming messages), I should close some of them.
How long should I let a long-polling connection stay? 1 hour or at most 1 day?
You have to adjust long-poll timeout to practical network environment, for example some adsl modems silently drop connections after, say, 10 minutes of inactivity. Some laptops might move to another wireless network or go to sleep, etc.
IMO you shouldn't have more than 5 minutes for practical public use case on the internet.
You may consider longer timeouts if you have control over network or peers; or if you have independent verification that client is still waiting, e.g. through a separate request that came from the same session.
When you analyze your workload, you might discover that after a certain threshold, doubling timeout brings very small performance improvement. Usually that threshold will be pretty small, then use that.
How long should I let a long-polling connection stay?