Skip to content

Streaming refactoring #991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2018
Merged

Conversation

phadej
Copy link
Contributor

@phadej phadej commented Jun 23, 2018

  • make StreamReqBody combinator
  • write proper example (now just cassava copy)
  • CPSise SourceT
  • Add instances for conduit with resourcet, safe-pipes etc.
  • potoki
  • streaming
  • withFile
  • cookbook example for an example how to work without conduit/pipes/machines/... in simple
    examples
  • rename things, like b to chunk.
  • update tutorial
  • update docs (API.Stream)
  • write stub changelog (there're a lot of changes), moved to Separate streaming client #1066

I'll leave implementing docs/foreign for now (i.e. leave dummy instances), as that we'll need to be redone for #841 / #969

@phadej phadej changed the title Servant machines WIP: servant-machines Jun 23, 2018
import Data.Machine
import Servant.API.Stream

instance m ~ IO => ToStreamGenerator (MachineT m k o) o where
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tempted to use MonadUnliftIO

@phadej phadej force-pushed the servant-machines branch 2 times, most recently from 6623927 to 14f43ef Compare June 24, 2018 17:10
@phadej phadej mentioned this pull request Jun 24, 2018
@phadej phadej force-pushed the servant-machines branch 12 times, most recently from 72d00e6 to 6db9f1a Compare June 27, 2018 16:40
@phadej
Copy link
Contributor Author

phadej commented Jun 27, 2018

Last commit adds a simple script to test the streaming stuff, as @alpmestan asked for!

Streaming test benchmark

size parameter: 10000000

Server

machines

time: 41,279152, size:  78888898, download speed: 1911114,000
...machines:example server +RTS -sbench-machines-server-rts.txt 
  71,520,388,096 bytes allocated in the heap
      29,192,072 bytes copied during GC
         121,560 bytes maximum residency (5 sample(s))
          27,520 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     39062 colls,     0 par    0.392s   0.384s     0.0000s    0.0011s
  Gen  1         5 colls,     0 par    0.005s   0.005s     0.0009s    0.0023s

  TASKS: 5 (1 bound, 4 peak workers (4 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.001s  (  0.001s elapsed)
  MUT     time   40.829s  ( 44.922s elapsed)
  GC      time    0.397s  (  0.388s elapsed)
  EXIT    time    0.000s  (  0.010s elapsed)
  Total   time   41.226s  ( 45.320s elapsed)

  Alloc rate    1,751,719,428 bytes per MUT second

  Productivity  99.0% of total user, 99.1% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

conduit

Conduit server is also used for client tests below

time: 41,901278, size:  78888898, download speed: 1882744,000
...conduit:example server +RTS -sbench-conduit-server-rts.txt 
 209,280,828,184 bytes allocated in the heap
      89,219,576 bytes copied during GC
         121,632 bytes maximum residency (5 sample(s))
          27,472 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     117187 colls,     0 par    1.223s   1.195s     0.0000s    0.0010s
  Gen  1         5 colls,     0 par    0.004s   0.006s     0.0012s    0.0043s

  TASKS: 5 (1 bound, 4 peak workers (4 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.000s  (  0.000s elapsed)
  MUT     time  127.654s  (132.061s elapsed)
  GC      time    1.227s  (  1.201s elapsed)
  EXIT    time    0.001s  (  0.008s elapsed)
  Total   time  128.883s  (133.270s elapsed)

  Alloc rate    1,639,437,404 bytes per MUT second

  Productivity  99.0% of total user, 99.1% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

Client

machines

Command being timed: "...machines:example client 10000000 +RTS -sbench-machines-client-rts.txt"
User time (seconds): 19.80
System time (seconds): 23.49
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:43.73
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 15808
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 1387
Voluntary context switches: 153263
Involuntary context switches: 3675
Swaps: 0
File system inputs: 0
File system outputs: 8
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
...machines:example client 10000000 +RTS -sbench-machines-client-rts.txt 
 119,718,183,000 bytes allocated in the heap
      48,344,592 bytes copied during GC
          82,240 bytes maximum residency (17 sample(s))
          29,360 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     62718 colls,     0 par    0.606s   0.597s     0.0000s    0.0017s
  Gen  1        17 colls,     0 par    0.001s   0.001s     0.0000s    0.0002s

  TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.001s  (  0.001s elapsed)
  MUT     time   42.687s  ( 43.127s elapsed)
  GC      time    0.607s  (  0.598s elapsed)
  EXIT    time    0.000s  (  0.005s elapsed)
  Total   time   43.295s  ( 43.730s elapsed)

  Alloc rate    2,804,552,791 bytes per MUT second

  Productivity  98.6% of total user, 98.6% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

conduit

Command being timed: "...conduit:example client 10000000 +RTS -sbench-conduit-client-rts.txt"
User time (seconds): 19.51
System time (seconds): 23.51
Percent of CPU this job got: 98%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:43.49
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 15732
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 1388
Voluntary context switches: 156142
Involuntary context switches: 3531
Swaps: 0
File system inputs: 0
File system outputs: 8
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
...conduit:example client 10000000 +RTS -sbench-conduit-client-rts.txt 
 117,581,651,768 bytes allocated in the heap
      41,904,504 bytes copied during GC
          83,240 bytes maximum residency (14 sample(s))
          29,304 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     60056 colls,     0 par    0.572s   0.569s     0.0000s    0.0048s
  Gen  1        14 colls,     0 par    0.001s   0.001s     0.0000s    0.0001s

  TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.000s  (  0.000s elapsed)
  MUT     time   42.456s  ( 42.917s elapsed)
  GC      time    0.573s  (  0.570s elapsed)
  EXIT    time    0.000s  (  0.002s elapsed)
  Total   time   43.029s  ( 43.490s elapsed)

  Alloc rate    2,769,514,146 bytes per MUT second

  Productivity  98.7% of total user, 98.7% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

@phadej
Copy link
Contributor Author

phadej commented Jun 27, 2018

And with pipes:

Streaming test benchmark

size parameter: 10000000

Server

machines

time: 40,190393, size:  78888898, download speed: 1962898,000
...machines:example server +RTS -sbench-machines-server-rts.txt 
  71,520,388,072 bytes allocated in the heap
      29,192,072 bytes copied during GC
         121,560 bytes maximum residency (5 sample(s))
          27,520 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     39062 colls,     0 par    0.392s   0.385s     0.0000s    0.0013s
  Gen  1         5 colls,     0 par    0.005s   0.005s     0.0010s    0.0027s

  TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.001s  (  0.001s elapsed)
  MUT     time   39.723s  ( 43.843s elapsed)
  GC      time    0.397s  (  0.390s elapsed)
  EXIT    time    0.001s  (  0.006s elapsed)
  Total   time   40.122s  ( 44.240s elapsed)

  Alloc rate    1,800,462,171 bytes per MUT second

  Productivity  99.0% of total user, 99.1% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

pipes

time: 40,915066, size:  78888898, download speed: 1928116,000
/home/ogre/Documents/shared-haskell/servant/dist-newstyle/build/x86_64-linux/ghc-8.2.2/servant-pipes-1/t/example/build/example/example server +RTS -sbench-pipes-server-rts.txt 
  69,760,387,856 bytes allocated in the heap
      29,817,056 bytes copied during GC
         121,584 bytes maximum residency (5 sample(s))
          27,664 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     39062 colls,     0 par    0.374s   0.368s     0.0000s    0.0010s
  Gen  1         5 colls,     0 par    0.003s   0.003s     0.0006s    0.0018s

  TASKS: 5 (1 bound, 4 peak workers (4 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.000s  (  0.000s elapsed)
  MUT     time   40.503s  ( 44.585s elapsed)
  GC      time    0.377s  (  0.371s elapsed)
  EXIT    time    0.000s  (  0.003s elapsed)
  Total   time   40.881s  ( 44.960s elapsed)

  Alloc rate    1,722,339,022 bytes per MUT second

  Productivity  99.1% of total user, 99.2% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

conduit

Conduit server is also used for client tests below

time: 42,947184, size:  78888898, download speed: 1836889,000
...conduit:example server +RTS -sbench-conduit-server-rts.txt 
 279,041,049,072 bytes allocated in the heap
     118,921,392 bytes copied during GC
         121,632 bytes maximum residency (5 sample(s))
          27,376 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     156250 colls,     0 par    1.804s   1.757s     0.0000s    0.0012s
  Gen  1         5 colls,     0 par    0.004s   0.004s     0.0007s    0.0017s

  TASKS: 5 (1 bound, 4 peak workers (4 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.000s  (  0.000s elapsed)
  MUT     time  176.726s  (181.269s elapsed)
  GC      time    1.807s  (  1.761s elapsed)
  EXIT    time    0.001s  (  0.010s elapsed)
  Total   time  178.534s  (183.040s elapsed)

  Alloc rate    1,578,951,794 bytes per MUT second

  Productivity  99.0% of total user, 99.0% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

Client

machines

Command being timed: "...machines:example client 10000000 +RTS -sbench-machines-client-rts.txt"
User time (seconds): 20.84
System time (seconds): 23.48
Percent of CPU this job got: 98%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:44.85
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 15756
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 1386
Voluntary context switches: 167604
Involuntary context switches: 4723
Swaps: 0
File system inputs: 0
File system outputs: 8
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
...machines:example client 10000000 +RTS -sbench-machines-client-rts.txt 
 117,719,119,032 bytes allocated in the heap
      46,776,576 bytes copied during GC
          83,504 bytes maximum residency (13 sample(s))
          33,328 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     61149 colls,     0 par    0.620s   0.602s     0.0000s    0.0010s
  Gen  1        13 colls,     0 par    0.001s   0.001s     0.0000s    0.0003s

  TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.001s  (  0.001s elapsed)
  MUT     time   43.704s  ( 44.242s elapsed)
  GC      time    0.621s  (  0.603s elapsed)
  EXIT    time    0.001s  (  0.005s elapsed)
  Total   time   44.326s  ( 44.851s elapsed)

  Alloc rate    2,693,584,307 bytes per MUT second

  Productivity  98.6% of total user, 98.7% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

pipes

Command being timed: "/home/ogre/Documents/shared-haskell/servant/dist-newstyle/build/x86_64-linux/ghc-8.2.2/servant-pipes-1/t/example/build/example/example client 10000000 +RTS -sbench-pipes-client-rts.txt"
User time (seconds): 21.20
System time (seconds): 22.94
Percent of CPU this job got: 98%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:44.76
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 15660
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 1385
Voluntary context switches: 342092
Involuntary context switches: 4216
Swaps: 0
File system inputs: 0
File system outputs: 8
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
/home/ogre/Documents/shared-haskell/servant/dist-newstyle/build/x86_64-linux/ghc-8.2.2/servant-pipes-1/t/example/build/example/example client 10000000 +RTS -sbench-pipes-client-rts.txt 
 114,891,552,264 bytes allocated in the heap
      44,797,032 bytes copied during GC
          83,552 bytes maximum residency (27 sample(s))
          29,312 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     61024 colls,     0 par    0.690s   0.689s     0.0000s    0.0121s
  Gen  1        27 colls,     0 par    0.001s   0.001s     0.0000s    0.0001s

  TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.000s  (  0.000s elapsed)
  MUT     time   43.460s  ( 44.063s elapsed)
  GC      time    0.691s  (  0.689s elapsed)
  EXIT    time    0.000s  (  0.007s elapsed)
  Total   time   44.152s  ( 44.760s elapsed)

  Alloc rate    2,643,632,966 bytes per MUT second

  Productivity  98.4% of total user, 98.5% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

conduit

Command being timed: "...conduit:example client 10000000 +RTS -sbench-conduit-client-rts.txt"
User time (seconds): 21.66
System time (seconds): 23.98
Percent of CPU this job got: 98%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:46.27
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 15844
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 1389
Voluntary context switches: 219272
Involuntary context switches: 3585
Swaps: 0
File system inputs: 0
File system outputs: 8
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
...conduit:example client 10000000 +RTS -sbench-conduit-client-rts.txt 
 121,831,224,344 bytes allocated in the heap
      44,719,976 bytes copied during GC
          83,152 bytes maximum residency (9 sample(s))
          33,328 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     63359 colls,     0 par    0.626s   0.622s     0.0000s    0.0050s
  Gen  1         9 colls,     0 par    0.001s   0.001s     0.0001s    0.0003s

  TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.001s  (  0.000s elapsed)
  MUT     time   45.020s  ( 45.640s elapsed)
  GC      time    0.627s  (  0.623s elapsed)
  EXIT    time    0.000s  (  0.007s elapsed)
  Total   time   45.648s  ( 46.270s elapsed)

  Alloc rate    2,706,143,849 bytes per MUT second

  Productivity  98.6% of total user, 98.7% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

@phadej
Copy link
Contributor Author

phadej commented Jun 27, 2018

FWIW, test suites fails because of deps (conduit lower bound forces to GHC >= 8.0 (see https://matrix.hackage.haskell.org/package/conduit). Maybe it's time to drop older GHC support (though atm the only reason is deps).

@phadej phadej changed the title WIP: servant-machines Streaming refactoring Jun 27, 2018
@phadej
Copy link
Contributor Author

phadej commented Jun 27, 2018

one idea is to bake Codensity into ClientM. I'll try that next.

@alpmestan
Copy link
Contributor

Me: 🍿

go (Effect ms) = Effect (liftIO (fmap go ms))
go (Yield x s) = Yield x (go s)

-- This fires e.g. in Client.lhs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Thanks for leaving that note.

@phadej phadej added this to the 0.15 milestone Jun 29, 2018
@phadej phadej force-pushed the servant-machines branch 2 times, most recently from 9528665 to 51d6cab Compare June 29, 2018 21:47
@phadej
Copy link
Contributor Author

phadej commented Jun 29, 2018

With cookbook

Streaming test benchmark

size parameter: 10000000

Server

  • /fast/10000000
  • /proxy

machines

time: 39,733844, size:  78888898, download speed: 1985475,000
time: 0,089031, size:  37889192, download speed: 425721258,000
...machines:example server +RTS -sbench-machines-server-rts.txt 
  71,371,921,256 bytes allocated in the heap
      29,126,256 bytes copied during GC
         122,176 bytes maximum residency (5 sample(s))
          31,056 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     39073 colls,     0 par    0.325s   0.322s     0.0000s    0.0011s
  Gen  1         5 colls,     0 par    0.006s   0.006s     0.0012s    0.0034s

  TASKS: 5 (1 bound, 4 peak workers (4 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.002s  (  0.001s elapsed)
  MUT     time   39.509s  ( 43.524s elapsed)
  GC      time    0.331s  (  0.328s elapsed)
  EXIT    time    0.003s  (  0.009s elapsed)
  Total   time   39.845s  ( 43.862s elapsed)

  Alloc rate    1,806,474,599 bytes per MUT second

  Productivity  99.2% of total user, 99.2% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

pipes

time: 38,767521, size:  78888898, download speed: 2034949,000
time: 0,090281, size:  37889192, download speed: 420991022,000
...pipes:example server +RTS -sbench-pipes-server-rts.txt 
  69,774,638,824 bytes allocated in the heap
      30,068,000 bytes copied during GC
         122,440 bytes maximum residency (5 sample(s))
          30,712 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     39076 colls,     0 par    0.350s   0.345s     0.0000s    0.0010s
  Gen  1         5 colls,     0 par    0.004s   0.004s     0.0008s    0.0022s

  TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.000s  (  0.000s elapsed)
  MUT     time   38.499s  ( 42.557s elapsed)
  GC      time    0.354s  (  0.349s elapsed)
  EXIT    time    0.000s  (  0.004s elapsed)
  Total   time   38.853s  ( 42.910s elapsed)

  Alloc rate    1,812,398,052 bytes per MUT second

  Productivity  99.1% of total user, 99.2% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

conduit

Conduit server is also used for client tests below

time: 40,985865, size:  78888898, download speed: 1924823,000
time: 0,090496, size:  37889192, download speed: 420991022,000
...conduit:example server +RTS -sbench-conduit-server-rts.txt 
 348,414,455,624 bytes allocated in the heap
     147,302,664 bytes copied during GC
         122,472 bytes maximum residency (5 sample(s))
          31,040 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     195325 colls,     0 par    1.925s   1.889s     0.0000s    0.0012s
  Gen  1         5 colls,     0 par    0.004s   0.004s     0.0008s    0.0019s

  TASKS: 5 (1 bound, 4 peak workers (4 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.001s  (  0.001s elapsed)
  MUT     time  180.527s  (184.807s elapsed)
  GC      time    1.929s  (  1.893s elapsed)
  EXIT    time    0.000s  (  0.010s elapsed)
  Total   time  182.457s  (186.710s elapsed)

  Alloc rate    1,929,979,972 bytes per MUT second

  Productivity  98.9% of total user, 99.0% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

cookbook

time: 42,202252, size:  78888898, download speed: 1869316,000
time: 0,090934, size:  37889192, download speed: 420991022,000
...cookbook-basic-streaming server +RTS -sbench-cookbook-server-rts.txt 
  69,132,729,840 bytes allocated in the heap
      28,502,832 bytes copied during GC
         122,424 bytes maximum residency (5 sample(s))
          30,704 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     39074 colls,     0 par    0.368s   0.362s     0.0000s    0.0006s
  Gen  1         5 colls,     0 par    0.004s   0.004s     0.0008s    0.0020s

  TASKS: 5 (1 bound, 4 peak workers (4 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.001s  (  0.001s elapsed)
  MUT     time   41.915s  ( 45.976s elapsed)
  GC      time    0.371s  (  0.365s elapsed)
  EXIT    time    0.005s  (  0.008s elapsed)
  Total   time   42.292s  ( 46.350s elapsed)

  Alloc rate    1,649,372,760 bytes per MUT second

  Productivity  99.1% of total user, 99.2% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

Client

machines

Command being timed: "...machines:example client 10000000 +RTS -sbench-machines-client-rts.txt"
User time (seconds): 17.52
System time (seconds): 15.87
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:33.44
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 15860
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 1386
Voluntary context switches: 81317
Involuntary context switches: 1320
Swaps: 0
File system inputs: 0
File system outputs: 8
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
...machines:example client 10000000 +RTS -sbench-machines-client-rts.txt 
  94,276,810,792 bytes allocated in the heap
      42,498,992 bytes copied during GC
          83,568 bytes maximum residency (86 sample(s))
          33,320 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     56300 colls,     0 par    0.781s   0.773s     0.0000s    0.0009s
  Gen  1        86 colls,     0 par    0.002s   0.002s     0.0000s    0.0001s

  TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.000s  (  0.000s elapsed)
  MUT     time   32.612s  ( 32.659s elapsed)
  GC      time    0.783s  (  0.775s elapsed)
  EXIT    time    0.001s  (  0.006s elapsed)
  Total   time   33.397s  ( 33.440s elapsed)

  Alloc rate    2,890,842,893 bytes per MUT second

  Productivity  97.7% of total user, 97.7% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

pipes

Command being timed: "...pipes:example client 10000000 +RTS -sbench-pipes-client-rts.txt"
User time (seconds): 19.02
System time (seconds): 23.38
Percent of CPU this job got: 100%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:42.39
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 15792
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 1386
Voluntary context switches: 116164
Involuntary context switches: 1804
Swaps: 0
File system inputs: 0
File system outputs: 8
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
...pipes:example client 10000000 +RTS -sbench-pipes-client-rts.txt 
 114,464,122,120 bytes allocated in the heap
      38,997,664 bytes copied during GC
          76,144 bytes maximum residency (3 sample(s))
          33,320 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     56631 colls,     0 par    0.468s   0.461s     0.0000s    0.0012s
  Gen  1         3 colls,     0 par    0.000s   0.000s     0.0000s    0.0001s

  TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.000s  (  0.000s elapsed)
  MUT     time   41.936s  ( 41.924s elapsed)
  GC      time    0.469s  (  0.461s elapsed)
  EXIT    time    0.000s  (  0.004s elapsed)
  Total   time   42.405s  ( 42.390s elapsed)

  Alloc rate    2,729,511,274 bytes per MUT second

  Productivity  98.9% of total user, 98.9% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

conduit

Command being timed: "...conduit:example client 10000000 +RTS -sbench-conduit-client-rts.txt"
User time (seconds): 18.03
System time (seconds): 24.93
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:42.98
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 15824
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 1391
Voluntary context switches: 124426
Involuntary context switches: 1967
Swaps: 0
File system inputs: 0
File system outputs: 8
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
...conduit:example client 10000000 +RTS -sbench-conduit-client-rts.txt 
 118,837,115,344 bytes allocated in the heap
      41,210,664 bytes copied during GC
          83,392 bytes maximum residency (5 sample(s))
          33,352 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     58899 colls,     0 par    0.501s   0.489s     0.0000s    0.0015s
  Gen  1         5 colls,     0 par    0.000s   0.000s     0.0001s    0.0002s

  TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.000s  (  0.000s elapsed)
  MUT     time   42.466s  ( 42.484s elapsed)
  GC      time    0.501s  (  0.490s elapsed)
  EXIT    time    0.000s  (  0.007s elapsed)
  Total   time   42.969s  ( 42.980s elapsed)

  Alloc rate    2,798,375,431 bytes per MUT second

  Productivity  98.8% of total user, 98.9% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

cookbook

Command being timed: "...cookbook-basic-streaming client 10000000 +RTS -sbench-cookbook-client-rts.txt"
User time (seconds): 15.71
System time (seconds): 6.83
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:22.55
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 15464
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 1364
Voluntary context switches: 85306
Involuntary context switches: 707
Swaps: 0
File system inputs: 0
File system outputs: 8
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
...cookbook-basic-streaming client 10000000 +RTS -sbench-cookbook-client-rts.txt 
  71,254,068,216 bytes allocated in the heap
      39,504,288 bytes copied during GC
          83,528 bytes maximum residency (183 sample(s))
          29,248 bytes maximum slop
               4 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     54759 colls,     0 par    1.116s   1.109s     0.0000s    0.0012s
  Gen  1       183 colls,     0 par    0.005s   0.005s     0.0000s    0.0004s

  TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.000s  (  0.000s elapsed)
  MUT     time   21.423s  ( 21.434s elapsed)
  GC      time    1.121s  (  1.114s elapsed)
  EXIT    time    0.000s  (  0.002s elapsed)
  Total   time   22.545s  ( 22.550s elapsed)

  Alloc rate    3,325,977,453 bytes per MUT second

  Productivity  95.0% of total user, 95.1% of total elapsed

gc_alloc_block_sync: 0
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 0

@phadej phadej force-pushed the servant-machines branch from 6e707a1 to d47937c Compare June 30, 2018 19:19
Copy link
Contributor

@alpmestan alpmestan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I'm completely in line with the approach and don't have much to say. I'll be a little more annoying when the docs etc are done, but great stuffs!


instance ToSourceIO a [a] where
toSourceIO = source

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we'll want to support all the reasonable container types we directly or indirectly depend on?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess things in base would be enough. But I still wonder how #841 would reshuffle this.

Let's leave an issue to remember about other containers?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

@phadej
Copy link
Contributor Author

phadej commented Oct 30, 2018

I'm resurrecting this PR. Hopefully will be able to finish soon.

@jvanbruegge
Copy link
Contributor

How is this PR related to #995 ? Or is it not related at all? I am not sure what this PR does

@phadej
Copy link
Contributor Author

phadej commented Oct 30, 2018

@jvanbruegge in short, here I refactor the "drivers". In #995 we'll rethink the type language.

@gbaz
Copy link
Contributor

gbaz commented Oct 30, 2018

The key bit iirc is that this (very nice) refactor makes it straightforward to add adapter libs for hooking up to the usual streaming libs, and actually adds some such adapters as well.

@jvanbruegge
Copy link
Contributor

jvanbruegge commented Oct 30, 2018

ok, thanks. That was my intuition too, but i wanted to ask just in case I missed something

@domenkozar
Copy link
Contributor

Also makes https://github.com/plow-technologies/servant-streaming redundant (well, once streaming glue is there) :)

@phadej
Copy link
Contributor Author

phadej commented Oct 31, 2018

@domenkozar not entirely true. The servant-streaming could act as an adoption layer like servant-machines, servant-conduit etc. If one wants to use streaming lib.

@phadej phadej mentioned this pull request Nov 1, 2018
1 task
Copy link
Contributor

@alpmestan alpmestan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave some feedback on the tutorial/docs, but aside from that LGTM.

@@ -129,16 +129,23 @@ type UserAPI4 = "users" :> Get '[JSON] [User]

### `StreamGet` and `StreamPost`

*Note*: Streaming have changed considerably in `servant-0.15`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has changed

type ServerStreamAPI = StreamAPI StreamGenerator
type ClientStreamAPI = StreamAPI ResultStream
```
Note that we use the same `SourceIO` type (this is different from `servant-0.14`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... the same SourceIO type as on the server-side (...)

posStream = client streamAPI
```

And here's how to just print out all elements from a `ResultStream`, to give some idea of how to work with them.
We'll get back a `Codensity IO (SourceIO Position)`. The wrapping in
`Codensity` is generally necessary, as `Codensity` let's us to `bracket` things
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets, and remove "to"

This simple application returns a stream of `User` values encoded in JSON
format, with each value separated by a newline. In this case, the stream will
consist of the value of `isaac`, followed by the value of `albert`, then the
value of `albert` a third time. Importantly, the stream is written back as
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a second time

- Introduce SourceT, which is simple variant of "correct `ListT`".
  There are another variants possible (like in `streaming`),
  but I'm not sure there's much real difference.

- Introduce `Codensity`. There's a flag if people don't want to depend
  on `kan-extensions`.

- `StreamGenerator` and `ResultStream` are both `SourceT`.
  `Stream` combinator in `servant-client` uses `Codensity` for CPS.

- Add servant-machines, servant-conduit, servant-pipes
- Add streaming cookbook: just code, no explanations.
- Add a script to run streaming 'benchmarks'
@phadej phadej merged commit e94919f into haskell-servant:master Nov 5, 2018
@phadej phadej deleted the servant-machines branch November 5, 2018 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants