Skip to content
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

added some more fakeps implementations #29

Merged
merged 2 commits into from
Mar 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/test/scala/fakeps/Benchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ object Benchmark extends Bench.LocalTime {
}
}

// measureMethod(fakePsFoldSlow, "fakePsFoldSlow")
measureMethod(fakePsFoldSlow, "fakePsFoldSlow")
measureMethod(fakePsFold, "fakePsFold")
measureMethod(fakePsArrayImmutable, "fakePsArrayImmutable")
measureMethod(fakePsMutable, "fakePsMutable")
measureMethod(fakePsArray, "fakePsArray")
measureMethod(fakePsMapReduce, "fakePsMapReduce")
measureMethod(fakePsMapReducePar, "fakePsMapReducePar")
measureMethod(fakePsArrayPar, "fakePsArrayPar")
measureMethod(fakePsArrayTrie, "fakePsArrayTrie")
measureMethod(fakePsArraySTM, "fakePsArraySTM")
measureMethod(fakePsSimpleFast, "fakePsSimpleFast")
}
3 changes: 3 additions & 0 deletions src/test/scala/fakeps/Spec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class Spec extends FunSuite {
testFakePs(fakePsArrayImmutable, "fakePsArrayImmutable")
testFakePs(fakePsMutable, "fakePsMutable")
testFakePs(fakePsArray, "fakePsArray")
testFakePs(fakePsMapReduce, "fakePsMapReduce")
testFakePs(fakePsMapReducePar, "fakePsMapReducePar")
testFakePs(fakePsArrayPar, "fakePsArrayPar")
testFakePs(fakePsArrayTrie, "fakePsArrayTrie")
testFakePs(fakePsArraySTM, "fakePsArraySTM")
testFakePs(fakePsSimpleFast, "fakePsSimpleFast")
}
36 changes: 34 additions & 2 deletions src/test/scala/fakeps/fakeps.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.luc.etl.osdi.processtree.scala

import scala.collection.mutable.ArrayBuffer
import scala.collection.GenIterable
import scala.util.Random
import common.Process

Expand Down Expand Up @@ -82,6 +83,28 @@ package object fakeps {
for (ppid <- ps.indices.iterator ; pid <- ps(ppid).iterator) yield (pid, ppid)
}

/**
* Generates a barebones process tree (ppid -> pid*) of size n
* using map-reduce over sequential collections.
*/
def fakePsMapReduce(n: Int): Iterator[(Int, Int)] = {
require { n > 0 }
val ps1 = (2 to n) map { nextPid => (1 + Random.nextInt(nextPid - 1), nextPid) }
val ps2 = (Seq((0, 1)) ++ ps1) groupBy { _._1 }
for (ppid <- ps2.keys.iterator ; (_, pid) <- ps2(ppid).iterator) yield (pid, ppid)
}

/**
* Generates a barebones process tree (ppid -> pid*) of size n
* using map-reduce over parallel collections.
*/
def fakePsMapReducePar(n: Int): Iterator[(Int, Int)] = {
require { n > 0 }
val ps1 = (2 to n).par map { nextPid => (1 + Random.nextInt(nextPid - 1), nextPid) }
val ps2 = (Seq((0, 1)).par ++ ps1) groupBy { _._1 }
for (ppid <- ps2.keys.iterator ; (_, pid) <- ps2(ppid).iterator) yield (pid, ppid)
}

/**
* Generates a barebones process tree (ppid -> pid*) of size n
* using a preallocated immutable vector of with a parallel range and
Expand Down Expand Up @@ -134,8 +157,17 @@ package object fakeps {
for (ppid <- ps.indices.iterator ; pid <- ps(ppid).single.iterator) yield (pid, ppid)
}

/**
* Simply enumerates the child-parent edges of a barebones process tree (ppid -> pid*)
* of size n. This should work in constant space.
*/
def fakePsSimpleFast(n: Int): Iterator[(Int, Int)] = {
require { n > 0 }
Iterator(1 -> 0) ++ ((2 to n).toIterator map { cpid => cpid -> (1 + Random.nextInt(cpid - 1)) })
}

/** Converts a tree (ppid -> pid*) into an iterator of pid -> ppid edges. */
def reverseEdges(m: Map[Int, Iterable[Int]]): Iterator[(Int, Int)] =
def reverseEdges(m: Map[Int, GenIterable[Int]]): Iterator[(Int, Int)] =
for (ppid <- m.keys.iterator ; pid <- m(ppid).iterator) yield (pid, ppid)

/** Adds a command string to each pid -> ppid edge. */
Expand All @@ -146,5 +178,5 @@ package object fakeps {
def addCmd(i: Iterator[(Int, Int)]): Iterator[Process] = addCmd(i, "Fake Process")

/** Generates the fake ps command output. */
def fakePs(n: Int) = addCmd(fakePsArrayImmutable(n))
def fakePs(n: Int) = addCmd(fakePsMapReduce(n))
}