208 Commits

Author SHA1 Message Date
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
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
e198c8fa8b Task: mark taskHandler field as nullable 2019-10-22 10:26:49 +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
e75a08a5a3 AsyncPool: ensure TLS is always cleaned on task removal, closes #3059 2019-07-27 14:39:40 +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
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
Dylan K. Taylor
0543c17849 Merge branch 'release/3.3' into release/3.4 2018-11-04 22:15:46 +00:00
Dylan K. Taylor
046c39b02e Remove some Throwable abuse in AsyncTasks 2018-11-04 22:15:06 +00:00
Dylan K. Taylor
87b471ce0f AsyncPool: reverse e0d5c79848335ae9335686fd896e593324f2b191, don't catch unexpected exceptions thrown by onCompletion()
this should never throw an uncaught exception, and if it does it indicates broken code.
2018-11-04 22:09:30 +00:00
Dylan K. Taylor
9caf62778c AsyncTask: remove $serialize parameter from setResult()
Whether serialization is necessary can be determined automatically based on the type of variable.
2018-11-03 16:56:24 +00:00
Dylan K. Taylor
f0182c9996 TaskHandler: remove incorrect internal warning
this is perfectly fine to use, and preferable to getting a cyclic ref to the scheduler. TaskScheduler->cancelTask() does pretty much the exact same thing, and the scheduler internals are designed to deal with this anyway.
2018-11-03 12:12:02 +00:00
Dylan K. Taylor
ab48d85c35 Properly deal with anonymous tasks in timings 2018-10-31 18:51:30 +00:00
Dylan K. Taylor
45c9caa38c Fixup some formatting issues 2018-10-21 18:15:25 +01:00
Dylan K. Taylor
2858db430e Fixed AsyncTask publishProgress() race condition on task exit
It's possible for a progress update to be lost due to the task finishing before the main thread found the progress update.
2018-10-10 13:41:15 +01:00
Dylan K. Taylor
f3f229ef7c Internet: only catch InternetExceptions - anything else is an unexpected fault condition 2018-08-04 14:51:26 +01:00
Dylan K. Taylor
6614183c7f Merge branch 'release/3.1' into release/3.2 2018-08-03 20:07:52 +01:00
Dylan K. Taylor
87f458f9bd AsyncPool: remove now-unnecessary isTerminated() call 2018-08-03 20:07:37 +01:00
Dylan K. Taylor
5a7e575c3a AsyncPool: isCrashed() now returns true when a fatal error occurred
the fix for chunks earlier didn't fix...
2018-08-03 20:06:41 +01:00
Dylan K. Taylor
706c620d04
Move Internet-related functions from Utils into their own class (#2324)
- Added `Internet::getIP()`, `Internet::getURL()`, `Internet::postURL()`, and `Internet::simpleCurl()`.
- Deprecated the corresponding functions in `Utils`. Updating to the new functions is as simple as replacing `Utils` with `Internet`, since this doesn't break backwards compatibility.

The deprecations should be catered for by plugin developers. These deprecated redirects will be removed no later than 4.0.0.
2018-07-25 15:51:18 +01:00
Dylan K. Taylor
2e18fe710c MemoryManager: Shut down idle workers during GC to reclaim memory
workers can be a major memory hog, especially if you have lots of them.
2018-07-14 18:07:37 +01:00
Dylan K. Taylor
53068caf3c Level: Only register generators when attempting to actually generate chunks
This saves a ton of memory on servers which don't generate any chunks during their runtime (which is most servers).
2018-07-14 11:34:55 +01:00
Dylan K. Taylor
95787c2be9 TaskScheduler: fixed tasks not getting destroyed when all tasks in scheduler are cancelled before next heartbeat
they got removed from the tasks array, but not from the queue (for performance reasons). The queue gets cleaned up by the heartbeat, but it was checking if there were things in the main array, not in the queue.

There are a couple of other bugs with cancelling tasks that this doesn't fix that are rather more complicated to deal with.
2018-06-21 12:49:08 +01:00
Dylan K. Taylor
80daaf09b2 SendUsageTask: fixed oops x2 (thanks PhpStorm)
looks like this file was somehow missed during the refactor.
2018-06-18 12:08:55 +01:00
Dylan K. Taylor
da6439e3f4 SendUsageTask: fixed oops 2018-06-17 16:13:05 +01:00
Dylan K. Taylor
05af87e1d4 Strip empty lines at the end of classes 2018-06-11 13:19:23 +01:00
Dylan K. Taylor
3be6665e3d AsyncWorker IDs now start from 0 instead of 1
this now matches their IDs in the AsyncWorker pool, as used by submitTask().
2018-06-11 11:58:24 +01:00
Dylan K. Taylor
17607b8116 AsyncPool: added some void typehints 2018-06-11 10:41:40 +01:00
Dylan K. Taylor
4c98d9d3ad AsyncPool: add a type doc to $size 2018-06-11 10:40:01 +01:00
Dylan K. Taylor
7d5b3079bc AsyncPool: more documentation 2018-06-11 10:38:51 +01:00
Dylan K. Taylor
88d83e0fca AsyncPool: Lazy-start AsyncWorkers when they are needed only
This changes how the AsyncPool works so that it does not immediately always start all of the workers in the pool.
Instead, workers will be started only when an idle worker was not found.
This allows for significant memory footprint reductions while idle.

In effect the async-workers setting in pocketmine.yml now dictates a _maximum_ pool size, not a fixed pool size.
2018-06-11 10:23:46 +01:00
Dylan K. Taylor
3725bea3e5 AsyncPool: Slightly reduce worker memory usage with more conservative start options
this results in a memory footprint reduction of maybe 4MB for a total of 8 workers. Not much, but it's something.
2018-06-10 10:18:07 +01:00
Dylan K. Taylor
c327b3d2c4 AsyncPool: be less dependent on Server in the code
The goal is to remove the Server things from here completely.
2018-06-08 20:08:23 +01:00
Dylan K. Taylor
b331f8e1c9 AsyncWorker: added removeFromThreadStore()
and use it instead of overwriting with null things, which still occupies memory
2018-06-07 10:12:50 +01:00
Dylan K. Taylor
ee787974f2 AsyncWorker: Use statics for thread-local worker storage instead of globals 2018-06-07 09:59:32 +01:00
Dylan K. Taylor
1a21041d00 AsyncPool: Parameterize worker memory limit instead of calling back into Server 2018-06-06 18:00:56 +01:00
Dylan K. Taylor
35eaf38ca1 MemoryManager: parameterize an abstract \Logger to remove dependency on MainLogger 2018-06-04 13:30:48 +01:00
Dylan K. Taylor
1d71f0cf43 AsyncWorker: added getLogger() 2018-06-04 13:29:38 +01:00