使用TCP跨进程共享内存(Using TCP for memory sharing across processes)
我一开始就错误地使用
Redis
或Memcache
或其他内存存储系统来处理nodejs
。 现在,重写所有内容以适应和关联这些API中的代码为时已晚。然而,我最近才发现了分叉过程以及它们有多么有益; 特别是因为我正在开发游戏服务器。
我
nodejs
的问题是:nodejs
内核之间没有共享内存 ..直到我找到一个名为Amensia的TCP
内存共享模块。
nodejs
,我还是有一些关于nodejs
和tcp
问题:1) TCP数据包的最大大小约为64k,因此使用此模块时,我只能共享最大64k的数据?
2)我使用全局
GAMES
和users
对象来存储播放器数据。 当玩家在地图(x,y位置)和其他动作中移动时,这些对象会更新。 通过TCP发送所有这些数据会导致瓶颈吗?I made a mistake working on
nodejs
in the beginning by not utilizingRedis
orMemcache
or other memory storage systems. Now, it's far too late to be rewriting everything to accommodate and correlate my code within those API's.However, I just recently found out about forking processes and how beneficial they can be; especially since I'm working on a gameserver.
The problem I have is: The memory is not shared between cores in
nodejs
.. until I found aTCP
memory sharing module called Amensia.With all that said, I have some question about it pertaining to
nodejs
andtcp
in general:1) The maximum size of a TCP packet is around 64k, so when using this module I can only share data up to 64k in size?
2) I use a global
GAMES
andusers
object to store player data. These objects are updated when a player moves in a map (x,y positions) and upon other actions. Would sending all this data across TCP derive into a bottleneck?
原文:https://stackoverflow.com/questions/32400108
最满意答案
听起来你应该在这里使用交易。 请参阅: 使用事务
如果你不想使用事务,另一种选择是使用信号量做生产者/消费者。 使用1个令牌初始化信号量。 任务1首先获得一个信号量。 在任务2结束时,任务2将释放信号量。 因此,您确保一次只能处理1个链。
sounds like you should be using transaction here. See: Using Transactions
if you don't want to use transaction, another option would be to do a producer/consumer using semaphores. Initalize semaphore with 1 token. Task 1 would first acquire a semaphore. at the end of task 2, task 2 would release a semaphore. Therefore you are ensuring that only 1 chain can be processing at a time.
相关问答
更多-
作为使用Handlers, Vogella网站上的AsyncTask和 Loader的Android后台处理教程,它提供: Handler类可用于向线程注册,并提供一个简单的通道来向此线程发送数据。 AsyncTask类封装了后台进程的创建和与主线程的同步。 它还支持报告运行任务的进度。 而Thread基本上是多线程的核心元素,开发人员可以使用以下缺点: 如果您使用Java线程,则必须在自己的代码中处理以下要求: 如果将结果发布回用户界面,则与主线程同步 没有默认取消线程 没有默认线程池 没有默认处理And ...
-
AsyncTask完成后无法关闭ProgressDialog(Can't dismiss ProgressDialog after the AsyncTask complete)[2022-01-02]
private ProgressDialog progressDialog; // class variable private void showProgressDialog(String title, String message) { progressDialog = new ProgressDialog(this); progressDialog.setTitle(title); //title progressDi ... -
它的字面意思是,当AsyncTask运行时,您无法再次启动它。 在您的MainActivity.class您有以下内容: task.execute(); 如果任务完成或未完成,并且再次调用该方法,则将抛出异常。 并将此方法放在onResume ()中是一种很好的做法。 只有一件事需要注意:如果你输入onRestart (),请记住,当你改变配置时,这个回调会起作用,但如果你创建activity ,它就不会被调用。 关于活动生命周期的文档。 It literally means, that while A ...
-
AsyncTask检测是否完成(AsyncTask detecting if done)[2021-12-23]
盲目的假设......! (没有StackTrace报告) 在AsyncTask实现onPostExecute()并将FillData()方法放入其中..当doInBackground() ..完成控制自动进入onPostExecute() ,然后填充您的UI部分.. Blindly Assumption...! (Without StackTrace report) Implement onPostExecute() in your AsyncTask and put FillData() method ... -
本教程介绍了ContentProvider和Loader的用法。 虽然内容提供程序对于小型应用程序来说过于苛刻,但它是在应用程序中实现SQLiteDatabase的最佳方法。 基本上,它允许您从您希望的每个其他应用程序访问应用程序数据库,并简化其中任何一个CRUD操作的使用。 有了它,您不需要对SQLiteOpenHelper的任何引用,以便在您的数据库中进行任何操作。 内容提供程序通过直接在Activity调用getContentResolver().
()保持代 ... -
无法在未调用Looper.prepare()的线程内创建处理程序 因为您试图显示来自doInBackground Toast消息,该消息在非ui线程上运行。 使用onPostExecute而不是doInBackground根据doInBackground方法输出向用户显示消息。 Can't create handler inside thread that has not called Looper.prepare() Because you are trying to show Toast message ...
-
听起来你应该在这里使用交易。 请参阅: 使用事务 如果你不想使用事务,另一种选择是使用信号量做生产者/消费者。 使用1个令牌初始化信号量。 任务1首先获得一个信号量。 在任务2结束时,任务2将释放信号量。 因此,您确保一次只能处理1个链。 sounds like you should be using transaction here. See: Using Transactions if you don't want to use transaction, another option would be ...
-
使用单AsyncTask Vs.(using Single AsyncTask Vs. multiple AsyncTask for multiple different request from network)[2023-10-18]
我会把它放在单个AsyncTask中,这实际上是因为AsyncTasks很难在Activites中管理,一旦你的Activity旋转或用户按下Home按钮 - 它开始它的生命周期 - 它可以以onCreate结束 - 这意味着你的活动可能会被破坏然后重建。 现在如果你需要以某种方式向Activity报告你的结果,那么你就麻烦了。 有了一个AsyncTask,它就容易多了。 如果您的AsyncTasks很fire and forget ,那么可能会发出10个AsyncTasks不会那么糟糕,但是您可以使用自己 ... -
您可以使用接口实现回调,如下所示: 界面: public interface CallbackActivity { public void activityCallback(); } 在活动中实现此接口: public class myActivity extends Activity implements CallbackActivity{ @Override public void activityCallback(){ finish(); ...
-
您正在使用错误索引..尝试1或2,因为您有此异常: 01-12 16:33:26.314: E/AndroidRuntime(966): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 3, size is 3 You are using a bad index.. try 1 or 2 because you have this exception: 01-12 16:33:26.314: E/AndroidRuntime(96 ...