首页 \ 问答 \ 分布式系统:保持不同节点之间的时间戳一致性(Distributed Systems: Keeping timestamp consistency between different nodes)

分布式系统:保持不同节点之间的时间戳一致性(Distributed Systems: Keeping timestamp consistency between different nodes)

上下文

我们有一个分配系统。 我们从其中一个系统发出事件,这些系统从另一个系统读取以生成报告。

逻辑顺序由以下事实确保:即使发射器系统具有N个节点,也存在下划线的有限状态机,这使得不可能同时发射一个聚合的事件。 这些事件标有时间戳。 N个节点不能总是在时间上同步。

我们非常关心时间戳,因为生成报告的下游系统总是需要时间戳,因为“报告人员”关心这类数据以检查事情是否正确。

问题

2节点可能有一点差异的事实让我们思考。 让我们想象下一个例子。

事件的逻辑顺序是这样的:

事件1 =>事件2 =>事件3

但在数据库中,我们可能会遇到这种情况:

-------------------------------------------
|  Name   |  TimeStamp  |  Logical Order  |
-------------------------------------------
| Event 1 |      2      |        1        |
| Event 2 |      1      |        2        |
| Event 3 |      3      |        3        |
-------------------------------------------

你有没有看到, 事件2事件1之后是逻辑上发生的,但它们的时间戳无法同步。

好吧,这不会每2秒发生一次,但可能会发生,因为时间戳来自不同的节点。 从报告的角度来看,这是一个异常现象。

可能的解决方案

  1. 让报告人员意识到可能存在的问题。 我们无法拥有一个全球性的时间来源(NTP不是一个很好的解决方案,因为有一些好的理由)所以如果有很小的时间差异不是问题,那就意味着“这个事件发生在那个周围时间”。
  2. 确保时间戳一致性检查逻辑流中的下一个事件的时间戳不能小于上一个使它们等于的事件的时间戳。 这不是事实,但即使从非开发人员的角度来看,也保持流程一致。

你有关于这个主题的经验吗?


Context

We have a distrubuted system. We emit events from one of those systems which are read from another system for report generation.

Logical order is ensured by the fact that even if the emitter system has N nodes there is a finite state machine underlined which makes impossible to have concurrent emission of an event for one aggregate. These events are marked with a timestamp. N nodes could not always be on synch about the time.

We care so much about timestamp because the down-stream system which generates reports needs quite always a timestamp because "Reporting people" care about this kind data to check things are going the right way.

The problem

The fact 2 nodes could have a little discrepancy is making us thinking. Let's imagine the next example.

The logical order of the events is this:

Event 1 => Event 2 => Event 3

But in the Database we could have this situation:

-------------------------------------------
|  Name   |  TimeStamp  |  Logical Order  |
-------------------------------------------
| Event 1 |      2      |        1        |
| Event 2 |      1      |        2        |
| Event 3 |      3      |        3        |
-------------------------------------------

Has you can see, Event 2 is logically happened after the Event 1 but their timestamp could not be on synch.

Ok, this is not going to happen every 2 seconds but it could happen because the timestamp comes from different nodes. And from a Reporting point of view this is an anomaly.

Possible solutions

  1. Make Reporting people aware of the possible problem. We are not able to have one global source of time (NTP is not a good solution for some good reasons) so if there are discrepancies of a very small amount of time is not a problem and it means that "this event is happened around that time".
  2. Ensure timestamp consistency checking that the next event in the logical flow could not have a timestamp which is less that the previous event making them equals. This is not the truth but keeps the flow consistent even from a non developer point of view.

Have you got experiences on this topic?


原文:https://stackoverflow.com/questions/20160631
更新时间:2023-05-29 08:05

最满意答案

