0

I've programmed a chat application using nodejs, expressjs and socket.io. So, When I used MYSQL database the application slows down then I replaced it with storing the data using JSON objects (in the server-side of nodejs).

Now everything is ok and the application is working well, but If I want to release an update of the nodejs' app.js file it should be restarted, so, everything in the JSON objects will be deleted!

How can I fix this problem? and can I store in a JSON file to fix it? and will the application stay at the same speed or what?

1
  • @yashpandey Yes, that's right, my application is a runtime chat, I don't want to use MYSQL because it will be the same (slow), My answer is about the speed of JSON object storing speed and JSON file storing speed! Commented Mar 7, 2018 at 16:15

1 Answer 1

2

Storing data in RAM will be always faster than writing to a database, but the problem in your case you need to persist it somewhere.

There are many solutions to this problem but if you are using JSON's, I recommend to look at mongodb database.

MongoDb supports multiple storage engines, but the one that you are interested is in memory.

An interesting architecture for you can be the following replica set configuration:

  1. Primary with in-memory storage engine
  2. Secondary with in-memory storage engine
  3. An other Secondary with wiredtiger storage engine.

You will have the benefits of speed by storing in RAM, and also it will be persisted in the database.

A simpler possibility will be to use a key-store db like redis. Easier to configure.

Sign up to request clarification or add additional context in comments.

2 Comments

I think that your answer as very useful and will solve the problem. But Mongodb is so hard to install and learn and I have wrote many lines of codes and it's so hard to change. Is there another way can help me please ?
you dont have to install mongo I suppose. you can use it on cloud - mlab.com. You can use that , they give 500 mb free and there is no hard learning curve in mongo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.