MyBB Community Forums

Full Version: 2 Servers using 1 MyBB database. Works, but glitchy...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
G'day,

I'm about to push my 5th revision of my website out the door and I was wondering if you could help me with this. What I intend to do, is to "load balance" a single MyBB install over 2 servers, so people can choose which server is closest to them. Let me visualize it for you:

Tomoyo - Main workhorse. Runs the "main" copy of MyBB, hosts the SQL database, hosts the theme files, etc.
Nagato - Secondary workhouse. Runs the same copy of MyBB that I have setup on Tomoyo and also hosts the theme resources, and talks to Tomoyo over a SQL Remote link on a non-standard port.

EDIT: You can see this at work here: hxxp://coburndomain.net . Pick Nagato as the mirror. Nagato is the one that talks to Tomoyo.

I have a rsync crontab that watches any file changes, and will sync them between the servers every 5 minutes.

Now, the thing is, I was wondering if anyone would be able to tell me how I could make it so if someone hits up nagato.domain.com, then MyBB will use the assets (theme images, etc) loaded on that server? At the moment, I can see the system is only designed for one domain install, so if you hit up the other mirror, it'll load the assets and everything off the "main" server, not the one I want it too - that means, all the requests go to tomoyo, which could be under heavy fire and make the software lag.

Simpler form could be this:
if incoming hostname detected by myBB = tomoyo, then set board URL settings (like "Board URL", "Home URL") to tomoyo.domain.com. If incoming hostname detected by myBB = nagato, then set board URLs to nagato.domain.com, etc.

It should not be too hard, maybe I have to hijack a setting or two? Any help would be appreciated!
Bump.

Please help me out with this issue. All I want is something that will sense what server I'm on, and will change the things appropriately.

The thing is at the moment that if I change settings on Tomoyo, it causes Nagato to make all links point to the main tomoyo.domain.com server, not nagato.domain.com.
look at my subdomain split plugin for how I handled similar needs

http://community.mybb.com/thread-71387.h...=subdomain
3 things to consider

1)
Optimize database ==>> because optimized database takes half the load of unoptimized database (so now you don't need any load balancing) - hire guys for database optimizing or do it yourself using google search , check your currnt load and check after load after optimizing Smile


2)
second choice is pure load balancing

7200 rpm drive is very slow, and take high respond time for higher load and in peak hours, 15k hard disk raids can handle much larger load [DONT USE SSD - SOLID STATE DRIVES, IT IS NOT STABLE CRASH AT ANY TIME AND YOU NOT ABLE TO RECOVER ANY DATA - YOU LOSE ALL]

mate you have 15k rpm HDD for database...?? if no means, move the database to 15k rpm drive, it handle much greater load effectively than normal 7200 rpm drives(most host have 7200 rpm drives only)

Load balancing = 2 or more server in same datacenter(same location)
Geo-loadbalancing = 2 or more server in different location or different country

First analyse your site with google analytics and add some other external stats (Crazystats from hortscripts - free stat script) and find the country/most visitors , then if you need host database in the most traffic country.

Ban bots using stopforumspam

if you need complex load balancing means, setup 2 servers ==>>
one db for read,
and other db for write

Master - slave

write takes lot of time, but read takes less time
this is what the corporate do, seperate servers for read/write


3)
cdn or cloud hosting for database
they take care of all Smile
Actually, I shouldn't have used the word 'load balancing'. Mirroring seems a better word to use in this setup.

One server is in Japan, the other is in USA. Japan one is fastest of the two, the other one does it's SQL via a remote link to the Japan one. That's why you get 2 - 3sec lag on nagato, it's busy talking over the MySQL link. I think I might need to tweak mySQL to see if I can speed it up a tad, both servers are on gigabit lines.

Quoted from the link that pavemen posted:
Quote:oh, and it will also change the 'bburl' variable in memory so all links stay within the subdomain

That's exactly what I need to do. Basically, I need something to "hijack" the bburl variable so that if you're on nagato.domain.com and something's modified the settings on either domain (thus causing all the post URLs to change to <server>.domain.com), it will still overwrite the in-memory bburl variable in $settings so regardless of what's stored in settings.php or the db.

I thought of hacking inc/settings.php and at the end of it putting:
$settings['bburl'] = "http://".trim(file_get_contents('/etc/hostname')).".domain.com/boards/"; 
...but when MyBB updates the settings.php file, would that get hosed (as in, it deletes everything in that file, and inserts it's new settings)? Or would MyBB just ignore my edits and append the setting vars at the end of the file?
again, see the plugin I posted above
You can solve all this by using Cloudflare imho.

This is what they do. They'll load balance and CDN based on geo location.

You can also get a pure CDN like maxCDN.com and just make sure all your site images,javascripts, and CSS point to the CDN. I use a CDN in this way for Hackforums.

What your doing is less efficient and a lot of work just to potentially save 1-3 seconds per page load.

My pings:
Tomoyo 126ms
Nagato 74ms

It's not even 1 second difference.

Load balancing and especially geo-load balancing are only going to be a benefit if you're serving a ton of content and the servers are over loaded. It's "LOAD" balancing. Are you really expecting that one single http serving can't handle the visitors?

At HF I serve one of the largest size pages to the largest audience and I'm only using about 5mb of pipe with average traffic and normal server load is 40% that's serving about 1.5 million page views per day.

So I just think you're over complicating it and over thinking it.

Quote:One server is in Japan, the other is in USA. Japan one is fastest of the two, the other one does it's SQL via a remote link to the Japan one. That's why you get 2 - 3sec lag on nagato, it's busy talking over the MySQL link. I think I might need to tweak mySQL to see if I can speed it up a tad, both servers are on gigabit lines.

You won't avoid that. I was having lag with a LAN datacenter just going to a new router. I had to ask my datacenter to put my SQL server in the same router to get rid of the lag. It's just not wise to run an SQL on a big site at another datacenter.

IMHO consider one great datacenter in EU and split the difference. Get one great HTTP server, one great DB server, and use something like a CDN or Cloudflare for static delivery.