well I'm not even a programmer, so please bare with me. let's say I own a myspace clone and my server is bogged down by heavy traffic. So what's next? I know I can place mysql on a separate server, but what if that's not enough? can i split mysql? Can I get another server to run just the photogallery of a myspace clone? will that entail rewriting the entire script? what if the image gallery or myql, already spread on 3 servers, just keeps growing? when is having multiple instances better than just adding servers?

Dani AI

Generated

For — building on ' point about splitting functions across machines: start by measuring, not guessing. Collect system metrics (CPU, memory, disk I/O, network) and identify slow SQL with the MySQL slow query log. Summarize problematic queries with a profiler like pt-query-digest to know whether the bottleneck is code, queries, or I/O rather than simply lack of boxes. MySQL slow query log, pt-query-digest.

Common, low-risk moves come first. Offload images and other static assets to an object store + CDN and serve them with long cache headers from a cookie-free hostname to cut requests and bandwidth. Add an in-memory cache for rendered fragments or frequent query results (Redis or memcached) and use a reverse proxy (Nginx) for static caching. Amazon CloudFront CDN, Redis.

When the database is the limiter, scale reads with asynchronous replication and use connection pooling or a query router; reserve sharding for when single-master or replicas cannot meet write or dataset size needs — sharding requires application changes. Also plan sessions for multiple app servers (central store like Redis) and automation/monitoring as server count grows. Quick checklist:

  1. Profile and fix hot queries.
  2. Cache static and dynamic fragments.
  3. Add read replicas and pool connections.
  4. Add load balancer + app servers; centralize sessions.
  5. Shard only if unavoidable.

Enable the slow log quickly for data:

SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 1;

References: MySQL replication.

Recommended Answers

All 2 Replies

If you code with the intention of splitting functions accross servers, you won't find it as difficult to split a site... Spreading things out adds a security risk unless you're carefull, but somethings don't matter so much...

Images on a separate server seems quite nice, maybe even cacheable pages on another server could work... Personally I'd try to keep script and database on the same server. Otherwise, you might lose any speed benefit you could gain because one server has to "call" the other to get hold of information...

If you own your equipment, you can run "script elements" as services to minimize the time a single request cycle takes... If you don't own your own equipment, you can usually solve alot of speed and load problems by optimizing code and caching...

If space is your biggest issue; buy more. If memory is your biggest issue; buy more. If speed is your biggest issue; upgrade. If your site is really huge, you could get a dedicated custom system: lots of highspec computers, all on a local network, and all servers.

Hey thanks Matt. I was just reading about Digg. They started off with 1 server and now they have 103.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.