Building a fault-tolerant soft real-time web application with Erlang/OTP

≡放荡痞女 提交于 2019-11-30 02:27:31

First of all, this is a big question, but i will try to break it down. Lets first look at the facts. Its a web service. Which means we have these layers: Web Server , Middle ware application and then Data Storage. In most highly available applications, the Data Storage layer must have redundancy through replication and load managed through Distribution. In most real-world applications, you will not need to store anything in RAM, unless the application is really real-time in nature, such as a Multi-player Game Server or A telecom Switch. So, your kind of application, in this case really, no need for RAM storage (maybe some kind of caching here and there, as we are going to see.)

Now, this kind of application, involves different kind of data,information that cannot have the same form at any one time, hence, using an RDMS will force you to arrange everything the same way. My suggestion is that you learn to use any document oriented database, a NoSQL DB or key-value system because they are well modelled for real-world complexities. More information about any kind of storage is found in this pdf. I suggest that you use Couch base server whereby your data will simply be JSON documents, schemaless and can be evolved as your application grows. It comes with distribution and replication, just the way any application ever needed it. You can add servers or remove servers,at run-time and the entire system just keeps re-balancing itself. It also comes with memcached built in for caching, so for the IN-Memory part you were talking about, caching will do everything for you.

After the Storage, lets talk about the middle ware. i want to talk about the web server as being part of the middle ware. You will need a very stable Web server, depending on the load, and being that you want to use Erlang, i suggest yaws web server and learn to do RESTFUL services with it using appmods. Using Proxies sunch as Nginx infront of a cluster of web servers may help in load management. Atleast there are several ways of load-balancing infront of web servers. After this, you will need an OTP application. An OTP application doesnot necessary have to have gen_servers. But as you will learn, you will discover, really, where you need parallelisation or where you need sequential code. Its however, worrying that you want to use something which you have not yet mastered. please follow this web book and this Orielly book to help you master everything about Erlang. You could find it useful to try out Chicago Boss and Mochiweb or Misultin Http server libraries.

The other thing i should mention about doing this in Erlang is that, you need to master your Data Structures and an effcient way to work with them. Poor choice of data structures may cause problems. Test and Test everything at each step. Use records everywhere if possible and check memory consumption at each stage. There is just lots to say about this question , but hopefully, others are also going to post their thinking.

hack this game: https://github.com/synrc/games all real-time, low latency, pub/sub, database, architecture questions are there, written as a state-of-the-art software. I suggest to use gen_fsm to control states in your app as done in 'okay' supervisors. riak is integrated with kvs lib, that has a good support for social updates also. n2o choosed cowboy server, in my view, the best server around. http://www.ostinelli.net/a-comparison-between-misultin-mochiweb-cowboy-nodejs-and-tornadoweb/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!