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::register(array('nickname' => sprintf('%s%d', $userprefix, $i),
45 'password' => sprintf('password%d', $i),
46 'fullname' => sprintf('Test User %d', $i)));
49 function newNotice($i, $tagmax)
54 $user = User::staticGet('nickname', sprintf('%s%d', $userprefix, $n));
56 $is_reply = rand(0, 4);
58 $content = 'Test notice content';
62 $content = "@$userprefix$n " . $content;
65 $has_hash = rand(0, 2);
68 $hashcount = rand(0, 2);
69 for ($j = 0; $j < $hashcount; $j++) {
70 $h = rand(0, $tagmax);
71 $content .= " #tag{$h}";
75 $notice = Notice::saveNew($user->id, $content, 'system');
83 $fromnick = sprintf('%s%d', $userprefix, $f);
85 $from = User::staticGet('nickname', $fromnick);
88 throw new Exception("Can't find user '$fromnick'.");
100 $tunic = sprintf('%s%d', $userprefix, $t);
102 $to = User::staticGet('nickname', $tunic);
105 throw new Exception("Can't find user '$tunic'.");
108 subs_subscribe_to($from, $to);
111 function main($usercount, $noticeavg, $subsavg, $tagmax)
117 // # registrations + # notices + # subs
119 $events = $usercount + ($usercount * ($noticeavg + $subsavg));
121 for ($i = 0; $i < $events; $i++)
123 $e = rand(0, 1 + $noticeavg + $subsavg);
128 } else if ($e < $noticeavg + 1) {
129 newNotice($n, $tagmax);
136 $usercount = (have_option('u', 'users')) ? get_option_value('u', 'users') : 100;
137 $noticeavg = (have_option('n', 'notices')) ? get_option_value('n', 'notices') : 100;
138 $subsavg = (have_option('b', 'subscriptions')) ? get_option_value('b', 'subscriptions') : max($usercount/20, 10);
139 $tagmax = (have_option('t', 'tags')) ? get_option_value('t', 'tags') : 10000;
140 $userprefix = (have_option('x', 'prefix')) ? get_option_value('x', 'prefix') : 'testuser';
142 main($usercount, $noticeavg, $subsavg, $tagmax);