Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Q2A on main and subdomain with single user base

+5 votes
460 views
asked Mar 6 in Q2A Core by ProThoughts

@Scott, @pupi1985, If q2a is hosted on main domain and then other instances of q2a installed on subdomains, similar to stackexchange.com multiple subdomain sites.

example:  q2asite.com main site, movies.q2asite.com, maths.q2asite.com, gaming.q2asite.com, science.q2asite.com subdomains etc.

Option1: Is it good idea to keep single db and then use solution mentioned in below answer

http://www.question2answer.org/qa/11006/how-to-make-two-q2a-s-based-on-one-user-database?show=11011#a11011

I guess this will make db very big. I dont know other disadvantage. how about speed of sites impacted?...

Option2: have separate db for each site and user base from main Q2A site db (q2asite.com)

What are advantages and disadvantage both option you see? is there any other better way.

also could you please provide solution for option2 here. It will help other.

Thanks!

Q2A version: 1.7.4

4 Answers

+3 votes
answered Mar 6 by sama55

This is my personal impression (may be not a solution).

Basically, Q2A is software for making a relatively small communities, I think that it is not suitable for enterprise (huge scale) site. Especially when sharing user data with multiple sites, there are performance limitations. The reason is ... For huge sites, the load of the database must be distributed. There are several data (tables) to be distributed. The qa-blobs and qa-cache (uploaded data) and qa-users tables should be distributed most (These tables may be distributed to different web and database servers). For example, there is a drop-in called "HyperDB" in Wordpress. This drop-in seems to be effective for database replication, failover, load balancing. However, this drop-in may not be useful on truly huge sites.

commented Mar 7 by ProThoughts
@sama55, thank you. so far I have see Q2A single site with 13.5Million visits/month (http://pokemondb.net) according to similarweb.com but dont know what is the highest load it can handle. Also dont know what server config is used for http://pokemondb.net site and if they are facing any performance limitations. but Q2A can handle good traffic.

@Scott can comment on this.

Other site like stackoverflow etc can handle much large load....here is stat according to similarweb.com

visits/month
Quora.com - 373.5 million
stackoverflow.com - 312 million
stackexchange.com 200 million
Answers.com - 58 million
pokemondb.net 13.5 million (Q2A site)
+4 votes
answered Mar 7 by pupi1985

Unless I'm totally missing something, and without making any core hacks to try to modify the external user feature to be able to actually register users from Q2A, option 2 is not an option as it is not possible.

If you have a main domain with multiple sub-domains, I would expect the idea is that each sub-domain displays absolutely different questions (e.g.: the total Q/A/C displayed in the activity box would display a different number for each sub-domain). This means you will have to have different tables to store the posts (I'm using this table as an example but there are many more tables that you'll need to have exclusively for each site).

However, regarding user management you might want to store users separately for each site, which would mean you will have different user logins per site. Alternatively, you might want to have one login for a user that can be shared among all sites. Both options are possible in Q2A. The former means you'll have to setup different sites per domain (could be under the same database or not, which doesn't change performance at all) and the latter means you'll have many sites setup in the same database (which doesn't mean they will be using the same tables).

Expanding the idea of having shared users in the same database, this is achieved in a very simple way: you have to setup different sites that will all connect to the same database. Note each site will need to have a different posts table so each site will have to have their own table prefix so that they don't mix posts data between sites. However, the idea is to actually mix user data so, apart from changing the QA_MYSQL_TABLE_PREFIX it will be needed to change the QA_MYSQL_USERS_PREFIX. All sites will need to have the latter constant defined with the same value so that all sites access the same user data tables.

You're talking about advantages and disadvantages. However, I think the two approaches tackle so different issues that thinking if it is more or less performant should be beyond discussion, as there is only one option for each user management approach. Still, sharing the same users table will lock it more often. Depending on how big the sites are this might be an issue or not (I hardly believe someone here has a site that big for this to actually be noticed).

