Page MenuHomePhabricator
Paste P29911

krinkle-tmp.php
ActivePublic

Authored by Krinkle on Jun 21 2022, 1:14 AM.
Tags
None
Referenced Files
F35257620: krinkle-tmp.php
Jun 21 2022, 1:14 AM
Subscribers
None
<?php
/*
[01:04 UTC] krinkle at mwmaint1002.eqiad.wmnet in ~
$ mwscript eval.php --wiki aawiki
> require '/home/krinkle/krinkle-tmp.php';
Done setting 6806 keys
Sleeping for 45 seconds...
Checking...
Checked 6806 keys.
Done!
*/
use MediaWiki\MediaWikiServices;
class KrinkleTmp {
const TIME_STORED = 60;
const TIME_SETTING = 5;
const TIME_WAIT = 45;
const MAX_KEYS = 10000;
public $stored = [];
public $wanCache;
public function __construct() {
$this->wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
}
public function add(int $i): void {
$key = $this->wanCache->makeGlobalKey('krinkle-tmp', 'num' . $i);
$val = 'some_interesting_data_here' . $i;
$this->stored[] = [
'key' => $key,
'val' => $val,
'res' => $this->wanCache->set($key, $val, self::TIME_STORED),
'time' => microtime(true),
];
}
public function check(array $entry): void {
$actual = $this->wanCache->get($entry['key']);
if ($actual !== $entry['val']) {
$now = microtime(true);
$this->report($entry, $now, $actual);
}
}
public function report(array $entry, $now, $actual): void {
print sprintf("Key %s was %s after %s seconds (res: %s)\n",
$entry['key'],
($actual === false ? 'missing' : json_encode($actual)),
round($now - $entry['time']),
json_encode(entry['res'])
);
}
public function execute(): void {
$t1 = microtime(true);
$i = 0;
while (
(microtime(true) - $t1) < self::TIME_SETTING &&
$i < self::MAX_KEYS
) {
$this->add($i);
$i++;
}
print "Done setting $i keys\n";
print "Sleeping for " . self::TIME_WAIT . " seconds...\n";
$this->wanCache->clearProcessCache();
sleep(self::TIME_WAIT);
print "Checking...\n";
$i = 0;
foreach ($this->stored as $entry) {
$this->check($entry);
$i++;
}
print "Checked $i keys.\n";
print "Done!\n";
}
}
$tmp = new KrinkleTmp();
$tmp->execute();