<div dir="ltr">Hi haskellers<div><br></div><div>I´m implementing a form of intelligent streaming among nodes so that a process could know if there are bottlenecks on sending/receiving data so the process can increase or decrease the number of worker threads, for example.</div><div><br></div><div>For this purpose, I planned to use <span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:15.2727px;white-space:pre">hPutBufNonBlocking </span>and <span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:15.2727px;white-space:pre"> </span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:15.2727px;white-space:pre">hGetBufNonBlocking </span>to detect when the buffer is full, using block buffering.</div><div><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:15.2727px;white-space:pre"><br></span></div><div>I created <span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:15.2727px;white-space:pre">hPutStrLn' </span>that tries to write the entire string in the buffer. if it does not fit, the process would be notified in a state variable, then it would do a flush of the buffer and the rest of the string would be sent with hPutBuf. Doing some tinkering here and there It came up to be this:<br></div><div><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:15.2727px;white-space:pre"><br></span></div><div><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace"><span style="font-size:12px;line-height:15.2727px;white-space:pre">hPutStrLn' h str= do
let bs@(PS ps s l) = BS.pack $ str ++ "\n"
n <- withForeignPtr ps $ \p-> hPutBufNonBlocking h (p `plusPtr` s) l
when( n < l) $ do
error "BUFFER FULLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL"
hFlush h
withForeignPtr ps $ \p -> hPutBuf h ( p `plusPtr` (n * sizeOf 'x' ) ) (l - n)
return ()</span></font><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:15.2727px;white-space:pre"> </span></div><div><br></div><div>The error condition is the one that I expected to detect in the tests. In the real code, this line just would set a state variable, that would be read by the process somewhere else.</div><div><br></div><div>The problem is that this routine behaves identically to <span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:15.2727px;white-space:pre">hPutStrLn</span>. The error condition never happens and <span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:15.2727px;white-space:pre">hPutBufNonBlocking </span>send the complete string every time.</div><div><br></div><div>I created a program </div><div><br></div><div><a href="https://gist.github.com/agocorona/6568bd61d71ab921ad0c">https://gist.github.com/agocorona/6568bd61d71ab921ad0c</a></div><div><br></div><div><div>The example print the output of the receiver "hello" continuously</div></div><div><br></div><div>Note that in the complete running code below, the receiver has a threadDelay of a second, so the send and receive buffers should be full.</div><div><br></div><div>That happens in Windows and Linux, in a single process (like in the example) or within two processes in the same machine.</div><div><br></div><div>How the processes can detect the congestion?</div><div><br></div><div><div><br></div>-- <br><div class="gmail_signature">Alberto.</div>
</div></div>