From NodeJS to Java

in java •  7 years ago  (edited)

From NodeJS to Java

title.png

The last update is running for a few days now. And the changes in the backend are big! You, as the enduser, probably won't have noticed so many changes. Because of that I'll give you more details about the backend in this article. I'll compare the old system with the new system, Java and Javascript, and why we made this step. I won't talk too much about efficiency comparison between NodeJS and Java because that's a difficult topic that has been discussed a lot in the internet. But we'll see later.

NodeJS (Javascript)

Node.js is an open-source, cross-platform JavaScript run-time environment for executing JavaScript code server-side... Ah what?
Javascript is a coding language better said a script language. Mostly used in browsers and webservices/webapplications. I started coding MiBro in Javascript because:

  • Executeable on every system
  • Easy to set up
  • Changes can be done very easy and with every editor
  • No compiling neccessary (Javascript is using an Interpreter to run the code)

Node.js has an event-driven architecture capable of asynchronous I/O, in other words it's handling the input/output communication asynchron. This is increasing the performance when the application grows.

  • Synchron: One task after the other
  • Asyncrhon: Multiple tasks at the same time

This is a big advantage of NodeJS. But there are some disadvantages as well. For example OOP (Object Oriented Programming). Yes, I know you can do OOP in Javascript but not as you can do in other languages like C++ or Java.

Java

One of the most known and used programming language. It's used in nearly any kind of applications. We said that JS is an interpreted language. What about Java?
Java is a mix of Compiled and Interpreted language. You need to compile your code (into Java Byte Code). And this code will be interpreted by the JVM (Java Virtual Machine). The JVM is the enviroment you install on your computer to execute java programs. The JVM is available for different system (Windows, Linux, ...).

  • Executeable on every system
  • Easy to set up (install JVM)
  • Compiling neccessary
  • IDE recommended (I'm using Eclipse)

What is better?

This question is very difficult to answer. And in my oppinion the way you implement things matter more than the language. So it's more a personal preference. Of course there are a few differences and compiled languages are mostly more efficient. I'm sure you find a thousand more articles about programming language comparisons.

What did matter for you?

Discord bots that are on more than 2500 discord servers (guilds), Sharding is required. Sharding is like splitting the bot sessions into different ones. The goal is to lighten the load for each websocket. For example: Let's say a bot is in 5000 guilds. You can set up 4 shards with:

  • Shard 1: 1400 guilds
  • Shard 2: 1200 guilds
  • Shard 3: 1200 guilds
  • Shard 4: 1200 guilds

In Javascript, each shard is starting it's own process. The problem with different processes is that each process has it's own data, workflow, etc... This was a problem because MiBro has some guild-global data, and inter-process-communication is not really a good data management. Java however is using threads. Each shard is handled in different threads. The advantage of threads is that they are part of one process and have the same data. Threads allow an asynchron workflow like Javascript does partly automatically.

Why the switch to Java?

I really enjoy OOP and I prefer threading before multiple processes. These two facts were decisive for the change. It was a lot of work because I had to code MiBro from scratch again. But this was a good step. Because the code became really messy. More and more feature have been added and the code grew and grew. Now we have a clean and oop system.

Bugs

Because I had to code everything from scratch again, bugs are unavoidable. But at this point, we are in a stable possition. The Discord API lags in the last days made it a bit difficult for us to adjust everything, but it seems to be fine now. With the update we introduced the Status Page. You can check the status of MiBro (and each individual shard). Any issues will be reported on this site.

That's it. The Developer report for the big update.

See you soon,

Mike
Founder & Developer
#mibro

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @mibro! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @mibro! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!