6 months ago
my server was running fine yesterday, today it was a shit show. Had over 200+ people using our bot and it was shambles, yesterday was fine im on pro plan, is there any other service other than Pro to have a much faster server?
230 Replies
6 months ago
All plans use the same server spec, could you please share more details about your use case as well as usage details?
6 months ago
I’m assuming you mean a discord bot
6 months ago
Just the single service? The bot and backend are in the same service?
6 months ago
There’s your issue. When your bot receives a ton of requests at once, your websocket server gets tied up servicing them all. If you architect your project such that your bot is in a separate service from your backend, you’ll be able to scale up your backend using replicas to handle more requests at once
6 months ago
This is not a Railway issue, but a project architecture issue. If you change the architecture of your bot you’ll be able to dramatically improve performance
6 months ago
modify your project so that your bot and backend are in different folders
Create a new service and deploy your backend to one, your bot to the other
Make sure that’s all working, then depending on the way your backend works, you may be able to use replicas. Regardless, they’re on different machines now, so they’re not sharing resources and will have more capacity
so should i make another workspace for my bot, and deploy the bot on railway and have the socket server seperate? what if i need to use certain stuff from the socket-server.js file
6 months ago
No, not another workspace. Another service
6 months ago
What do you need to use from the server file?
6 months ago
Sounds like you made two separate parts of your app pretty tightly coupled, that’s not great and will heavily restrict the optimizations you can do
6 months ago
this box on your bot’s project is a service. It’s an individual container hosting your bot’s code. The goal here is to separate your bot’s container from your server’s container so they don’t share resources and you can scale up your server count
6 months ago
Should be a new service button at the top right of the project page, or right click anywhere in your project and select new service
6 months ago
yes
what would I have to change in my code? will I have to re-code everything?
6 months ago
You will need to recode quite a bit, it seems like. But if you’re expecting to handle a lot of users, this is what you’ll need to do
6 months ago
All that needs to be done is decouple your bot from your backend, that shouldn’t be too complex
6 months ago
Recoding your app is the first step here, you’ll add a new service for your server once you’ve done that
6 months ago
But if your code is on Github, then Github. However you uploaded your first service
6 months ago
I don’t know enough about your project to tell you that
6 months ago
Any place where they’re directly referencing code files from each other, they shouldn’t
i'll tell you more info soon, ppl are interacting with our bot, 100+ ppl
6 months ago
I’ve given you all the information I can, at this point all that’s left is for you to start coding
6 months ago
Keep everything in one workspace, one project, but not one service
6 months ago
^
so all i need to do is create 2 folders - 1 is discord bot and 2 is websocket?
6 months ago
Pretty much yes, but you need to make sure those two folders don’t have any crossover.
6 months ago
Once the two are decoupled, you host each one as an individual service on Railway
ah… i see, we were using the bot in a small server (around 8,000-9,000 member server), and we just went back to our old discord (with 60,000+ members), and it's really slow in that cord, probably because of the member count.. just tested the bot in the 9k member cord and its really fast
6 months ago
Are you implementing discord's sharding feature? I think they suggest it around the ~10k mark
i thought sharding is only needed if the bot is in 2,000+ servers or something?
6 months ago
Oh i might be mistaking then. Havent had a need to use it hahaha
6 months ago
let me go read up on the docs real quick
6 months ago
And I assume this is a discord.js bot right?
yeah, discord.js bot + uses socket.io
6 months ago
Do you have any leveling logic on messageCreate event?
6 months ago
Or something that would get triggered on a commonly occuring event. Curious if theres some hanging with cache, db calls, or operations.
6 months ago
Was driving at db related functionality on messageCreate events.
Some servers have an "xp" system where you gain certain xp points per message sent.
ohh, we have the following :
messageReactionAdd
messageReactionRemove
messageCreate

