首页 \ 问答 \ 使用TCP跨进程共享内存(Using TCP for memory sharing across processes)

使用TCP跨进程共享内存(Using TCP for memory sharing across processes)

我一开始就错误地使用RedisMemcache或其他内存存储系统来处理nodejs 。 现在,重写所有内容以适应和关联这些API中的代码为时已晚。

然而,我最近才发现了分叉过程以及它们有多么有益; 特别是因为我正在开发游戏服务器。

nodejs的问题是: nodejs内核之间没有共享内存 ..直到我找到一个名为AmensiaTCP内存共享模块。

nodejs ,我还是有一些关于nodejstcp问题:

1) TCP数据包最大大小约为64k,因此使用此模块时,我只能共享最大64k的数据?

2)我使用全局GAMESusers对象来存储播放器数据。 当玩家在地图(x,y位置)和其他动作中移动时,这些对象会更新。 通过TCP发送所有这些数据会导致瓶颈吗?


I made a mistake working on nodejs in the beginning by not utilizing Redis or Memcacheor 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 a TCP memory sharing module called Amensia.

With all that said, I have some question about it pertaining to nodejs and tcp 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 and users 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
更新时间:2023-02-14 11:02

最满意答案

听起来你应该在这里使用交易。 请参阅: 使用事务

如果你不想使用事务,另一种选择是使用信号量做生产者/消费者。 使用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 ...
  • 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 ...
  • 盲目的假设......! (没有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中,这实际上是因为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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。