239 Commits

Author SHA1 Message Date
Dylan K. Taylor
177b963d8e
TaskScheduler: do not push cancelled repeating tasks back onto the queue 2021-04-19 13:23:31 +01:00
Dylan K. Taylor
972c911485
phpstan 0.12.65 2021-01-09 18:04:42 +00:00
Dylan K. Taylor
a251960c1c AsyncPool: expose workerUsage to the API
this allows plugins (and maybe later on the core) to detect async worker overload and warn the user about potential performance issues.
I planned to implement such detection in the core directly, but it turned out to be a bit more complex than I anticipated. At the least, this API might be useful to someone else.
2020-10-16 21:20:49 +01:00
Dylan K. Taylor
d3ea29d527 Release memory to OS on garbage collection
ZMM often holds onto big chunks of memory after they aren't used anymore, which is fine in a webserver, but it's not OK for PM.
2020-09-09 01:40:18 +01:00
Dylan K. Taylor
5d4880b0a7 SendUsageTask: fixed json_encode() choking on player list keys 2020-07-11 20:14:04 +01:00
Dylan K. Taylor
b2249f93c0 TaskHandler: bail if given a task that already has a handler
This fixes undefined behaviour when scheduling the same task twice. This is usually accidental and almost never desirable.
Note that this still allows a task to be scheduled again after it has
been cancelled; it only disallows scheduling a task multiple times
concurrently.

This commit will probably break MyPlot and other plugins that have
self-scheduling tasks, but as far as I can tell those use-cases should
be replaced with self-cancelling repeating tasks anyway.
2020-07-08 11:02:33 +01:00
Dylan K. Taylor
d8d994351b phpstan 0.12.29 2020-06-14 16:25:55 +01:00
Dylan K. Taylor
df13e967fd imports cleanup 2020-06-14 10:27:15 +01:00
Dylan K. Taylor
c3fabe833e FileWriteTask: mark as deprecated 2020-06-10 11:22:18 +01:00
Dylan K. Taylor
8c0d441a13 Merge branch 'stable' into next-minor 2020-05-17 10:03:17 +01:00
Dylan K. Taylor
5a8917f6f2 TaskScheduler: queue contains TaskHandler, not Task 2020-05-16 15:27:20 +01:00
Dylan K. Taylor
755919c496 SendUsageTask: explicitly assume that json_encode() will not return false 2020-04-15 12:43:05 +01:00
Dylan K. Taylor
88b216a17b AsyncTask: fix another phpstan level 7 error about wrong types
this should really be a dedicated type, but everything done with pthreads sucks.
2020-04-15 12:42:18 +01:00
Dylan K. Taylor
8020912448 AsyncPool: add phpstan array type information to all fields 2020-04-15 12:40:54 +01:00
Dylan K. Taylor
5571ae05b5 AsyncPool: silence a warning about wrong key type
getTaskId() returns int|null, although it won't happen after the ID has been set.
2020-04-15 12:40:23 +01:00
Dylan K. Taylor
3907a2b6ba Process: split getMemoryUsage() into 2 functions
this isn't released yet so it's OK to change.
phpstan level 7 doesn't like these kinds of ambiguous return types because there's no way for it to tell which type is returned without a return type specifying extension, and it's easier to just change the API than to make PHPStan understand it.
2020-03-13 17:32:17 +00:00
Dylan K. Taylor
2d51971b84 Revert "ClosureTask: drop requirement for void return type"
This reverts commit 9e993aa83fafe8434c5aef1ec7e0e0190bd2f9d3.

