Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions app/Models/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Observers\RoomObserver;
use App\Settings\GeneralSettings;
use App\Traits\AddsModelNameTrait;
use HiFolks\Statistics\Stat;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -18,6 +19,7 @@
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Support\Facades\Context;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\Rule;

#[ObservedBy([RoomObserver::class])]
Expand Down Expand Up @@ -430,4 +432,54 @@ public function streaming(): HasOne
]
)->chaperone('room');
}

/**
* Get the estimated max participants of the room based on the last x meetings.
*/
public function getEstimatedMaxParticipants(int $limit = 10): ?int
{
$meetings = $this->meetings()
->whereNotNull('end')
->whereNotNull('start')
->limit($limit);

$db = DB::connection()->getConfig();

// Get only meetings that lasted at least 10 min.
switch ($db['driver']) {
case 'mariadb':
case 'mysql':
$meetings->whereRaw('end > start + INTERVAL 10 MINUTE');
break;
case 'pgsql':
$meetings->whereRaw("end - start > INTERVAL '10 minutes'");
break;
default:
throw new \Exception('Database driver not supported');
}

$meetings = $meetings->pluck('id');

if ($meetings->isEmpty()) {
return null;
}

$maxParticipants = MeetingStat::whereIn('meeting_id', $meetings)
->groupBy('meeting_id')
->selectRaw('max(participant_count) as max_participants')
->orderBy('created_at')
->pluck('max_participants');

if ($maxParticipants->isEmpty()) {
return null;
}

// Calculate weighted median
// Using median over average to compensate outliners
// Use a weighted median to give more weight to newer meetings, as they are more relevant for the future than older meetings
$weights = range(1, $maxParticipants->count());
$weightedMedian = Stat::weightedMedian($maxParticipants->toArray(), $weights);

return (int) ceil($weightedMedian);
}
}
11 changes: 10 additions & 1 deletion app/Plugins/Defaults/ServerLoadCalculationPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
namespace App\Plugins\Defaults;

use App\Plugins\Contracts\ServerLoadCalculationPluginContract;
use BigBlueButton\Core\Meeting;
use Carbon\Carbon;

class ServerLoadCalculationPlugin implements ServerLoadCalculationPluginContract
{
/**
* @param Meeting[] $meetings
*/
public function getLoad(array $meetings): int
{
$load = 0;
Expand All @@ -24,7 +28,12 @@ public function getLoad(array $meetings): int

// If meeting is in the starting phase, we use a higher number of users to calculate
// the load to compensate that the meeting will probably have more users in the future
$minUserCount = config('bigbluebutton.load_new_meeting_min_user_count');

// Use bbb-meeting-size-hint metadata if provided, fallback to fixed configurable value.
// (bbb-meeting-size-hint is set by PILOS based on previous meetings, other frontends e.g. an LMSs might set it to the class size, etc.)
$metadata = $meeting->getMetas();
$meetingSizeHint = isset($metadata['bbb-meeting-size-hint']) && is_numeric($metadata['bbb-meeting-size-hint']) ? (int) $metadata['bbb-meeting-size-hint'] : null;
$minUserCount = $meetingSizeHint ?? config('bigbluebutton.load_new_meeting_min_user_count');

// However if the meeting has a max user limit the meeting will never go over that limit,
// so we use the max user limit to calculate the load if it is lower than the min user count
Expand Down
5 changes: 5 additions & 0 deletions app/Services/MeetingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public function start(): ?CreateMeetingResponse
$meetingParams->addMeta('bbb-origin', 'PILOS');
$meetingParams->addMeta('pilos-sub-spool-dir', config('recording.spool-sub-directory'));

$estimatedMax = $this->meeting->room->getEstimatedMaxParticipants(config('bigbluebutton.meeting_size_hint_meetings_count'));
if ($estimatedMax !== null) {
$meetingParams->addMeta('bbb-meeting-size-hint', (string) $estimatedMax);
}

// get files that should be used in this meeting and add links to the files
$files = $this->meeting->room->files()->where('use_in_meeting', true)->orderBy('default', 'desc')->get();
foreach ($files as $file) {
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"ext-zip": "*",
"directorytree/ldaprecord-laravel": "^4.0",
"guzzlehttp/guzzle": "^7.0.1",
"hi-folks/statistics": "^1.5",
"laravel/fortify": "^1.36",
"laravel/framework": "^13.2",
"laravel/horizon": "^5.21",
Expand Down
55 changes: 54 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/bigbluebutton.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

'load_new_meeting_min_user_count' => (int) env('BBB_LOAD_MIN_USER_COUNT', 15),
'load_new_meeting_min_user_interval' => (int) env('BBB_LOAD_MIN_USER_INTERVAL', 15),
'meeting_size_hint_meetings_count' => (int) env('BBB_MEETING_SIZE_HINT_MEETINGS_COUNT', 10),

'allowed_name_characters' => env('BBB_ALLOWED_NAME_CHARACTERS', "\w ,.'\-+\/&()"),

Expand Down
Loading