Skip to content

Commit

Permalink
perf: switch to sharded redis adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKolarik committed Feb 12, 2024
1 parent 630a706 commit 0598c16
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

services:
redis:
image: redislabs/rejson:latest
image: redis/redis-stack-server:latest
ports:
- 6379:6379
options: >-
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@koa/router": "^12.0.1",
"@maxmind/geoip2-node": "^4.2.0",
"@redocly/openapi-core": "^1.6.0",
"@socket.io/redis-adapter": "^8.2.1",
"@socket.io/redis-adapter": "github:MartinKolarik/socket.io-redis-adapter#dist",
"adm-zip": "^0.5.10",
"any-ascii": "^0.3.2",
"bluebird": "^3.7.2",
Expand Down
6 changes: 3 additions & 3 deletions src/lib/ws/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type RemoteSocket, Server, Socket } from 'socket.io';
import { createAdapter } from '@socket.io/redis-adapter';
import { createShardedAdapter } from '@socket.io/redis-adapter';
// eslint-disable-next-line n/no-missing-import
import type { DefaultEventsMap } from 'socket.io/dist/typed-events.js';
import type { Probe } from '../../probe/types.js';
Expand Down Expand Up @@ -32,8 +32,8 @@ export const initWsServer = async () => {
pingTimeout: 3000,
});

io.adapter(createAdapter(pubClient, subClient, {
publishOnSpecificResponseChannel: true,
io.adapter(createShardedAdapter(pubClient, subClient, {
subscriptionMode: 'static',
}));
};

Expand Down
4 changes: 2 additions & 2 deletions src/measurement/runner.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from 'config';
import type { Server } from 'socket.io';
import createHttpError from 'http-errors';
import { getWsServer } from '../lib/ws/server.js';
import { getWsServer, PROBES_NAMESPACE } from '../lib/ws/server.js';
import { getProbeRouter, type ProbeRouter } from '../probe/router.js';
import type { Probe } from '../probe/types.js';
import { getMetricsAgent, type MetricsAgent } from '../lib/metrics.js';
Expand Down Expand Up @@ -61,7 +61,7 @@ export class MeasurementRunner {
const maxInProgressProbes = config.get<number>('measurement.maxInProgressProbes');
onlineProbesMap.forEach((probe, index) => {
const inProgressUpdates = request.inProgressUpdates && inProgressProbes++ < maxInProgressProbes;
this.io.of('probes').to(probe.client).emit('probe:measurement:request', {
this.io.of(PROBES_NAMESPACE).to(probe.client).emit('probe:measurement:request', {
measurementId,
testId: index.toString(),
measurement: {
Expand Down
2 changes: 1 addition & 1 deletion test/tests/unit/measurement/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('MeasurementRunner', () => {
beforeEach(() => {
sinon.resetHistory();
to.returns({ emit });
io.of.returns({ to } as any);
io.of.withArgs('/probes').returns({ to } as any);
store.createMeasurement.resolves('measurementid');
testId = 0;
});
Expand Down

0 comments on commit 0598c16

Please sign in to comment.