Sequentially consistent but not linearizable execution - concurrency

I'm trying to understand the difference between linearizability and sequential consistency. More specifically, I would like to have an example of an execution which is sequentially consistent but not linearizable.
My professor gave me the following example of such execution:
Alice and bob write checks to each other.
Alice’s Statement:
-10 Check Alice -> Bob
0 Check Bob -> Alice
Bob’s Statement
-10 Check Bob -> Alice
0 Check Alice -> Bob
Both overdraft.
It is sequential: each client sees a consistent order
It is not linearizable: no globally linear story
But I didn't get it. Line
n Check A -> B
is supposed to be interpreted as "A writes a check to B and its account after the operation is n".
I don't understand why the operation shouldn't be linearisable: both Alice and Bob end up with 0 in the end which is a consistent value, so maybe I didn't get the definition of 'linearisability' properly.

First off, what your professor gave you is not the history/execution explicitly, but the projection of the history on both of its threads.
A history H is linearizable if by leaving away pending invocations and/or adding responses to pending invocations (that you didn't leave away) you can get a history that is equivalent to a sequential history S that doesn't contradict any precedences implied by H.
In other words, the reason your example is not linearizable is because the operations (financial transactions) can't be assigned a single point in time. First money is deducted, and then later added, and this behaviour is observed by the threads/individual bank statements.
If the bank statements were
Alice’s Statement:
-10 Check Alice -> Bob
0 Check Bob -> Alice
Bob’s Statement
10 Check Alice -> Bob
0 Check Bob -> Alice
then we would have a history S as follows:
Alice: Send Bob 10
Alice: Send completed
Bob: Send Alice 10
Bob: Send completed
But in your example the history could be
Alice: Send Bob 10 (i.e. money is gone)
Bob: Send Alice 10 (i.e. money is gone)
Bob: Send completed (i.e. money arrived)
Alice: Send completed (i.e. money arrived)
(or any combination of lines 1/2 switched and 3/4 switched) and you can't reorder that sequentially (i.e. pairs of started/completed together) without changing the account balance observed by each thread in between.

Related

Does 'msgMultiSend' of Cosmos coin, guarantee the order of input and output?

I am a coin wallet developer, and I am investigating Cosmos' transfer this time.
Cosmos has msgMultiSend as well as msgSend.
I know that MsgMultiSend sends several transfers using inputs and outputs in the form of an array.
At this time, I wonder if the order of inputs and outputs is matched one on one and guaranteed.
(i.e., whether the recipient matching the first sender of inputs is always guaranteed to be the first of outputs.)
(i.e.
transfer 1 : inputs[0] -> outputs[0]
transfer 2 : inputs[1] -> outputs[1]
...)
In cosmos 0.45.9, cosmjs 0.28.11, msgMultiSend have inputs that must be the same address. If you have multiple input addresses, you must have multiple signatures to verify them. And when I try to do this, the SDK show error BroadcastTxError: Broadcasting transaction failed with code 4 (codespace: sdk). Log: wrong number of signers; expected 1, got 2: unauthorized at CosmWasmClient.broadcastTx. But if you use the same address, It'll successful. Example on Aura Network Testnet: A070ED2C0557CFED34F48BF009D2E21235E79E07779A80EF49801F5983035F1B. Click JSON to view Raw Data.
And the sum token amount of inputs should equal the sum token amount of outputs. If it's not equal, this error will throw Broadcasting transaction failed with code 4 (codespace: bank). Log: sum inputs != sum outputs.
You can see the events data of the transaction to know more about this typeUrl.
Example:
1 input send to 19 outputs

Looking for SLAs pertaining to endpoint responsiveness

Could you please point me at documents you might have detailing your expected responsiveness of HERE geocoding APIs please? I'm after something more concrete than 99.9% availability.
Also, if I'm waiting for 40 minutes or 14 hours for a batch job containing a single address to be processed, does that fail 99.9%?
You can view the SLA-report by logging into developer.here.com and going to https://developer.here.com/sla-report. Batch jobs are POST requests and the time to complete your request depends on the queue size (there would be other requests waiting) and the batch size. So this doesn't fail 99.9%.
For a single address as you listed will take just few milliseconds. Anything above that, especially 40 min indicates that you are probably not connected. This includes invalid address input as the result will be back telling you that the address is not found. You can check the previous status using RequestID from the request like that https://batch.geocoder.ls.hereapi.com/6.2/jobs/
E2bc948zBsMCG4QclFKCq3tddWYCsE9g
?action=status
&apiKey={YOUR_API_KEY}
In general, if your address has more address tokens, it will take longer to return comparing to if it has fewer address tokens.
example
USA vs 1600 Pennsylvania Ave NW, Washington, DC 20500,USA

Running three functions at once?

C++
Working on a problem for school, running 3 horses in a race and whoever finishes first is the winner. the 3 horses are supposed to run in sync like this
1|--------H------|
2|-------H-------|
3|---------H-----|
However my code runs the program correctly (generate a random number between 1 and 100 and if that number is less than 50 move the horse 1 space up). but it runs the first horse, then the 2nd and the 3rd last.
tried to look this up but none of the methods seem to work (using codeblocks (latest version Windows 10) for C++).
srand(time(NULL));
Horse1();
Horse2();
Horse3();
Github file: https://gist.github.com/EthanA2020/f16a699f1b8136a1da0350ab48acdda0
I don't think your issue is with the type of function but instead the structure of your program. No matter how you program, one operation must come before the next. Developers work with this by running each operation of the object (in your case the horse movement) side by side and checking later to see the outcome.
For example, lets use your horse scenario:
while "all horses" are less than "finish"
horse 1 moves
horse 2 moves
horse 3 moves
I am sure that you are familiar with loops so we'll use that here. Some set distance must exist to determine when a horse has finished. So you'll want to continue that loop while all horses have a distance less than that value. During each loop, each horse's movement value must either change or not (determined by your random movement function).
Now once this while loop has ended, you can be sure that at least one horse has crossed the finish line. All operations have been completed and you have a data set of the horses positions. This is the point where you check to see which horses have finished (I say horses plural because there is a chance that more than one horse or even all 3 finish at the same time, so be sure to factor that in at the end).
With that, your program structure should be something like:
while "all horses" are less than "finish"
horse 1 moves
horse 2 moves
horse 3 moves
//movement of horses complete
check and print the horses with a movement value of "finish"
I think you should do:
while (!horse(rand() % 100)) {
usleep(100);
}
Where horse(int n) moves horse n 1 position and if it reached the end, it returns true (to end the race). It does nothing if an invalid n (only 1 to 3 is valid) is passed to it.

Interactive Brokers returns multiple "presubmitted" order statuses for a single order

Has anyone experienced multiple order statuses per sent order?
Is there a way to fix this or what is the best way to deal with it?
./PosixSocketClientTest 10.1.55.2
Start of POSIX Socket Client Test 0
Attempt 1 of 50
Connecting to 10.1.55.2:7496 clientId:0
Connected to 10.1.55.2:7496 clientId:0
Placing Order 42: BUY 1000 IBM at 0.010000
Order: id=42, status=PreSubmitted
Requesting Current Time
The current date/time is: Sat May 7 12:20:04 2016
Order: id=42, status=PreSubmitted
Order: id=42, status=Cancelled
https://www.interactivebrokers.com/en/software/api/apiguide/c/orderstatus.htm
Note: It is possible that orderStatus() may return duplicate
messages. It is essential that you filter the message accordingly.
There's 2 fields, filled and remaining that I watch to know how the order is doing. When remaining is 0, it's all done. That way you also know if it's a partial fill.

rdkafka consumer query about partition size

Let's say I don't have access to the set of producers that commits on the partition of interest, but just have control over a bunch of C++ consumers.
Since I'm running benchmarks over a complex program, I'd like to know the spread between the offset my consumers are fetching and the total offset stored in the partition.
e.g., >> reading message #1234 of 5678 total in partition 0 of topic foo
I misunderstood the purpose of RdKafka::Consumer->outq_len() and RdKafka::Topic->OFFSET_END, because they seem always equal to 0 and -1, respectively.
How can I acquire the 5678 value of my example?
You need to subscribe to librdkafka's statistics to get an updated view of your consumer's lag.
Register an Event callback class and regularily call poll() on your handle, check for EVENT_STATS and then parse the corresponding JSON message and look for lo_offset, hi_offset and consumer_lag.