Net Surgery教程应该为您提供所需的基础知识。 但是,让我更详细地解释您需要做的步骤:

  1. 准备.prototxt网络体系结构:您需要两个文件:现有的ImageNet .prototxt文件和新的时态网络体系结构。 您应该在两个网络中使第一个卷积层之外的所有层相同,包括层的名称。 这样,您可以使用ImageNet .caffemodel文件自动初始化权重。

    由于第一个转换层具有不同的大小,因此必须在.prototxt文件中为其指定与ImageNet文件中不同的名称。 否则,Caffe将尝试使用现有权重初始化此图层,由于它们具有不同的形状,因此会失败。 (这是在你的问题的编辑中发生的事情。)只需将其命名为conv1b并相应地更改对该层的所有引用。

  2. 加载ImageNet网络进行测试,以便从模型文件中提取参数:

    net = caffe.Net('imagenet.prototxt', 'imagenet.caffemodel', caffe.TEST)
    
  3. 从此加载的模型中提取权重。

    conv_1_weights = old_net.params['conv1'][0].data
    conv_1_biases = old_net.params['conv1'][1].data
    
  4. 平均渠道的权重:

    conv_av_weights = np.mean(conv_1_weights, axis=1, keepdims=True)
    
  5. 将新网络与旧的.caffemodel文件一起加载,因为除第一层之外的所有图层都直接使用ImageNet中的权重:

    new_net = caffe.Net('new_network.prototxt', 'imagenet.caffemodel', caffe.TEST)
    
  6. 将计算出的平均权重分配给新网络

    new_net.params['conv1b'][0].data[...] = conv_av_weights
    new_net.params['conv1b'][1].data[...] = conv_1_biases
    
  7. 将权重保存到新的.caffemodel文件:

    new_net.save('new_weights.caffemodel')
    

The Net Surgery tutorial should give you the basics you need to cover this. But let me explain the steps you need to do in more detail:

  1. Prepare the .prototxt network architectures: You need two files: the existing ImageNet .prototxt file, and your new temporal network architecture. You should make all layers except the first convolutional layers identical in both networks, including the names of the layers. That way, you can use the ImageNet .caffemodel file to initialize the weights automatically.

    As the first conv layer has a different size, you have to give it a different name in your .prototxt file than it has in the ImageNet file. Otherwise, Caffe will try to initialize this layer with the existing weights too, which will fail as they have different shapes. (This is what happens in the edit to your question.) Just name it e.g. conv1b and change all references to that layer accordingly.

  2. Load the ImageNet network for testing, so you can extract the parameters from the model file:

    net = caffe.Net('imagenet.prototxt', 'imagenet.caffemodel', caffe.TEST)
    
  3. Extract the weights from this loaded model.

    conv_1_weights = old_net.params['conv1'][0].data
    conv_1_biases = old_net.params['conv1'][1].data
    
  4. Average the weights across the channels:

    conv_av_weights = np.mean(conv_1_weights, axis=1, keepdims=True)
    
  5. Load your new network together with the old .caffemodel file, as all layers except for the first layer directly use the weights from ImageNet:

    new_net = caffe.Net('new_network.prototxt', 'imagenet.caffemodel', caffe.TEST)
    
  6. Assign your calculated average weights to the new network

    new_net.params['conv1b'][0].data[...] = conv_av_weights
    new_net.params['conv1b'][1].data[...] = conv_1_biases
    
  7. Save your weights to a new .caffemodel file:

    new_net.save('new_weights.caffemodel')
    

相关问答

