Advanced

Re: Accessing Public Attributes in PGC API Calls

Accessing Public Attributes in PGC API Calls
June 12, 2021 03:06PM
Hello,

https://project-gc.com/doxygen/lua-sandbox/classPGC__LUA__Sandbox.html descripts that MAXCPUTIME is available as a public attribute

const MAXCPUTIME = 60

However attempting to access it as PGC.MAXCPUTIME appears to give me an error.

Am I missing the syntax or does a function need to be defined to grant access to this?

I can see this being useful so project-gc can adjust the times scripts take to manage load and scripts can tailor their computation.

Thanks.
Re: Accessing Public Attributes in PGC API Calls
June 12, 2021 04:18PM
Do you mean this?

local args = {...}
local env = args[1].environmentSettings

PGC.print(env.maxExecutionTime)

local deadline = os.time()+env.maxExecutionTime-5

to end:

if (os.time > deadline) then
"abort"
end



Edited 1 time(s). Last edit at 06/12/2021 04:20PM by pieterix. (view changes)
Re: Accessing Public Attributes in PGC API Calls
June 12, 2021 09:26PM
That is what I am looking to do.

Is the Doxygen documentation out of date about MAXCPUTIME?
Re: Accessing Public Attributes in PGC API Calls
June 26, 2021 09:39PM
It's more that I didn't know that the consts showed up in the documentation at all. The danger of automatic documentation I guess.
Re: Accessing Public Attributes in PGC API Calls
June 26, 2021 11:46PM
Another question that is more curious. os.time measures wallclock time.

The CPUtime name of the variable suggests that os.clock is the better as a measure of "time" so that stalled CPU's. Also the language in the template talks about CPUusage. CPU time can pass more slowly than wall time.

What sort of time is the limit really measured in? Also as sometime checkers need to wait for tokens is this time included or not in the quota?
Re: Accessing Public Attributes in PGC API Calls
June 27, 2021 09:23AM
LUA is executed using MediaWiki's LuaSandbox. Max memory usage and Max cpu time is handled by their code entirely.

I don't know how well documented it is what it's actually doing, I never looked it up. When switching sandbox implementation I just checked that it worked reasonable. From Project-GC's perspective it didn't really matter if it was 30 or 40 seconds for example, but there needs to be some kind of max.

Queuing for tokens and other pre/post code is not included. Since the max-settings are set for the sandbox, it's that code alone. Here is some cut'n'paste code of how it's setup (not all callbacks included).

$sandbox = new LuaSandbox();
$sandbox->setMemoryLimit( PGC_LUA_Sandbox::MAXMEM );
$sandbox->setCPULimit( PGC_LUA_Sandbox::MAXCPUTIME );
PGC_LUA_Sandbox::$sandbox = $sandbox;
$sandbox->registerLibrary('PGC', [
	'GetCPUUsage' => function() {
		return [PGC_LUA_Sandbox::$sandbox->getCPUUsage()];
	},
	'Log' => 'PGC_LUA_Sandbox::Log',
	'GetFinds' => 'PGC_LUA_Sandbox::GetFinds',
	'GetHides' => 'PGC_LUA_Sandbox::GetHides',
	'HTMLEscape' => 'PGC_LUA_Sandbox::HTMLEscape',
]);

Sorry, you do not have permission to post/reply in this forum.