Skip to content

NodeBB Global Tchat : Forum with many users performance issues

Solved Configure
  • Like you know I use glolbal chat plugin
    We had a massive influx of registrations and new members which means that they all integrate the chat room of the plugin

    We see this topic on github plugin page :

    I see maybe a solution here dating from 2019 : https://github.com/NodeBB/nodebb-plugin-global-chat/issues/5#issuecomment-492242438

    7bc1e6f9-542e-41d9-96aa-8a717d6bd538-image.png

    I then asked the question to the staff without an answer :

    Is this still relevant?
    Where in the file should I put the code?

    So I’m opening this topic to find out what you think about it with your expert eye 😉

  • Like you know I use glolbal chat plugin
    We had a massive influx of registrations and new members which means that they all integrate the chat room of the plugin

    We see this topic on github plugin page :

    https://github.com/NodeBB/nodebb-plugin-global-chat/issues/5

    I see maybe a solution here dating from 2019 : https://github.com/NodeBB/nodebb-plugin-global-chat/issues/5#issuecomment-492242438

    7bc1e6f9-542e-41d9-96aa-8a717d6bd538-image.png

    I then asked the question to the staff without an answer :

    Is this still relevant?
    Where in the file should I put the code?

    So I’m opening this topic to find out what you think about it with your expert eye 😉

    @DownPW I’d say that this was still relevant, and would solve the short term issue (in most cases) but if anything, you’ll still experience slowness if you have say 600 users online.

    The right way to handle this in my view would be to pass the notification stream to a message queuing service (like RabbitMQ or Redis) and let that process in the back end rather than cause locking on the forum itself. I’m surprised that this is in fact the case as standard emails are being queued and aren’t sent in real time.

    I personally don’t use this plugin as you know, so I’d need to review the code first in order to understand it’s structure.

  • @DownPW I’d say that this was still relevant, and would solve the short term issue (in most cases) but if anything, you’ll still experience slowness if you have say 600 users online.

    The right way to handle this in my view would be to pass the notification stream to a message queuing service (like RabbitMQ or Redis) and let that process in the back end rather than cause locking on the forum itself. I’m surprised that this is in fact the case as standard emails are being queued and aren’t sent in real time.

    I personally don’t use this plugin as you know, so I’d need to review the code first in order to understand it’s structure.

    @phenomlab said in NodeBB Global Tchat : Forum with many users performance issues:

    I’d say that this was still relevant, and would solve the short term issue (in most cases) but if anything, you’ll still experience slowness if you have say 600 users online.
    The right way to handle this in my view would be to pass the notification stream to a message queuing service (like RabbitMQ or Redis) and let that process in the back end rather than cause locking on the forum itself. I’m surprised that this is in fact the case as standard emails are being queued and aren’t sent in real time.
    I personally don’t use this plugin as you know, so I’d need to review the code first in order to understand it’s structure.

    Thank you for your analyse 👍

    I would have liked to try the thing all the same, just to see the result

    600 users is better than 4000 😉

    Here is the content of the /src/messsagin/notification.js file

    I put it here because I don’t see where to integrate the given code for test :

    'use strict';
    const winston = require('winston');
    const user = require('../user');
    const notifications = require('../notifications');
    const sockets = require('../socket.io');
    const plugins = require('../plugins');
    const meta = require('../meta');
    module.exports = function (Messaging) {
    Messaging.notifyQueue = {}; // Only used to notify a user of a new chat message, see Messaging.notifyUser
    Messaging.notifyUsersInRoom = async (fromUid, roomId, messageObj) => {
    let uids = await Messaging.getUidsInRoom(roomId, 0, -1);
    uids = await user.blocks.filterUids(fromUid, uids);
    let data = {
    roomId: roomId,
    fromUid: fromUid,
    message: messageObj,
    uids: uids,
    };
    data = await plugins.hooks.fire('filter:messaging.notify', data);
    if (!data || !data.uids || !data.uids.length) {
    return;
    }
    uids = data.uids;
    uids.forEach((uid) => {
    data.self = parseInt(uid, 10) === parseInt(fromUid, 10) ? 1 : 0;
    Messaging.pushUnreadCount(uid);
    sockets.in(`uid_${uid}`).emit('event:chats.receive', data);
    });
    if (messageObj.system) {
    return;
    }
    // Delayed notifications
    let queueObj = Messaging.notifyQueue[`${fromUid}:${roomId}`];
    if (queueObj) {
    queueObj.message.content += `\n${messageObj.content}`;
    clearTimeout(queueObj.timeout);
    } else {
    queueObj = {
    message: messageObj,
    };
    Messaging.notifyQueue[`${fromUid}:${roomId}`] = queueObj;
    }
    queueObj.timeout = setTimeout(async () => {
    try {
    await sendNotifications(fromUid, uids, roomId, queueObj.message);
    } catch (err) {
    winston.error(`[messaging/notifications] Unabled to send notification\n${err.stack}`);
    }
    }, meta.config.notificationSendDelay * 1000);
    };
    async function sendNotifications(fromuid, uids, roomId, messageObj) {
    const isOnline = await user.isOnline(uids);
    uids = uids.filter((uid, index) => !isOnline[index] && parseInt(fromuid, 10) !== parseInt(uid, 10));
    if (!uids.length) {
    return;
    }
    const { displayname } = messageObj.fromUser;
    const isGroupChat = await Messaging.isGroupChat(roomId);
    const notification = await notifications.create({
    type: isGroupChat ? 'new-group-chat' : 'new-chat',
    subject: `[[email:notif.chat.subject, ${displayname}]]`,
    bodyShort: `[[notifications:new_message_from, ${displayname}]]`,
    bodyLong: messageObj.content,
    nid: `chat_${fromuid}_${roomId}`,
    from: fromuid,
    path: `/chats/${messageObj.roomId}`,
    });
    delete Messaging.notifyQueue[`${fromuid}:${roomId}`];
    notifications.push(notification, uids);
    }
    };
  • @phenomlab said in NodeBB Global Tchat : Forum with many users performance issues:

    I’d say that this was still relevant, and would solve the short term issue (in most cases) but if anything, you’ll still experience slowness if you have say 600 users online.
    The right way to handle this in my view would be to pass the notification stream to a message queuing service (like RabbitMQ or Redis) and let that process in the back end rather than cause locking on the forum itself. I’m surprised that this is in fact the case as standard emails are being queued and aren’t sent in real time.
    I personally don’t use this plugin as you know, so I’d need to review the code first in order to understand it’s structure.

    Thank you for your analyse 👍

    I would have liked to try the thing all the same, just to see the result

    600 users is better than 4000 😉

    Here is the content of the /src/messsagin/notification.js file

    I put it here because I don’t see where to integrate the given code for test :

    'use strict';
    
    const winston = require('winston');
    
    const user = require('../user');
    const notifications = require('../notifications');
    const sockets = require('../socket.io');
    const plugins = require('../plugins');
    const meta = require('../meta');
    
    module.exports = function (Messaging) {
    	Messaging.notifyQueue = {}; // Only used to notify a user of a new chat message, see Messaging.notifyUser
    
    	Messaging.notifyUsersInRoom = async (fromUid, roomId, messageObj) => {
    		let uids = await Messaging.getUidsInRoom(roomId, 0, -1);
    		uids = await user.blocks.filterUids(fromUid, uids);
    
    		let data = {
    			roomId: roomId,
    			fromUid: fromUid,
    			message: messageObj,
    			uids: uids,
    		};
    		data = await plugins.hooks.fire('filter:messaging.notify', data);
    		if (!data || !data.uids || !data.uids.length) {
    			return;
    		}
    
    		uids = data.uids;
    		uids.forEach((uid) => {
    			data.self = parseInt(uid, 10) === parseInt(fromUid, 10) ? 1 : 0;
    			Messaging.pushUnreadCount(uid);
    			sockets.in(`uid_${uid}`).emit('event:chats.receive', data);
    		});
    		if (messageObj.system) {
    			return;
    		}
    		// Delayed notifications
    		let queueObj = Messaging.notifyQueue[`${fromUid}:${roomId}`];
    		if (queueObj) {
    			queueObj.message.content += `\n${messageObj.content}`;
    			clearTimeout(queueObj.timeout);
    		} else {
    			queueObj = {
    				message: messageObj,
    			};
    			Messaging.notifyQueue[`${fromUid}:${roomId}`] = queueObj;
    		}
    
    		queueObj.timeout = setTimeout(async () => {
    			try {
    				await sendNotifications(fromUid, uids, roomId, queueObj.message);
    			} catch (err) {
    				winston.error(`[messaging/notifications] Unabled to send notification\n${err.stack}`);
    			}
    		}, meta.config.notificationSendDelay * 1000);
    	};
    
    	async function sendNotifications(fromuid, uids, roomId, messageObj) {
    		const isOnline = await user.isOnline(uids);
    		uids = uids.filter((uid, index) => !isOnline[index] && parseInt(fromuid, 10) !== parseInt(uid, 10));
    		if (!uids.length) {
    			return;
    		}
    
    		const { displayname } = messageObj.fromUser;
    
    		const isGroupChat = await Messaging.isGroupChat(roomId);
    		const notification = await notifications.create({
    			type: isGroupChat ? 'new-group-chat' : 'new-chat',
    			subject: `[[email:notif.chat.subject, ${displayname}]]`,
    			bodyShort: `[[notifications:new_message_from, ${displayname}]]`,
    			bodyLong: messageObj.content,
    			nid: `chat_${fromuid}_${roomId}`,
    			from: fromuid,
    			path: `/chats/${messageObj.roomId}`,
    		});
    
    		delete Messaging.notifyQueue[`${fromuid}:${roomId}`];
    		notifications.push(notification, uids);
    	}
    };
    

    @phenomlab

    An idea for where to put this code before I open a thread an NodeBB communauty ?

  • @phenomlab

    An idea for where to put this code before I open a thread an NodeBB communauty ?

    @DownPW not specifically, no, as there is an existing function with the same name. The comma at the end of the revised function would indicate part of an existing array but I’m not entirely sure of where it should be placed - or if it should override the existing function altogether (which I don’t think is the case).

  • @DownPW not specifically, no, as there is an existing function with the same name. The comma at the end of the revised function would indicate part of an existing array but I’m not entirely sure of where it should be placed - or if it should override the existing function altogether (which I don’t think is the case).

    @phenomlab arf I hope i have an answers in nodeBB 😞

    But it’s an async function maybe here :

    345a9b2c-26cf-491d-8ffe-047afa529d61-image.png

  • @phenomlab arf I hope i have an answers in nodeBB 😞

    But it’s an async function maybe here :

    345a9b2c-26cf-491d-8ffe-047afa529d61-image.png

    @DownPW you can always experiment 👍

  • @DownPW you can always experiment 👍

    @phenomlab no luck 😞

  • @DownPW what have you tried?

  • @phenomlab lot of things 😉

  • @DownPW can you provide some brief examples?

  • @DownPW can you provide some brief examples?

    @phenomlab .

    'use strict';
    const winston = require('winston');
    const user = require('../user');
    const notifications = require('../notifications');
    const sockets = require('../socket.io');
    const plugins = require('../plugins');
    const meta = require('../meta');
    module.exports = function (Messaging) {
    Messaging.notifyQueue = {}; // Only used to notify a user of a new chat message, see Messaging.notifyUser
    Messaging.notifyUsersInRoom = async (fromUid, roomId, messageObj) => {
    let uids = await Messaging.getUidsInRoom(roomId, 0, -1);
    uids = await user.blocks.filterUids(fromUid, uids);
    let data = {
    roomId: roomId,
    fromUid: fromUid,
    message: messageObj,
    uids: uids,
    };
    data = await plugins.hooks.fire('filter:messaging.notify', data);
    if (!data || !data.uids || !data.uids.length) {
    return;
    }
    uids = data.uids;
    uids.forEach((uid) => {
    data.self = parseInt(uid, 10) === parseInt(fromUid, 10) ? 1 : 0;
    Messaging.pushUnreadCount(uid);
    sockets.in(`uid_${uid}`).emit('event:chats.receive', data);
    });
    if (messageObj.system) {
    return;
    }
    // Delayed notifications
    let queueObj = Messaging.notifyQueue[`${fromUid}:${roomId}`];
    if (queueObj) {
    queueObj.message.content += `\n${messageObj.content}`;
    clearTimeout(queueObj.timeout);
    } else {
    queueObj = {
    message: messageObj,
    };
    Messaging.notifyQueue[`${fromUid}:${roomId}`] = queueObj;
    }
    queueObj.timeout = setTimeout(async () => {
    try {
    await sendNotifications(fromUid, uids, roomId, queueObj.message);
    } catch (err) {
    winston.error(`[messaging/notifications] Unabled to send notification\n${err.stack}`);
    }
    }, meta.config.notificationSendDelay * 1000);
    if (roomId != 11) { // 5 Is the ID of the ID of the global chat room.
    Messaging.getUidsInRoom(roomId, 0, -1); // Proceed as normal.
    } else {
    user.getUidsFromSet('users:online', 0, -1); // Only notify online users.
    }
    };
    async function sendNotifications(fromuid, uids, roomId, messageObj) {
    const isOnline = await user.isOnline(uids);
    uids = uids.filter((uid, index) => !isOnline[index] && parseInt(fromuid, 10) !== parseInt(uid, 10));
    if (!uids.length) {
    return;
    }
    const { displayname } = messageObj.fromUser;
    const isGroupChat = await Messaging.isGroupChat(roomId);
    const notification = await notifications.create({
    type: isGroupChat ? 'new-group-chat' : 'new-chat',
    subject: `[[email:notif.chat.subject, ${displayname}]]`,
    bodyShort: `[[notifications:new_message_from, ${displayname}]]`,
    bodyLong: messageObj.content,
    nid: `chat_${fromuid}_${roomId}`,
    from: fromuid,
    path: `/chats/${messageObj.roomId}`,
    });
    delete Messaging.notifyQueue[`${fromuid}:${roomId}`];
    notifications.push(notification, uids);
    }
    };

    nodebb build is ok with this code but I don’t see any diiference of latencies

  • @phenomlab .

    'use strict';
    
    const winston = require('winston');
    
    const user = require('../user');
    const notifications = require('../notifications');
    const sockets = require('../socket.io');
    const plugins = require('../plugins');
    const meta = require('../meta');
    
    module.exports = function (Messaging) {
    	Messaging.notifyQueue = {}; // Only used to notify a user of a new chat message, see Messaging.notifyUser
    	
    	Messaging.notifyUsersInRoom = async (fromUid, roomId, messageObj) => {
    		let uids = await Messaging.getUidsInRoom(roomId, 0, -1);
    		uids = await user.blocks.filterUids(fromUid, uids);
    
    		let data = {
    			roomId: roomId,
    			fromUid: fromUid,
    			message: messageObj,
    			uids: uids,
    		};
    		data = await plugins.hooks.fire('filter:messaging.notify', data);
    		if (!data || !data.uids || !data.uids.length) {
    			return;
    		}
    
    		uids = data.uids;
    		uids.forEach((uid) => {
    			data.self = parseInt(uid, 10) === parseInt(fromUid, 10) ? 1 : 0;
    			Messaging.pushUnreadCount(uid);
    			sockets.in(`uid_${uid}`).emit('event:chats.receive', data);
    		});
    		if (messageObj.system) {
    			return;
    		}
    		// Delayed notifications
    		let queueObj = Messaging.notifyQueue[`${fromUid}:${roomId}`];
    		if (queueObj) {
    			queueObj.message.content += `\n${messageObj.content}`;
    			clearTimeout(queueObj.timeout);
    		} else {
    			queueObj = {
    				message: messageObj,
    			};
    			Messaging.notifyQueue[`${fromUid}:${roomId}`] = queueObj;
    		}
    
    		queueObj.timeout = setTimeout(async () => {
    			try {
    				await sendNotifications(fromUid, uids, roomId, queueObj.message);
    			} catch (err) {
    				winston.error(`[messaging/notifications] Unabled to send notification\n${err.stack}`);
    			}
    		}, meta.config.notificationSendDelay * 1000);
    		
    		
               if (roomId != 11) { // 5 Is the ID of the ID of the global chat room.
                   Messaging.getUidsInRoom(roomId, 0, -1); // Proceed as normal.
                } else {
                    user.getUidsFromSet('users:online', 0, -1); // Only notify online users.
                }
    	};
    
    	async function sendNotifications(fromuid, uids, roomId, messageObj) {
    		const isOnline = await user.isOnline(uids);
    		uids = uids.filter((uid, index) => !isOnline[index] && parseInt(fromuid, 10) !== parseInt(uid, 10));
    		if (!uids.length) {
    			return;
    		}
    
    
    		const { displayname } = messageObj.fromUser;
    
    		const isGroupChat = await Messaging.isGroupChat(roomId);
    		const notification = await notifications.create({
    			type: isGroupChat ? 'new-group-chat' : 'new-chat',
    			subject: `[[email:notif.chat.subject, ${displayname}]]`,
    			bodyShort: `[[notifications:new_message_from, ${displayname}]]`,
    			bodyLong: messageObj.content,
    			nid: `chat_${fromuid}_${roomId}`,
    			from: fromuid,
    			path: `/chats/${messageObj.roomId}`,
    		});
    
    		delete Messaging.notifyQueue[`${fromuid}:${roomId}`];
    		notifications.push(notification, uids);
    	}
    	
    
    		
    };
    

    nodebb build is ok with this code but I don’t see any diiference of latencies

    'use strict';
    const winston = require('winston');
    const user = require('../user');
    const notifications = require('../notifications');
    const sockets = require('../socket.io');
    const plugins = require('../plugins');
    const meta = require('../meta');
    module.exports = function (Messaging) {
    Messaging.notifyQueue = {}; // Only used to notify a user of a new chat message, see Messaging.notifyUser
    Messaging.notifyUsersInRoom = async (fromUid, roomId, messageObj) => {
    let uids = await Messaging.getUidsInRoom(roomId, 0, -1);
    uids = await user.blocks.filterUids(fromUid, uids);
    let data = {
    roomId: roomId,
    fromUid: fromUid,
    message: messageObj,
    uids: uids,
    };
    data = await plugins.hooks.fire('filter:messaging.notify', data);
    if (!data || !data.uids || !data.uids.length) {
    return;
    }
    uids = data.uids;
    uids.forEach((uid) => {
    data.self = parseInt(uid, 10) === parseInt(fromUid, 10) ? 1 : 0;
    Messaging.pushUnreadCount(uid);
    sockets.in(`uid_${uid}`).emit('event:chats.receive', data);
    });
    if (messageObj.system) {
    return;
    }
    // Delayed notifications
    let queueObj = Messaging.notifyQueue[`${fromUid}:${roomId}`];
    if (queueObj) {
    queueObj.message.content += `\n${messageObj.content}`;
    clearTimeout(queueObj.timeout);
    } else {
    queueObj = {
    message: messageObj,
    };
    Messaging.notifyQueue[`${fromUid}:${roomId}`] = queueObj;
    }
    queueObj.timeout = setTimeout(async () => {
    try {
    await sendNotifications(fromUid, uids, roomId, queueObj.message);
    } catch (err) {
    winston.error(`[messaging/notifications] Unabled to send notification\n${err.stack}`);
    }
    }, meta.config.notificationSendDelay * 1000);
    };
    async function sendNotifications(fromuid, uids, roomId, messageObj) {
    const isOnline = await user.isOnline(uids);
    uids = uids.filter((uid, index) => !isOnline[index] && parseInt(fromuid, 10) !== parseInt(uid, 10));
    if (!uids.length) {
    return;
    }
    if (roomId != 11) { // 5 Is the ID of the ID of the global chat room.
    Messaging.getUidsInRoom(roomId, 0, -1); // Proceed as normal.
    } else {
    user.getUidsFromSet('users:online', 0, -1); // Only notify online users.
    }
    const { displayname } = messageObj.fromUser;
    const isGroupChat = await Messaging.isGroupChat(roomId);
    const notification = await notifications.create({
    type: isGroupChat ? 'new-group-chat' : 'new-chat',
    subject: `[[email:notif.chat.subject, ${displayname}]]`,
    bodyShort: `[[notifications:new_message_from, ${displayname}]]`,
    bodyLong: messageObj.content,
    nid: `chat_${fromuid}_${roomId}`,
    from: fromuid,
    path: `/chats/${messageObj.roomId}`,
    });
    delete Messaging.notifyQueue[`${fromuid}:${roomId}`];
    notifications.push(notification, uids);
    }
    };
  • undefined DownPW has marked this topic as solved on 27 Apr 2023, 21:22