更多
  • 遇到与我面临同样问题的人,请查看下面显示的原型文件。 与下载的文件夹中提供的原始原型文件相比,进行了一些修改。 我在训练和测试中使用了80x64图像大小的输入。 Train_val.prototxt name: "AlexNet" layers { name: "data" type: DATA top: "data" top: "label" data_param { source: "../../examples/Alexnet_2/Alexnet_train_leveldb ...
  • solverstate文件如其名称所传递的那样存储解算器的状态,而不是与分类结果相关的任何信息。 该模型被保存为caffemodel文件,您可以使用它来获取数据的分类结果。 如果你想微调你的网络,你可以使用预先训练好的caffemodel文件。 这将节省时间,因为您的网络不需要从头开始学习。 但是,如果您目前的培训需要停止,由于停电或意外重启,您可以恢复您以前的solverstate快照的培训。 使用solverstate和caffemodel文件的区别在于,前者允许您以预定方式完成训练,而后者可能需要更改 ...
  • caffe.io.load_image做得不多。 它只执行以下操作: 从磁盘读取图像(给定路径) 确保返回的图像有3个尺寸(HxWx1或HxWx3) (参见source caffe.io.load_image ) 因此它不会将图像加载到模型中 ,它只是一个从磁盘加载图像的辅助函数。 要将图像加载到内存中,您可以随意加载它(从磁盘,从webcam..etc)。 要加载网络,将图像输入网络并进行推理,您可以执行以下操作: # Load pre-trained network net=caffe.Net(depl ...
  • Ross Girshik博士在物体检测方面做了大量工作。 你可以从他在RCNN上的详细git中学到很多东西 :你应该能够在那里找到一个caffe分支,并且有一个演示。 我自己并没有使用它,但似乎很容易理解。 您可能会感兴趣的另一个方向是LSDA :使用弱监督来训练许多类别的对象检测。 顺便说一句,你有没有看过fast-rcnn ? Dr Ross Girshik has done a lot of work on object detection. You can learn a lot from his ...
  • 继上面的评论...... Caffe版本包括几种可以用ImageNet数据训练的流行模型。 这些模型的输入层采用一致的格式,通常是JPEG或LMDB。 接受一种格式的输入层对于不兼容的格式(例如BMP)无用。 如果要接受BMP输入,则必须指定或写入不同的输入层。 如果要在同一训练运行中同时接受JPEG和BMP,则必须为这两种格式设置单独的输入处理,以使它们成为兼容的形式。 Following on to my comment above ... The Caffe release includes seve ...
  • channel_swap将RGB转换为BGR ,如果您使用基于[1]中的注释的参考图像网络模型,则显然这是必要的。 在你的情况下,图像是灰度的,所以你可能没有三个通道。 您可能需要将其设置为(0,0,0),但即使这可能也无济于事(我不确定channel_swap的确切实施情况)。 如果这没有帮助,最简单的解决方案可能是通过将每个像素分成具有相同值的三个值(RGB)来预处理数据。 之后,您可能会完全删除channel_swap ,因为您的频道具有相同的值,并且交换它们是不可操作的。 意思是将从输入数据中减去将 ...
  • 您(或界面)未能调整灰度输入。 Gray只有1个输入通道(值); 该模型需要3个通道(RGB)。 图层顶部形状中的3应为1 。 在你的* .prototxt文件中查找顶部附近的类似内容(输入图层): shape { dim: 10 dim: 3 dim: 227 dim: 227 } 这些维度是batch_size,channels,rows和columns。 无论您在此订单上有什么内容(应该只有一个,只在输入文件中),请将3更改为1。 I figured out how to do t ...
  • 有多种方法来标准化图像。 减去训练集的平均值/归一化图像为[-1,1] 在这种情况下,他们使用函数tf.image.per_image_standardization()将每个图像标准化为[-1,1],您可以在预处理文件夹部分中看到该函数。 您也可以按照相同的预处理脚本进行微调。 def preprocess_for_eval(image, output_height, output_width): """Preprocesses the given image for evaluation. ...
  • 看一下draw_net.py脚本,你可以看到如何使用draw.py函数的draw.py 。 net参数与caffe.Net对象不完全相同,而是解析的原型文本: from google.protobuf import text_format import caffe.draw from caffe.proto import caffe_pb2 net = caffe_pb2.NetParameter() text_format.Merge(open(args.input_net_proto_file).re ...
  • Net Surgery教程应该为您提供所需的基础知识。 但是,让我更详细地解释您需要做的步骤: 准备.prototxt网络体系结构:您需要两个文件:现有的ImageNet .prototxt文件和新的时态网络体系结构。 您应该在两个网络中使除第一个卷积层之外的所有层都相同,包括层的名称。 这样,您可以使用ImageNet .caffemodel文件自动初始化权重。 由于第一个转换层具有不同的大小,因此必须在.prototxt文件中为其指定与ImageNet文件中不同的名称。 否则,Caffe将尝试使用现有权 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)