Does Firebase handle threading on Java Server SDK with App Engine?

北战南征 提交于 2019-12-24 08:23:21

问题


I have a setup like this:

Client <----> Realtime Database <----> AppEngine Server

The AppEngine server has some code inside the servlet init() method.

@Override
public void init(ServletConfig sc) throws ServletException {
  // Setup Firebase....
  firebase.addChildEventListener(..nested SingleValueEventListener..);
}

Whenever the client updates a node in firebase, the AppEngine will listen for this change, and do some processing and update some other nodes.

This setup works for testing, as I am a single user. But what if 100 people are using this app? Am I guaranteed that this childEventListener will run code for every user? Will those nested SingleValueEventListeners also trigger?

Or will I have to deal creating threads on every different firebase request? Or is this all taken care of by Firebase Java Server SDK?

Also, is the init() method, the right place to put the ChildEventListeners and can I add like... 10 listeners in there?


回答1:


On app engine firebase uses background threads to listen to changes on firebase. By adding ChildEventListener you create a new long living thread in background that will handle everything for you, no need to worry about it and create a new one or etc. It will be triggered by changes in firebase no matter who did those changes(any user of yours can do it). But to use long living background threads on app engine manual scaling is needed to be enabled, that means that only one instance of your back end will run. And it will proceed as many request as it has capabilities, so you have a fixed limit of changes per second that your back end can handle.




回答2:


I have a similar application going on and we've been working with it for some months. I do not recommend you to use appEngine standard environment for this mean, as it is not prepared to keep persistent connections (we started this way)

Because of this, sometimes we lost connection with firebase and after making some research we found out that this was a common issue. The only way of solving it was migrating the server to the flexible environment

https://cloud.google.com/appengine/docs/flexible/java/migrating-an-existing-app

It is a beta release and I'm not sure about the pricing in the future, but so long it works fine with our application.

Hope this helps you!



来源:https://stackoverflow.com/questions/38929984/does-firebase-handle-threading-on-java-server-sdk-with-app-engine

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