we have a channel if we need some people , we ask for people in there and they type and it'll return with a button to add them
6 months ago
Oh my…
6 months ago
There's your problem right there!
6 months ago
if i understand correctly, each and every one of those events is being fired every time a user sends a message.
tho, Adam said it's because i have socket-server and a discord bot in the same project and I should make 2 separate services

6 months ago
<:Hmmmmm:891565000068587551> that doesnt sound like it would be a large factor although I could see the concern.
6 months ago
Heres my suggestion for steps of debugging and verification.
6 months ago
Split this into 2 major services (easiest). Websocket (backend) discord bot (the bot).
Have them communicate over private network. In general thats better practice long term.
It'll also help verify thats not the issue.
6 months ago
I'm also curious, what database are you using?
6 months ago
Yeahhh in terms of best project structure that's honestly your best bet.
It'll help you service things much better in the future
thing is, i don't think i can do it all in one day, and we use this bot for our discord daily, at around 6pm est
6 months ago
Yeah i can understand that.
So for a bit of preface, were you using this bot in this 60k member server before?
6 months ago
Can I get a bit of info on the timeline?
We provide "scrim-practice" for the Fortnite community to over 60,000 members, and we use that bot to host "scrim-practice", like practice games
6 months ago
Have you always been using Railway to host it?
6 months ago
Okay yeah that clears things up
6 months ago
in your server, can you search for the total number of messages from a given day?
6 months ago

6 months ago
curious what this number is
6 months ago
And by any chance, on the 9k one what are you seeing?
6 months ago
Mhm
6 months ago
So
6 months ago
Well you can search on a past day
6 months ago
if you have a rough time of when it was most active
6 months ago
What you're running into is scaling issues.
60k is a very large number. From a 9k member server -> 60k member server you're looking at an increase of 6 times.
From 3k -> 60k thats ~20x larger.
If i understand that screenshot with folder structure correctly, it looks like you're running ~17 different events every single time somebody sends a message.
If each of those events trigger a DB call or are blocking you're having race conditions and a whole host of problems that come with databases and scaling
6 months ago
Typing out what I would do now <:picassoface:1398147502598918144>
6 months ago
If i were in your situation here's what I would do. The server didnt grow from 0-60 overnight. I assume you guys were using something before so I highly suggest switching back to it and doing maintenance on this bot for a few days.
Split it into 2 services, for our conversations sake: BOT and WS.
Each of those services will run on Railway in a separate service. (Same project)
Now you have per service 32g of ram and 32vCPU available. You shouldnt ever run into a resource issue on them.
That's step 1.
Your bot should never actively query the database it should only make a request to WS which is the only service who talks to your database.
Each of your events is making a call to your websocket so look into pairing down.
I suggest figuring out which parts of the logic actively need to talk to your database and what doesnt. I'd implement a layer of caching with Redis for repetitive calls (username, user id, avatar, team, etc etc.)
Split the services up + cache data will fix a good bit of the latency
6 months ago
I'd also do some live debugging to figure out what part of that process is taking the longest. Is it the db call? Response from websocket? Once you know what's taking longest you can debug that
6 months ago
there's 9k members joining instantly? Sheesh
6 months ago
Sure my dms are open. As for solving this I prefer keeping them in threads so if other users have similar issues they can reference this
6 months ago
Yeah @mylo I think I'd look into doing what I suggested with figuring out which process is taking longest
6 months ago
Simple as adding console logs at certain points with durations until next points
6 months ago
Alright. I'm more then happy to help with suggestions/direction however I can 😁
6 months ago
6 months ago
@mylo Railway supports running a mongo DB on project!

6 months ago
I'm not personally familiar with mongo as much as I'd like, the process would be backing up the cloud mongo db you pay for and restoring to the railway hosted one.
6 months ago
That'll remove all network latency on each request and could help by a decent margin
6 months ago
In your service its pointing to a connection url/uri so you would just swap the one its looking for out to the INTERNAL_URL variable found in the variables tab of that service
ohh, do i just need to grab the mongo url and update it in the websocket-server
6 months ago
Yep! But I suggest the internal one
6 months ago
You'd be using this one