apparently PHPStan isn't cool with this ...
2020-02-10 11:40:47 +00:00
Dylan K. Taylor
f08e411cad Merge branch 'stable' into next-minor 2020-02-10 11:40:08 +00:00
Dylan K. Taylor
1a5228e7a6 Fixed property types with missing null PhpDoc types 2020-02-05 20:55:03 +00:00
Dylan K. Taylor
260ac47588 add some phpstan array types 2020-01-30 22:23:11 +00:00
Dylan K. Taylor
0537c66849 populate missing array value types in scheduler namespace 2020-01-30 21:19:15 +00:00
Dylan K. Taylor
2b402e525a add some PHPStan-specific callable prototypes 2020-01-29 15:03:55 +00:00
Dylan K. Taylor
f624871b3f strip extra blank lines (php-cs-fixer) 2020-01-22 14:50:29 +00:00
Dylan K. Taylor
9cd6b3e1c7 fix remaining multiline @var annotations 2020-01-22 14:44:36 +00:00
Dylan K. Taylor
c4793241f5 Mass removal of useless @param/@return PHPDoc annotations, pass 1 2020-01-21 15:10:18 +00:00
Dylan K. Taylor
f5a18df835 scheduler: populate missing return type information 2020-01-19 17:11:12 +00:00
Dylan K. Taylor
1eedac87b2 added missing @var property types (reported by phpstan) 2020-01-09 14:13:54 +00:00
Dylan K. Taylor
9a67192f74 Merge branch 'stable' into next-minor 2019-12-03 10:45:51 +00:00
Dylan K. Taylor
0890b5fc99 AsyncPool: assert() that the unstacked task is actually an AsyncTask
it's possible that it might not be if the workers were accessed directly, but that shouldn't be possible.
This also silences a PHPStan warning on level 2.
2019-12-01 19:28:05 +00:00
Dylan K. Taylor
0591458ef6 Merge branch 'stable' into next-minor 2019-10-22 18:49:22 +01:00
Dylan K. Taylor
e198c8fa8b Task: mark taskHandler field as nullable 2019-10-22 10:26:49 +01:00
Dylan K. Taylor
cde2c10c1d AsyncTask: partial backport of 6ac0c517f54dc83fc23f41a6797c14e1f4b457a1 (simplify TLS)
- deprecated AsyncTask::peekLocal()
- AsyncTask::fetchLocal() no longer deletes stored data
2019-07-27 15:09:42 +01:00
Dylan K. Taylor
87fb42cabd Merge branch 'stable' into next-minor 2019-07-27 14:53:13 +01:00
Dylan K. Taylor
cb40484a2e AsyncTask: Remove a bunch of reference-management drivel from documentation of storeLocal()
this works (mostly) the same way regular properties do, so the usual rules are implied.
2019-07-27 14:52:53 +01:00
Dylan K. Taylor
6566dd8c8f AsyncPool: Remove useless warning about complex data leftovers
this is automatically cleaned up anyway, so this warning is just redundant noise.
2019-07-27 14:44:40 +01:00
Dylan K. Taylor
1e65ac0d85 Merge branch 'stable' into next-minor 2019-07-27 14:40:31 +01:00
Dylan K. Taylor
e75a08a5a3 AsyncPool: ensure TLS is always cleaned on task removal, closes #3059 2019-07-27 14:39:40 +01:00
Dylan K. Taylor
cb247a5f28 AsyncTask: Deprecate methods removed in 2c4f2810d2654375c2b834fe12999b465bfa2caf 2019-07-26 19:52:26 +01:00
Dylan K. Taylor
bb048fb361 Merge branch 'stable' into next-minor 2019-07-26 19:50:17 +01:00
Dylan K. Taylor
d55889d85f AsyncTask: fixing docs 2019-07-26 19:41:45 +01:00
Dylan K. Taylor
99f65f19ac BulkCurlTask: point to the right place in docs 2019-07-26 19:18:09 +01:00
Dylan K. Taylor
581eeee01d fix rogue @package doc making doxygen choke 2019-07-26 19:15:02 +01:00
Dylan K. Taylor
9e993aa83f ClosureTask: drop requirement for void return type
this creates unnecessary boilerplate for many inline usages.
2019-07-01 17:19:19 +01:00
Dylan K. Taylor
4635b93f4d backport 23071d257 + deprecations: Extract process-related functions from Utils into a separate Process class 2019-06-16 14:40:51 +01:00
Dylan K. Taylor
4eaea54b0e TaskScheduler: fixed wrong typehints
These methods never return null.
2019-02-22 17:47:28 +00:00
Dylan K. Taylor
4b9a142a5d Import global functions and constants for enhanced performance
This is better for performance because these then don't need to be reevaluated every time they are called.

When encountering an unqualified function or constant reference, PHP will first try to locate a symbol in the current namespace by that name, and then fall back to the global namespace.
This short-circuits the check, which has substantial performance effects in some cases - in particular, ord(), chr() and strlen() show ~1500x faster calls when they are fully qualified.

However, this doesn't mean that PM is getting a massive amount faster. In real world terms, this translates to about 10-15% performance improvement.
But before anyone gets excited, you should know that the CodeOptimizer in the PreProcessor repo has been applying fully-qualified symbol optimizations to Jenkins builds for years, which is one of the reasons why Jenkins builds have better performance than home-built or source installations.
We're choosing to do this for the sake of future SafePHP integration and also to be able to get rid of the buggy CodeOptimizer, so that phar and source are more consistent.
2019-01-04 20:43:15 +00:00
Dylan K. Taylor
6bd1491b8b AsyncPool: Apply a cooldown to workers to cut down unnecessary GC lag spikes
Since 3.2 there have been some runtime performance issues related to garbage collection and dynamic AsyncWorker booting. This is partly because of GC being dumb about shutting down what it thinks are "unused" workers. A worker which has been idle for a single tick is considered the same as a worker which has been idle for hours. The result of this is that on active servers, workers would get shut down and then immediately restarted because of something like chunk sending. Since booting an async worker is frightfully expensive, this causes lag spikes, which is obviously bad.

This commit changes the GC mechanism to only shutdown workers which have not been used for the last 5 minutes.
2019-01-03 15:06:53 +00:00
Dylan K. Taylor
a95694ed06 Add signature validation for some user-defined callbacks 2018-12-04 18:33:58 +00:00
Dylan K. Taylor
e26af3fa1b TaskScheduler: don't catch unexpected exceptions
this means that errors in scheduled tasks which are uncaught will now cause a server crash.
2018-11-04 23:22:30 +00:00
Dylan T
755db3dac8
Added a ClosureTask implementation for easier task scheduling (#2497) 2018-11-04 22:55:40 +00:00