BTW, database size is something you shouldn't care at all. You should care more about row amount for each table. The more rows you have the more time you'll spend searching and the more time you will spend maintaining the index after modifying indexed data. Having all users from multiple sites in the same table will, of course, increase the amount of rows that it will store.

commented Mar 8 by Scott
@pupi I don't think you'd need a specific "registration-only" site. You can have one main Q2A site which serves as the user base for all the other sites, and that site can still have questions on it.
commented Mar 8 by pupi1985
@Scott That's correct. The thing is that the instance will be different than the rest as the rest will be using external users while that one won't. Features supported by external users are less than the ones that don't. So that site will have actually more features than the rest (for example, favouriting users). I'd rather have all sites equal to ease administration and to avoid users wondering why they can favorite users in the Movies site and not in the Gardening site
+3 votes
answered Mar 8 by ProThoughts

Here is experiment I did for this.

  1. Installed first Q2A site as normal on main domain myq2asite.com (first instance of q2a), set below parameters as

define('QA_MYSQL_TABLE_PREFIX', 'qa_');
define('QA_MYSQL_USERS_PREFIX', 'qa_');

  1. Copied files for second Q2A site(subdomain movies.myq2asite.com). (second instance of q2a).
  2. Edited qa-config.php and set the users prefix option to "qa2" modified these two lines:
    define('QA_MYSQL_TABLE_PREFIX', 'qa2_');
    define('QA_MYSQL_USERS_PREFIX', 'qa_');
  3. Now run the installation on the second site.
  4. created normal user account on myq2asite.com
  5. Login to myq2asite.com as a normal user, it works fine.
  6. Went to movies.myq2asite.com but it is again asking for username and password. so sessions are not shared between two sites.
  7. same way, I login as a normal user to movies.myq2asite.com and it works fine, then went to myq2asite.com and it is asking for username and password.

any idea how to fix this session issue?

commented Mar 9 by sama55
I recommend to read QA_BLOBS_DIRECTORY comment in qa-config.php carefully.

/*
    ...
Note than if multiple Q2A sites are using QA_MYSQL_USERS_PREFIX to share users, they must also have the same value for QA_BLOBS_DIRECTORY. If there are already some BLOBs stored in the database from previous uploads, click the 'Move BLOBs to disk' button in the 'Stats' section of the admin panel to move them to disk.
    ...
*/

Problem occurrence condition:
This issue occurs when you allow users to upload avatar.

Operation and phenomena:
Avatars uploaded on one site can not be accessed from other sites.

Cause:
Avatar is stored in the database (or file system) of the uploaded site. Other sites try to show avatar from own databases (or file system).

Solution:
1. Enable QA_BLOBS_DIRECTORY on all sites.
2. Unify the location of QA_BLOBS_DIRECTORY at all sites.

My advice.
commented Mar 9 by ProThoughts
@sama55 thank you. I will enable that and test sites again.
+2 votes
answered Apr 17 by ProThoughts

Here is solution for multi-site.

- Install first Q2A site as normal on main domain myq2asite.com (first instance of q2a), set below parameters as below in qa-config.php

define('QA_MYSQL_TABLE_PREFIX', 'qa_mainsite_');
define('QA_MYSQL_USERS_PREFIX', 'qa_users');
define('QA_COOKIE_DOMAIN', '.myq2asite.com');

- second Q2A site(subdomain site2.myq2asite.com). (second instance of q2a).

qa-config.php and set the users prefix option to "qa_users" same as main site, modify below lines:
define('QA_MYSQL_TABLE_PREFIX', 'qa_site2'); //this line is different
define('QA_MYSQL_USERS_PREFIX', 'qa_users'); //this must be same as main site
define('QA_COOKIE_DOMAIN', '.myq2asite.com'); //this must be same as main site

Now run the installation on the second site. site2.myq2asite.com, it will ask to update tables, just do that.

create normal user account on myq2asite.com

Login to myq2asite.com, it should work for admin and all users on both site.

for avatars, see comments by sama55.

...