Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
fixed least_loaded and agent_count queries to account only for active…
Browse files Browse the repository at this point in the history
… streams
  • Loading branch information
khodzha committed Aug 20, 2020
1 parent 88fc184 commit f560d45
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/app/endpoint/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,11 +1045,13 @@ mod test {
.insert(&conn);

// Insert active stream.
factory::JanusRtcStream::new(USR_AUDIENCE)
let stream = factory::JanusRtcStream::new(USR_AUDIENCE)
.backend(&backend)
.rtc(&rtc)
.insert(&conn);

crate::db::janus_rtc_stream::start(stream.id(), &conn).unwrap();

// Insert active agents.
shared_helpers::insert_agent(&conn, writer.agent_id(), rtc.room_id());
shared_helpers::insert_agent(&conn, reader1.agent_id(), rtc.room_id());
Expand Down
9 changes: 2 additions & 7 deletions src/db/janus_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,21 +206,16 @@ const LEAST_LOADED_SQL: &str = r#"
ON rtc.room_id = rl.room_id
LEFT JOIN janus_rtc_stream AS jrs
ON jrs.rtc_id = rtc.id
WHERE UPPER(jrs.time) IS NULL
WHERE LOWER(jrs.time) IS NOT NULL AND UPPER(jrs.time) IS NULL
GROUP BY jrs.backend_id
)
SELECT jb.*
FROM janus_backend AS jb
LEFT JOIN janus_rtc_stream AS jrs
ON jrs.backend_id = jb.id
LEFT JOIN rtc
ON rtc.id = jrs.rtc_id
LEFT JOIN janus_backend_load AS jbl
ON jbl.backend_id = jb.id
LEFT JOIN room AS r2
ON 1 = 1
WHERE r2.id = $1
AND UPPER(jrs.time) IS NULL
AND COALESCE(jb.capacity, 2147483647) - COALESCE(jbl.taken, 0) > COALESCE(r2.reserve, 0)
ORDER BY COALESCE(jb.capacity, 2147483647) - COALESCE(jbl.taken, 0) DESC
LIMIT 1
Expand All @@ -246,7 +241,7 @@ pub(crate) fn agents_count(backend_id: &AgentId, conn: &PgConnection) -> Result<
.inner_join(rtc::table.on(rtc::room_id.eq(agent::room_id)))
.inner_join(janus_rtc_stream::table.on(janus_rtc_stream::rtc_id.eq(rtc::id)))
.filter(janus_rtc_stream::backend_id.eq(backend_id))
.filter(sql("UPPER(\"janus_rtc_stream\".\"time\") IS NULL"))
.filter(sql("LOWER(\"janus_rtc_stream\".\"time\") IS NOT NULL AND UPPER(\"janus_rtc_stream\".\"time\") IS NULL"))
.filter(agent::status.eq(AgentStatus::Connected))
.select(count(agent::id))
.get_result(conn)
Expand Down

0 comments on commit f560d45

Please sign in to comment.