微服务之间的通信(Communication Between Microservices)
假设您有微服务A,B和C,它们当前都通过HTTP进行通信。 假设服务A向服务B发送请求,从而产生响应。 然后,必须将该响应中返回的数据发送到服务C进行某些处理,最后返回到服务A.服务A现在可以在网页上显示结果。
我知道延迟是实现微服务架构的固有问题,我想知道减少这种延迟的常用方法是什么?
另外,我一直在阅读Apache Thrift和RPC如何帮助解决这个问题。 任何人都可以详细说明吗?
Say you have microservice A,B, and C which all currently communicate through HTTP. Say service A sends a request to service B which results in a response. The data returned in that response must then be sent to service C for some processing before finally being returned to service A. Service A can now display the results on the web page.
I know that latency is an inherent issue with implementing a microservice architecture, and I was wondering what are some common ways of reducing this latency?
Also, I have been doing some reading on how Apache Thrift and RPC's can help with this. Can anyone elaborate on that as well?
原文:https://stackoverflow.com/questions/35673254
最满意答案
您不需要滚动条滚动。 所有可滚动的小部件都有一个用于滚动的api:
xview
和yview
方法。 滚动条只是调用这些方法的一种方便方法,但它不是唯一的方法。我不知道滑动会发送什么事件,但您可以绑定到这些事件并直接自己调用
xview
和/或yview
方法。例如,我们假设触摸是
<B1>
事件,而滑动是<B1-Motion>
事件。 您可以使用这样的滑动动作滚动:class Example: def __init__(self): ... self.tree = ttk.Treeview(...) self.tree.bind("<B1>", self.start_swipe) self.tree.bind("<B1-Motion>", self.on_swipe) ... def start_swipe(self, event): self.last_y = event.y def on_swipe(self, event): # only do the scrolling if the swipe is 10 pixels or more if abs(event.y - self.swipe_start) < 10: return # compute whether we are scrolling up or down delta = -1 if event.y > self.last_y else 1 # remember this location for the next time this is called self.last_y = event.y # do the scroll self.tree.yview_scroll(delta, "units")
You don't need scrollbars to scroll. All scrollable widgets have an api that is used for scrolling: the
xview
andyview
methods. The scrollbar is just a convenient way to call those methods, but it's not the only way.I don't know what events a swipe will send, but you can bind to those events and directly call the
xview
and/oryview
methods yourself.For example, let's assume for the moment that a touch is the
<B1>
event, and a swipe is the<B1-Motion>
event. You can scroll with a swiping motion like this:class Example: def __init__(self): ... self.tree = ttk.Treeview(...) self.tree.bind("<B1>", self.start_swipe) self.tree.bind("<B1-Motion>", self.on_swipe) ... def start_swipe(self, event): self.last_y = event.y def on_swipe(self, event): # only do the scrolling if the swipe is 10 pixels or more if abs(event.y - self.swipe_start) < 10: return # compute whether we are scrolling up or down delta = -1 if event.y > self.last_y else 1 # remember this location for the next time this is called self.last_y = event.y # do the scroll self.tree.yview_scroll(delta, "units")
相关问答
更多-
Python - tkinter删除滚动条和条目小部件之间的空间(Python - tkinter remove space between scrollbar and entry widgets)[2023-12-10]
在这种特定情况下,最简单的解决方案是使用sticky=(N, E, W) 。 您的代码目前使其粘贴到单元格的顶部和底部( N和S ),导致它在以太网中拉伸或在单元格中居中(例如,在Mac上,滚动条是固定大小的,因此它们将集中而不是伸展)。 由于您希望它“粘贴”在紧靠其上方的小部件的底部,因此您不希望它也“粘住”到其自己单元格的底部。 In this specific case, the simplest solution is to use sticky=(N, E, W). Your code curre ... -
所以,我刚刚为我的问题找到了一种解决方法Tkinter似乎在多线程方面存在问题。 所以我只是将Tkinter.Scrollbar更改为ttk.Scrollbar 。 ttk模块是Tkinter的扩展版本,解决了Tkinter模块的一些奇怪行为。 请查看http://docs.python.org/3.1/library/tkinter.ttk.html 更改小部件的模块后,一切都按预期工作! 这个解决方案只是实际问题的解决方法,但它的工作原理! So, I just found a kind of work ...
-
概观 您只能将滚动条与一些小部件相关联,并且根窗口小部件和Frame不是该组窗口小部件的一部分。 最常见的解决方案是创建一个画布小部件,并将滚动条与该小部件相关联。 然后,在该画布中嵌入包含标签小部件的框架。 确定框架的宽度/高度,并将其馈送到画布scrollregion选项,以便滚动区域与框架的大小完全匹配。 在画布上直接绘制文本不是很难,因此如果框架嵌入式画布解决方案似乎太复杂,您可能需要重新考虑该方法。 由于您正在创建一个网格,所以每个文本项目的坐标将很容易计算,特别是如果每一行的高度相同(如果使用单 ...
-
滚动条需要将根窗口作为父窗口,而不是树。 scrollbar = Scrollbar(root) The scrollbars need to have the root window as the parent, not the tree. scrollbar = Scrollbar(root)
-
不是一个完整的答案,但你考虑过创建自己的滚动条看起来像: import tkinter as tk class MyScrollbar(tk.Canvas): def __init__(self, master, *args, **kwargs): if 'width' not in kwargs: kwargs['width'] = 10 if 'bd' not in kwargs: kwargs['bd'] = 0 ...
-
Tk Scrollbar小部件(vbar)是Windows中的本机滚动条。 它的外观取决于Windows主题。 如果重要,请考虑更换工具包; 我知道PyQt4会让你在Windows上设置滚动条的样式。 The Tk Scrollbar widget (vbar) is a native scrollbar in Windows. Its appearance depends on the Windows theme. Consider switching toolkits if it matters; I ...
-
在向画布添加项目时,必须重新配置scrollregion 。 You must re-configure scrollregion when you add items to the canvas.
-
您不需要滚动条滚动。 所有可滚动的小部件都有一个用于滚动的api: xview和yview方法。 滚动条只是调用这些方法的一种方便方法,但它不是唯一的方法。 我不知道滑动会发送什么事件,但您可以绑定到这些事件并直接自己调用xview和/或yview方法。 例如,我们假设触摸是
事件,而滑动是 事件。 您可以使用这样的滑动动作滚动: class Example: def __init__(self): ... self.tree = ttk.T ... -
您不希望将文本小部件用作滚动条的主控。 与任何其他窗口小部件一样,如果您在文本窗口小部件中打包或网格化滚动条,则文本窗口小部件将缩小或展开以适合滚动条。 这是你问题的症结所在。 相反,创建一个单独的框架(您已经在做),并将该框架用作文本窗口小部件和滚动条的父框架。 如果您想要滚动条位于其中的外观,请将文本小部件的边框宽度设置为零,然后为包含的框架指定一个小边框。 作为最终的可用性提示,我建议不要使窗口不可调整大小。 您的用户可能比您更了解他们想要的窗口大小。 不要将控制权从用户手中夺走。 这是(大致)我将如 ...
-
虽然我很少推荐place ,但在利用配置选项时它非常强大。 例如,您可以使用in_指定要相对于此窗口小部件放置的窗口小部件。 您可以使用relx指定相对x坐标,并且可以使用relheight指定高度。 在你的情况下,你可以尝试这样的事情: vscroll.place(in_=txtOutput, relx=1.0, relheight=1.0, bordermode="outside") 如果您想要在某些平台上将滚动条嵌入到文本小部件内部(或曾经是常用的),我建议将文本小部件和滚动条放在一个框架中。您可以 ...