3/13

6 Jan 2023, 16:58


Did this solution help you?
Did you find the suggested solution useful? Why not buy me a coffee? It's a nice gesture, and a great way to show your appreciation 💗

Related Topics
  • Nodebb and emails

    Solved Configure 21 Dec 2024, 20:45
    5 Votes
    27 Posts
    814 Views
    @Panda it will use SMTP. In all cases, I never use any plugin to send email. I’ll always send it raw.
  • 3 Votes
    8 Posts
    514 Views
    @Panda You should be able to expose the CSS for these using F12 to get into console [image: 1686833368846-3591518c-e3a3-4ada-a43c-6b32a5e0359c-image.png] [image: 1686833399483-a2b8ed46-4157-4ff2-85f0-576543380107-image.png] That should then expose the element once selected [image: 1686833431032-89d9c545-a47a-40d1-98f4-80cf3b958e8f-image.png] Here’s the below CSS you need based on the screenshot provided. .composer .formatting-bar .formatting-group li[data-format="picture-o"], .composer .formatting-bar .formatting-group li[data-format="spoiler"] { display: none; }
  • NodeBB: hCaptcha

    Solved Configure 11 Apr 2023, 12:21
    2 Votes
    15 Posts
    660 Views
    @mventures none that I know of. I don’t recall selecting these either for mine.
  • 0 Votes
    6 Posts
    427 Views
    @mventures You’d need to connect to the server and execute it directly - not on your local terminal. Review the guide below, which will show you how to gain access via SSH to your server https://docs.ovh.com/gb/en/dedicated/ssh-introduction/ Once you have access, you’ll need to navigate to the actual folder where NodeBB is installed You’ll then need to change to the directory as shown below /home/unbuntu/nodebb [image: 1680448167972-fdffe673-bf63-4b6d-a728-5506fddc1aff-image.png] In most cases, initial access takes you to the root of the file system. You can always issue pwd in a Linux terminal which will show you the Present Working Directory. From there, you can issue the command cd /home/ubuntu/nodebb Once in the NodeBB directory, you’d use the below commands ./nodebb stop git fetch && git checkout develop && git reset --hard origin/develop ./nodebb upgrade ./nodebb start Line 1 stops the NodeBB instance Line 2 gets the latest files from GIT (repository) and then checks out the development branch. It then resets the version you are using to the development branch ready for v3 Line 3 Runs the upgrade once the new branch is set, and code pulled Line 4 Restarts the NodeBB instance after the upgrade has completed Note that when you restart NodeBB and log back in, things will look very different to what you had in v2.
  • 0 Votes
    5 Posts
    356 Views
    @mventures Yes, exactly. The other icon will restart NodeBB whilst the first icon I referenced will rebuild (recompile) it. The huge strength of NodeBB over Flarum (for example) is that the code is precompiled, and called once at boot. PHP’s code has to repeatedly reload code from source making it much slower.
  • 1 Votes
    16 Posts
    801 Views
    @DownPW sure. Let me have a look at this in more detail. I know nginx plus has extensive support for this, but it’s not impossible to get somewhere near acceptable with the standard version. You might be better off handling this at the Cloudflare level given that it sits in between the requesting client and your server.
  • Podcast Share NodeBB

    Solved Configure 2 Nov 2022, 11:37
    4 Votes
    15 Posts
    875 Views
    @cagatay You could experiment with nodebb-plugin-ns-embed but I expect the x-origin tag on the remote site to prevent playback.
  • Iframely (Nodebb)

    Solved Configure 5 Nov 2021, 15:37
    4 Votes
    40 Posts
    3k Views
    @DownPW This is now resolved. The issue was an incorrect URL specified in the Nodebb plugin. I’ve corrected this, and now it works as intended.