Web Excursions 2022-01-10
2012 年 6 月 30 日,很多互联网在线服务系统和网站突然同时宕机,包括知名的社区 Reddit:这是一个被人忽略的和时间相关的现象导致的错误。
Linux Kernel 的一个子系统 Hrtimer 负责唤醒因等待 CPU 时间片而睡眠的进程。但因为闰秒的影响,Hrtimer 在 Linux 内核还未完成任务前提前 1 秒唤醒了睡眠的进程,进而导致了 CPU 过载而无法正常工作。
三个常用时间格式的标准:ISO 8601, RFC 3339, & Unix timestamp
时间同步会让计算机的本地时间突然向前或者回拨,当程序在做时间差统计的时候,可能会带来错误的值(比如负数),这是墙上时钟(Wall Clock)的弊端。
而单调时钟(Monotonic Clock) 则是一种更简单的时间表示方式,它不会被 NTP 服务器影响,但是它也不能保证时间的精确性,因为它只能保证时间的递增或递减,而不能保证时间的绝对准确。
一个程序可以看作一系列行为的集合,而一个行为又可以看作一系列状态的转换
[E.g.,] 在 Erlang 的世界观里,程序是由一系列独立的进程组成的,这些进程通过消息传递(Message)来通信共享状态。
消息传递的是状态,而状态的转换是由进程来完成的。这个消息传递就是上述中的行为,
从这个角度看,程序是由大量的消息传递行为(事件)组成的
在分布式系统中,因为网络原因和节点同步时钟会产生一定的偏差,可能会出现因果悖论。
视角不同,事件的相互次序很难被判定。
全序与偏序。
宇宙时空中不存在绝对的全序事件顺序(因为很多事件都没有因果关系,也就是没有次序关系)。
但当且仅当(iff)事件 e2 是由 e1 引起时(存在因果关系),e2 后于 e1 发生,它们之间存在偏序关系。
既然在分布式中很难解决时钟同步的问题,那就不去解决这个问题。
在分布式中同步时钟是为了解决不同节点发出事件的次序(因果关系),那只需要通过某种手段解决这个事件次序的问题就好了。
这正是逻辑时钟解决问题的思路。
在 Java JMM 中就有了 Happened-before 的概念:
在多线程编程中,Happened-before 提供了跨线程的内存可见性保证。
在编译器执行编译优化的时候,会对指令做重排序,为了保证程序运行的最终正确,JMM 设定了一些 Happened-before 规则,
程序员只要遵循这些规则,JMM 就能保证程序的正确运行。
Lamport timestamp
发送进程端:
# event is known
time = time + 1;
# event happens
send(message, time);
接受进程端:
(message, time_stamp) = receive();
time = max(time_stamp, time) + 1;
描述起来就是:
每个节点都维护一个本地永远递增的逻辑时间戳(初始都为 0),节点发送事件时必须携带此逻辑时间戳。
每当节点有事件产生或接收时,节点本地的逻辑时间戳就自增 1。
如果节点接受到一个事件,
如果事件逻辑时间戳比本地逻辑时间戳还小就忽略,
否则就接收此事件,
并更新节点本地的逻辑时间戳,
新的值取节点本地逻辑时间戳和接收事件所携带的逻辑时间戳二者的最大值并自增 1。
通过构造一个全序关系来描述实际上是偏序关系的问题集。
如果两个事件毫无关系,它们的逻辑时间戳的大小比较毫无意义。
无法识别并行事件。
Vector clock
在 Lamport timestamp 单值逻辑时间戳的基础上升级为向量(Vector)时间戳。
虽然解决了 Lamport timestamp 无法识别并行事件的问题,但它也不是一种公平的算法。
在冲突出现时,也只能选择提前定义好的冲突策略来确定最终的事件版本。
不过在分布式中集群一般会通过共识算法选举一个 leader 节点,通过 leader 节点可以制定一些更合适的冲突解决算法。
In a Race to Shape the Future, History Is Under New Pressure
A wave of brazenly false or misleading historical revision,
from democratic and authoritarian governments alike,
may be threatening an already-weakened sense of a shared, accepted narrative about the world.
The trend, scholars believe, reflects some of the century’s defining forces.
Polarized societies receptive to identity-affirming falsehoods.
Collapsing faith in central institutions or arbiters of truth.
Rising nationalism.
Despots growing savvier.
Elected leaders turning increasingly toward illiberalism.
often, the goal is seemingly more short-term: to provoke rage or pride in ways that will rally citizens behind the leader’s agenda.
Since the Arab Spring and “color revolution” uprisings of a decade ago,
dictators have shifted emphasis from blunt-force repression (although this still happens, too)
to subtler methods like manipulating information or sowing division,
aimed at preventing dissent over suppressing it.
Among other changes, the blaring state newspaper has been replaced
with arrays of flashy, state-aligned outlets and social media bots,
creating a false sense that the official narrative is not imposed from on high but emerging organically.
More sophisticated propaganda, aimed at persuasion over coercion, often manifests as a particular sort of historical rewriting.
Rather than simply excising disfavored officials or government blunders,
it cultivates national pride and collective grievance meant to rally citizens.
The most effective propaganda of any sort, research finds, often focuses on an appeal to some group identity like race or religion.
Historical revisionism plays on this same impulse, telling people that the established record is an attack on their identity, like a poor score on a test,
so it should be rejected.
For opportunistic leaders, a country’s uglier moments of history are not a problem to solve — they are a gift.
A discomforting truth that citizens might prefer to forget, or, better yet, replace,
gives them an opening to impose their own narrative.
Only That I Were an Official Person! | Glenda Sluga
Women born in Europe between 1763 and 1771 and who lived through the Napoleonic wars—
even those who lacked a formal education—
were liable to remark on the limits to their life choices.
Letters between the Russian grand duchess Ekaterina and her brother Tsar Alexander during this period
overflow with her ambitions for political agency.
Ekaterina discussed politics, military dispositions, and the Russian economy.
Bourgeois and aristocratic European women took up patriotic versions of philanthropy.
Once the coalition against France began its campaign, and
the inevitable battles wounded and killed hundreds of thousands of European men,
in Prussia, patriotic philanthropy meant that for the first time “even middle-class women—like the men of their class—became an important part of wartime society.”
Among those women was Rahel Levin, who had fled French-occupied Berlin for Prague.
She drew on her meager resources to care for the soldiers who were otherwise left to die on the streets of the Bohemian town.
Before leaving Berlin, she had accrued a reputation as a salonniére, and she now had those substantial salon-based networks to draw upon.
These stretched to the men leading the political and military effort against France and to their families.
patriotism or “the love of the fatherland” was one of a number of socially acceptable forms of being political available to women.
In the shifting early nineteenth-century terrain of politics,
Patriotism’s basis in “love” or personal feelings reflected a broader philosophy of thought
that anchored political authenticity in emotions and made feeling the center of “civic identity.”
In one of Germaine de Staël’s earliest essays on the “happiness of individuals and nations,”
the French writer argued for a philosophical understanding of the passions—
the desire for glory; greed; vanity; love;
the inclination to friendship;
filial, paternal, or conjugal tenderness; and
religion.
That understanding, she believed, could be the basis of a “political science,” a discipline which, of course, had not yet been invented.
patriotism became a means of engaging politics as an emotional right.
For women so often identified with their emotional life over their intellectual capacity—
or even in relation to the “violence of their thought”
women found that philanthropy evoked as an emotional patriotism, or on behalf of humanity,
was a respectable method of being political in the emerging forum of a shared European politics.
men’s political authority could be undermined
by questioning their masculinity, their inclinations to femininity, or even a penchant for taking women seriously
Just as women could turn an emotional authenticity to some political advantage