Firebase是否处理Java Server SDK与App Engine的线程? [英] Does Firebase handle threading on Java Server SDK with App Engine?

查看:143
本文介绍了Firebase是否处理Java Server SDK与App Engine的线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



客户端<---->实时数据库<----> AppEngine服务器



AppEngine服务器在servlet的init()方法内部有一些代码。



$ $ $ $ $ $ $ $ $ $ @Override
public void init(ServletConfig sc)throws ServletException {
//设置Firebase ....
firebase.addChildEventListener(..嵌套的SingleValueEventListener ..);



$ b $ p
$ b

每当客户端更新firebase中的一个节点,AppEngine就会监听这个变化,并做一些处理和更新其他节点。

这个设置适用于测试,因为我是一个用户。但是,如果有100人使用这个应用程序呢?我保证这个childEventListener将为每个用户运行代码?这些嵌套的SingleValueEventListeners是否也会触发?

或者我将不得不在每个不同的firebase请求上创建线程?或者,这一切都由Firebase Java Server SDK负责吗?

另外,init()方法是放置ChildEventListeners的正确位置,我可以添加。在这里有10个监听器?在应用引擎上,firebase使用后台线程来监听Firebase上的更改。通过添加ChildEventListener,您可以在后台创建一个新的长生存线程,为您处理所有事情,无需担心并创建新线程等。无论用户做出哪些更改(任何用户你的可以做到)。但是要在应用程序引擎上使用长时间的后台线程,需要启用手动缩放,这意味着只有后端的一个实例可以运行。而且它会处理尽可能多的请求,所以你有一个固定的每秒变化的限制,你的后端可以处理。


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?

解决方案

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.

这篇关于Firebase是否处理Java Server SDK与App Engine的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