4 * StatusNet - the distributed open-source microblogging tool
5 * Copyright (C) 2008, 2009, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
23 $shortoptions = 'u:n:b:t:x:';
24 $longoptions = array('users=', 'notices=', 'subscriptions=', 'tags=', 'prefix=');
26 $helptext = <<<END_OF_CREATESIM_HELP
27 Creates a lot of test users and notices to (loosely) simulate a real server.
29 -u --users Number of users (default 100)
30 -n --notices Average notices per user (default 100)
31 -b --subscriptions Average subscriptions per user (default no. users/20)
32 -t --tags Number of distinct hash tags (default 10000)
33 -x --prefix User name prefix (default 'testuser')
35 END_OF_CREATESIM_HELP;
37 require_once INSTALLDIR.'/scripts/commandline.inc';
39 // XXX: make these command-line options
44 $user = User::register(array('nickname' => sprintf('%s%d', $userprefix, $i),
45 'password' => sprintf('password%d', $i),
46 'fullname' => sprintf('Test User %d', $i)));
52 function newNotice($i, $tagmax)
57 $user = User::staticGet('nickname', sprintf('%s%d', $userprefix, $n));
59 $is_reply = rand(0, 4);
61 $content = 'Test notice content';
65 $content = "@$userprefix$n " . $content;
68 $has_hash = rand(0, 2);
71 $hashcount = rand(0, 2);
72 for ($j = 0; $j < $hashcount; $j++) {
73 $h = rand(0, $tagmax);
74 $content .= " #tag{$h}";
78 $notice = Notice::saveNew($user->id, $content, 'system');
89 $fromnick = sprintf('%s%d', $userprefix, $f);
91 $from = User::staticGet('nickname', $fromnick);
94 throw new Exception("Can't find user '$fromnick'.");
106 $tunic = sprintf('%s%d', $userprefix, $t);
108 $to = User::staticGet('nickname', $tunic);
111 throw new Exception("Can't find user '$tunic'.");
114 subs_subscribe_to($from, $to);
120 function main($usercount, $noticeavg, $subsavg, $tagmax)
123 $config['site']['dupelimit'] = -1;
129 // # registrations + # notices + # subs
131 $events = $usercount + ($usercount * ($noticeavg + $subsavg));
133 for ($i = 0; $i < $events; $i++)
135 $e = rand(0, 1 + $noticeavg + $subsavg);
140 } else if ($e < $noticeavg + 1) {
141 newNotice($n, $tagmax);
148 $usercount = (have_option('u', 'users')) ? get_option_value('u', 'users') : 100;
149 $noticeavg = (have_option('n', 'notices')) ? get_option_value('n', 'notices') : 100;
150 $subsavg = (have_option('b', 'subscriptions')) ? get_option_value('b', 'subscriptions') : max($usercount/20, 10);
151 $tagmax = (have_option('t', 'tags')) ? get_option_value('t', 'tags') : 10000;
152 $userprefix = (have_option('x', 'prefix')) ? get_option_value('x', 'prefix') : 'testuser';
154 main($usercount, $noticeavg, $subsavg, $tagmax);