1 /******************************************************************************* 2 3 Test project doing emulating scheduler based application different kind of 4 concurrent task processing. Most useful when doing manual debugging with 5 `-debug=TaskScheduler` trace enabled, as there won't be any extra noise from 6 imported unittests. 7 8 Copyright: 9 Copyright (c) 2017 dunnhumby Germany GmbH. 10 All rights reserved. 11 12 License: 13 Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. 14 Alternatively, this file may be distributed under the terms of the Tango 15 3-Clause BSD License (see LICENSE_BSD.txt for details). 16 17 *******************************************************************************/ 18 19 module integrationtest.scheduler.main; 20 21 import ocean.task.Scheduler; 22 import ocean.task.Task; 23 import ocean.task.TaskPool; 24 import ocean.task.util.Timer; 25 26 import ocean.meta.types.Qualifiers; 27 import ocean.core.Test; 28 import ocean.io.Stdout; 29 30 import core.stdc.stdlib; 31 32 /// Entry point task that starts up everything else 33 class MainTask : Task 34 { 35 GeneratorTask[] generators; 36 TaskPool!(RegularTask) pool; 37 38 this ( ) 39 { 40 this.pool = new typeof(this.pool); 41 42 for (int i = 0; i < 5; ++i) 43 { 44 this.generators ~= new GeneratorTask; 45 this.generators[$-1].root = this; 46 } 47 } 48 49 override public void run ( ) 50 { 51 foreach (task; this.generators) 52 theScheduler.schedule(task); 53 } 54 } 55 56 /// Task emulating some sort of priority / real-time computation 57 /// that must not ever wait in queue, but is known to have predictable 58 /// max concurrency factor. Spawns `RegularTask` as part of its work. 59 class GeneratorTask : Task 60 { 61 MainTask root; 62 63 override public void run ( ) 64 { 65 for (int i = 0; i < 5; ++i) 66 this.root.pool.start(); 67 } 68 } 69 70 /// Task doing some prolonged I/O wait after being queued 71 class RegularTask : Task 72 { 73 static long completed_count; 74 75 override public void run ( ) 76 { 77 .wait(100_000); 78 ++RegularTask.completed_count; 79 } 80 81 void copyArguments ( ) { } 82 } 83 84 version (unittest) {} else 85 void main ( ) 86 { 87 SchedulerConfiguration config; 88 89 with (config) 90 { 91 worker_fiber_stack_size = 102400; 92 worker_fiber_limit = 10; 93 task_queue_limit = 100; 94 95 specialized_pools = [ 96 PoolDescription(GeneratorTask.classinfo.name, 204800) 97 ]; 98 } 99 100 initScheduler(config); 101 102 theScheduler.exception_handler = ( Task t, Exception e ) 103 { 104 Stderr.formatln("{} [{}:{}] {}", e.classinfo.name, 105 e.file, e.line, e.message()); 106 abort(); 107 }; 108 109 theScheduler.schedule(new MainTask); 110 theScheduler.eventLoop(); 111 112 test!("==")(RegularTask.completed_count, 25); 113 }