6 months ago
this is still sensitive i wouldnt share it
can i keep the name like this and just grab the connection string and replace it?

6 months ago
wdym
6 months ago
Is that the env var on your websocket service?
6 months ago
Oh perfect, type this
6 months ago
in the value side
6 months ago
${{MongoDB.INTERNAL_URL}}
6 months ago
It's a variable reference so it'll go look at the value of that env var on the mongo service and use that
6 months ago
Yeah its a blank mongodb. As I mentioned, you would need to save a copy/backup from the production mongo one and back it up onto that railway project
6 months ago
unsure the best way to do that
6 months ago
Did you backup things?
6 months ago
I usually love JSON. Totally up to you though
6 months ago
Make sure that any changes you do are non destructive haha
6 months ago
You can connect to that database using the railway cli https://docs.railway.com/guides/cli and import data from there
6 months ago
Once you are connected with a shell you can just use mongo's version of pgdump from a file
6 months ago
Yes. Theres no GUI for it
6 months ago
cli isnt hard at all haha
6 months ago
looks a bit scary but its not difficult to get a hang of
6 months ago
ss from an old support thread i helped with

6 months ago
once installed its simplyrailway loginrailway linkrailway connect
6 months ago
and boom
6 months ago
Actually I just looked online. You are dumping the entire mongo db into a single json file right?
6 months ago
the one you're downloading
6 months ago
6 months ago
looking through this right now
6 months ago
iirc you can pass the public connection string when running this command.
6 months ago
(that way you dont have to be railway cli sshd in)
6 months ago
If you're able to export into a single json/csv file it looks easiest
6 months ago
the entire database that is
could you help me soon with importing data? i cant do it rn as we have to use the bot in 30 min
6 months ago
I might be free we will see. Ping me when you're done and if im free happy to help
6 months ago
I'm EST based
6 months ago
Usually up until 10-10:30 EST
6 months ago
If you're switching over to Railway as your mongo db host you dont need to 😁
btw how do i do railway link in cmd? looked at docs and cant get it working
6 months ago
did you first run railway login ?
6 months ago
Oh you have to restart your cmd instance haha
6 months ago
OH you installed a "project specific" version of railway
6 months ago
you have to run npm i -g railway
6 months ago
-g means global
6 months ago
then when you restart the CMD your PATH changes take effect
6 months ago
I guess its @railway/cli oops
6 months ago
Sorry, I have homebrew so for me its just brew install railway-cli or something like that
6 months ago
npm i -g @railway/cli yes
6 months ago
I'm quite confused now <:Hmmmmm:891565000068587551>
6 months ago
npm uninstall -g railway
6 months ago
i think
6 months ago
time to google 😁
6 months ago
oh great
6 months ago
Wonderful haha
6 months ago
you can connect to the shell of that mongo db instance.
Or, if you point the mongodb command to a connection string (the public url) it'll work too
could you guide me with importing data into the railway db? just in case you're offline later
Question @Adam would I be able to put my other bots (Excel and Excel Verification) into railway, split into different services? I use pebble host for those 2 bots atm and pay around $20 total

6 months ago
If you have the source code for those bots, absolutely you can
6 months ago
Did you and Noah get splitting your backend + bot working?
Haven't done that yet, but we found the issue. It was the database, I'm gonna add MongoDB onto railway soon
6 months ago
Awesome! Sorry i just got home otherwise i’d have loved to help with the migration. Is it running any faster?
6 months ago
Yay! Good to know for future reference too.
Still suggest splitting them up into different services haha
@Error Question, I can create multiple mongodb services for different services right?

6 months ago
Yep! Each is a contained mongo database
6 months ago
Give it a reload and let me know if its still applying those changes 😁
6 months ago
Oh good to hear!
6 months ago
!s
Status changed to Solved noahd • 6 months ago


















