WebFaction
Community site: login faq
0
1

I am about to launch a django/mysql based site. I talked to a blogger about my site and she said "brilliant" and "huge potential", so now I am a bit worried about how well I can handle all the internet rushing in all at once... (She is willing to write a review and has roughly 10000 twitter followers & 30000 monthly visitors, which is not a problem unless they all decide to visit at the same time :-) )

Steps I have taken:

  • all images, js & css are served by static nginx
  • site is divided to two sections:
  • (1) public site info, which is static html served by nginx
  • (2) secure/https django app, starting from signup/login pages and everything else
  • secure part also serves static media using nginx (but naturally over https)
  • django debug toolbar shows queries with as much data I expect to have in a month can all be done in well under 1 sec (without other load and on couple of years old laptop)
  • I am using memcached, but this could be optimized
  • there will be many reads compared to writes (maybe 100:1) for the main data (django sessions etc. might have writes in addition)

Now, I can't decide should I move to managed dedicated server or buy many accounts (maybe replicating db + using one account as load balancer?) to best handle the site launch. There is not that much data yet, so each account should be able to fit mysql (*) + (replicated) db + memcached in memory for some time.

(*) It seems that I would need to build my own mysql for replication, but I think I should still be able to fit everything in memory.

I am looking for some sort of estimate of how many accounts would be equal to one dedicated server in my situation. Also, practical solutions for handling load balancing of secure django sites are very welcome.

Somehow I am thinking the dedicated machine might not have that big advantage as everything should fit in memory and the most expensive part is likely to be the read queries that can be distributed. Ah, it would be so simple if a "Dedicated 1" machine was equal to 25 shared accounts :-)

Any help is greatly appreciated!

Juha

asked 17 Jun '12, 15:40

threedee
112
accept rate: 0%


In general a Dedicated server is always better than any number of Shared accounts.

There are many reasons, but the general idea is with a dedicated machine you will have all the CPU cores, and RAM, other resources all working for your application. Doing load balancing between multiple shared machines will always have replication latency, and other technical issues you will have to engineer around, which would not be needed on a Dedicated server.

The real question for most people is cost, and 'overkill'. Does your application justify the cost of that much power?

Its impossible to give you a direct answer, since anything involving load balancing and other optimization all take real-time testing to see the data, without the data its only a guess.

To get the data you would use a series of tools,

ab can be used to benchmark the web-server's request handling. I normally run this on the server itself so i know what the server alone is doing, but it can be ran from your location and get times which monitor the distance from your location to the server. A basic command would look like this,

ab -n 100 -c 10 http://domain.com/

This would hit the server with 10 concurrent requests, 100 times, than provide statistics. This is a way to generate false load to see what happens if your site, or any particular page, is hit with many users at once.

Mod_wsgi has bench-marking tools which can further dissect the web-server and tune up options, which are covered here and here.

Lastly you as the Django developer has to be in the mindset to always look for code that could be written more efficiently, in Django this typically means writing clever Querysets which get the data you need with the smallest Database query possible. However it applies to all of the python code you write. This just takes a lot of practice and reading of the official docs to understands how it does what it does. Using tools like the Django Debug Toolbar can help too.

Using these practices Django developers can get high volume sites working within our Shared plans.

permanent link

answered 17 Jun '12, 17:29

johns
5.3k312
accept rate: 23%

edited 17 Jun '12, 17:31

Thanks for detailed answer! I know the the only way to find "the truth" in my case is to test, release, optimize, repeat, ... So far everything looks promising: no expensive queries, ab with -n 100 -c 30 gets the main pages in under 2 secs to Finland (time per request: 1.8 secs, requests per second: 16).

The only thing I would argue is "In general a Dedicated server is always better than any number of Shared accounts.": CPU bound algorithm could take for example 2secs/core. On shared machine it would take somewhat longer due to other load, but the only way to get significantly more requests done would be to have more cores. Latencies would add something, but 100 overlapping requests would be handles faster if each was running on separate core :-)

I know typical queries/algorithms are nowhere near cpu bound and only testing can tell my situation, but I think there are situations where more accounts will beat the single dedicated machine.

(17 Jun '12, 18:26) threedee

Memcached would change those numbers quite a bit, since at that point its a matter of how fast internally memcached can fetch it from RAM, as opposed to many remote DB calls to a second machine. I am sure there is some theoretical limit in which many shared machines would approach some numbers a dedicated would, but to get there might take a great deal of effort in engineering, cost of time is still cost and so would it be better? As a django developer myself I admit I have never really found an answer that sits right, instead I think of it as a ever changing problem that must be dealt with economically, depending on where the bottleneck is.

(17 Jun '12, 19:13) johns
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×908
×168
×6
×4

question asked: 17 Jun '12, 15:40

question was seen: 2,934 times

last updated: 17 Jun '12, 19:13

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM