1

输入:

一个数据库,包括

  • 不随用户数量或时间扩展的静态表
  • 当用户与应用程序交互时增长的动态表(因此随着用户数量和时间而扩展)
  • 包含 x 个用户的真实数据的数据库

任务:

  • 扩展数据库以模拟更多用户

例子:

Tables: 

t_user (scale target)
UserId , Name
1 , John
2, Terry

t_post (dynamic)
AuthorId, PostId, TagId
1, 1 , 1
1, 2 , 2
1, 3 , 2
2, 4 , 1

t_tag (static)
TagId, Name
1, C#
2, Java

比例因子 = 2 的所需输出

t_user
UserId , Name
1 , John
2, Terry
3 , John
4, Terry

t_post (dynamic)
AuthorId, PostId, TagId
1, 1 , 1
1, 2 , 2
1, 3 , 2
2, 4 , 1
1, 5 , 1
1, 6 , 2
1, 7 , 2
2, 8 , 1

t_tag (static)
TagId, Name
1, C#
2, Java

当然,对于这么小的数据库,这可以在 MySQL 中完成,但我需要一个适用于具有 150 多个表的数据库的解决方案(为每个表编写扩展例程不是解决方案)和将数据库从 100 变为多达 10 000 个用户。

有谁知道可以做到这一点的专用工具或黑客?

4

2 回答 2

0

Benchmark Factory for Databases看起来可以满足您的需求,或者您可以尝试使用MySQL Benchmark Tool 。

于 2013-02-02T23:47:10.153 回答
0

我最终编写了自己的脚本。您将在下面找到一个简化版本(为清楚起见,省略了表格中的许多列)。这工作得很好。我能够非常有效地将数据库扩展 100 倍。希望这可以帮助

SET autocommit = 0;

START TRANSACTION;

SET @UMAX = (SELECT MAX(UserID) AS MX FROM t_user);
SET @QSMAX = (SELECT MAX(QuestionSetID) AS MX FROM t_question_set);
SET @QGMAX = (SELECT MAX(QuestionGroupID) AS MX FROM t_question_group);
SET @QMAX = (SELECT MAX(QuestionID) AS MX FROM t_question);
SET @TMAX = (SELECT MAX(TestID) AS MX FROM t_test);


DROP TABLE IF EXISTS t_seq;
CREATE table t_seq AS
    (
    SELECT
        1 S
    );
INSERT INTO t_seq (S) VALUES (2),(3),(4),(5),(6),(7),(8),(9),(10);    


INSERT INTO `t_user`
    (
        `UserID`,
        `Login`,
        `Password`,
    )
SELECT
    `UserID` + 1000000 + @UMAX * t_seq.S,
    concat(if(Login is null, '', Login), `UserID` + 1000000 + @UMAX * t_seq.S),
    `Password`,
FROM t_user,
    t_seq;

INSERT INTO `t_question_set`(`QuestionSetID`) 
SELECT `QuestionSetID` + 1000000 + @QSMAX * t_seq.S 
FROM t_question_set,t_seq;   

INSERT INTO `t_question_group`(
    `QuestionGroupID`, 
    `QuestionSetID`
    )
SELECT 
  `QuestionGroupID` + 1000000 + @QGMAX * t_seq.S,  
  `QuestionSetID` + 1000000 + @QSMAX * t_seq.S, 
FROM t_question_group,t_seq;

INSERT INTO `t_question`(`QuestionID`, `QuestionGroupID`)
SELECT
  `QuestionID` + 1000000 + @QMAX * t_seq.S, 
  `QuestionGroupID` + 1000000 + @QGMAX * t_seq.S, 
FROM t_question, t_seq;

INSERT INTO `t_test`
    (
        `TestID`,
        `QuestionSetID`,
        `UserID`,
            )
SELECT
    `TestID` + 1000000 + @TMAX * t_seq.S,
    `QuestionSetID` + 1000000 + @QSMAX * t_seq.S,
    `UserID` + 1000000 + @UMAX * t_seq.S,
FROM t_test,t_seq;

INSERT INTO `t_question_answer`(
    `QuestionID`, 
    `TestID`
    )
SELECT 
  `QuestionID` + 1000000 + @QMAX * t_seq.S,
  `TestID` + 1000000 + @TMAX * t_seq.S,
FROM t_question_answer,t_seq;

COMMIT;
于 2013-03-30T15:53:21.233 回答