def stoppable_multi():
    hc = ecto.hardware_concurrency()
    def makeplasm():
        plasm = ecto.Plasm()
        ping = ecto_test.Ping("Ping")
        sleeps = [ecto_test.Sleep("Sleep_0", seconds=1.0/hc)
                  for x in range(hc)]
        plasm.connect(ping[:] >> sleeps[0][:])
        for i in range(1,hc-1):
            print "i=", i
            plasm.connect(sleeps[i][:] >> sleeps[i+1][:])
        return plasm

    p = makeplasm()

    st = ecto.schedulers.Multithreaded(p)
    st.execute_async()
    time.sleep(1.3) # wait until we are in steady state
    start = time.time()
    st.stop()
    st.wait()
    elapsed = time.time() - start
    print "elapsed multithreaded:", elapsed
    # we'll be partially through an iteration that has just started
    print "hc=", hc, "(hc-1.0)/hc=", ((hc-1.0)/hc)
    assert elapsed >= (hc-1.0)/hc
    assert elapsed <= (1.0 + eps)
    st.execute_async()
    time.sleep(1.0)
    # this time the start is just before stop is called, not
    # when execute was called
    start = time.time()
    st.stop()
    st.wait()
    elapsed = time.time() - start
    mintime =  (hc-1.0)/hc
    maxtime = 1.0 + (1.0/hc)
    print "elapsed multithreade:", elapsed, "expected min:", mintime, \
          "expected max:", maxtime
    assert elapsed >= mintime
    assert elapsed <= maxtime
Beispiel #2
0
def stoppable_multi():
    hc = ecto.hardware_concurrency()
    def makeplasm():
        plasm = ecto.Plasm()
        ping = ecto_test.Ping("Ping")
        sleeps = [ecto_test.Sleep("Sleep_0", seconds=1.0/hc)
                  for x in range(hc)]
        plasm.connect(ping[:] >> sleeps[0][:])
        for i in range(1,hc-1):
            print "i=", i
            plasm.connect(sleeps[i][:] >> sleeps[i+1][:])
        return plasm

    p = makeplasm()

    st = ecto.schedulers.Multithreaded(p)
    st.execute_async()
    time.sleep(1.3) # wait until we are in steady state
    start = time.time()
    st.stop()
    st.wait()
    elapsed = time.time() - start
    print "elapsed multithreaded:", elapsed
    # we'll be partially through an iteration that has just started
    print "hc=", hc, "(hc-1.0)/hc=", ((hc-1.0)/hc)
    assert elapsed >= (hc-1.0)/hc
    assert elapsed <= (1.0 + eps)
    st.execute_async()
    time.sleep(1.0)
    # this time the start is just before stop is called, not
    # when execute was called
    start = time.time()
    st.stop()
    st.wait()
    elapsed = time.time() - start
    mintime =  (hc-1.0)/hc
    maxtime = 1.0 + (1.0/hc)
    print "elapsed multithreade:", elapsed, "expected min:", mintime, \
          "expected max:", maxtime
    assert elapsed >= mintime
    assert elapsed <= maxtime
Beispiel #3
0
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
import ecto
import ecto.ecto_test as ecto_test
from util import fail
import sys, time

print "Hardware concurrency is", ecto.hardware_concurrency()

eps = 0.1

def makeplasm():
    plasm = ecto.Plasm()

    ping = ecto_test.Ping("Ping")
    startstop = ecto_test.StartStopCounter()

    plasm.connect(ping[:] >> startstop[:])

    return (plasm, startstop)

def do_test(fn):
    def impl(Sched):
Beispiel #4
0
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
import ecto
import ecto.ecto_test as ecto_test
from util import fail
import sys, time

print "Hardware concurrency is", ecto.hardware_concurrency()

eps = 0.1


def makeplasm():
    plasm = ecto.Plasm()

    ping = ecto_test.Ping("Ping")
    startstop = ecto_test.StartStopCounter()

    plasm.connect(ping[:] >> startstop[:])

    return (plasm, startstop)