How can I find out why my app is slow?

2019-07-12 19:20发布

I have a simple Rails app deployed on a 500 MB Slicehost VPN. I'm the only one who uses the app. When I run it on my laptop, it's fast enough. But the deployed version is insanely slow. It take 6 to 10 seconds to load the login screen.

I would like to find out why it's so slow. Is it my code? (Don't think so because it's much faster locally, but maybe.) Is it Slicehost's server being overloaded? Is it the Internet?

Can someone suggest a technique or set of steps I can take to help narrow down the cause of this problem?


Update:

Sorry forgot to mention. I'm running it under CentOS 5 using Phusion Passenger (AKA mod_rails or mod_rack).

10条回答
▲ chillily
2楼-- · 2019-07-12 19:33

You might want to run a local virtual machine with 500 MB. Are you doing a lot of client-server interaction? Delays over the WAN are significant

查看更多
等我变得足够好
3楼-- · 2019-07-12 19:36

If it is just slow on the first time you load it is probably because of passenger killing the process due to inactivity. I don't remember all the details but I do recall reading people who used cron jobs to keep at least one process alive to avoid this lag that can occur with passenger needed to reload the environment.

Edit: more details here

Specifically - pool idle time defaults to 2 minutes which means after two minutes of idling passenger would have to reload the environment to serve the next request.

查看更多
Summer. ? 凉城
4楼-- · 2019-07-12 19:37

You might want to check out RPM (there's a free "lite" version too) and/or New Relic's Tune Up.

查看更多
【Aperson】
5楼-- · 2019-07-12 19:40

You could try running 'top' when you SSH in to see which process is heavy. If you also have problems logging you, perhaps you may try getting Statistics in the Slicehost manager.

If you discover it is MySQL's fault, consider decreasing the number of servers it can spawn.

512 seems decent for Rails application, you might have to check if you misconfigured too.

查看更多
Melony?
6楼-- · 2019-07-12 19:42

Try to pint point where the slowness lies

1/ application is slow, or infrastructure (network + web server)

  • put a static file on your web server, and access it through your browser

2/ If it is fast, it is probable a problem with application + server configuration.

  • database access is slow
  • try a page with a simpel loop: is it slow?

3/ If it slow, it is probably your infrastructure. You can check:

  • bad network connection: do a packet capture (with Wireshark for example) and look for retransmissions, duplicate packets, etc.
  • DNS resolution is slow?
  • server is misconfigured?
  • etc.
查看更多
狗以群分
7楼-- · 2019-07-12 19:48

If you are using FireFox and doing localhost testing (or maybe even on LAN) you may want to try editing the network.dns.disableIPv6 setting.

Type about:config in the address bar and filter for network.dns.disableIPv6 and double-click to set to true.

This bug has been reported mainly from Vista OS's, but some others as well.

查看更多
登录 后发表回答