Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Oops, forgotten files
[simgrid.git] / teshsuite / s4u / io-set-bw / io-set-bw.cpp
1 /* Copyright (c) 2017-2021. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <simgrid/s4u.hpp>
7
8 namespace sg4 = simgrid::s4u;
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(io_set_bw, "Messages specific for this simulation");
11
12 static void io(const sg4::Disk* disk)
13 {
14   double cur_time = sg4::Engine::get_clock();
15   disk->read(1e6);
16   XBT_INFO("Read finished. Took: %lf", sg4::Engine::get_clock() - cur_time);
17   cur_time = sg4::Engine::get_clock();
18   disk->write(1e6);
19   XBT_INFO("Write finished. Took: %lf", sg4::Engine::get_clock() - cur_time);
20 }
21
22 static void host()
23 {
24   auto* disk = sg4::Host::current()->get_disks()[0];
25   XBT_INFO("I/O operations: size 1e6. Should take 1s each");
26   io(disk);
27
28   XBT_INFO("Setting read limit to half (.5e6). Read should take 2s, write still 1s");
29   disk->set_read_bandwidth(.5e6);
30   io(disk);
31
32   XBT_INFO("Setting write limit to half (.5e6). Write should take 2s, read still 1s");
33   disk->set_read_bandwidth(1e6);
34   disk->set_write_bandwidth(.5e6);
35   io(disk);
36
37   XBT_INFO("Setting readwrite limit to half (.5e6). Write and read should take 2s now");
38   disk->set_readwrite_bandwidth(.5e6);
39   disk->set_write_bandwidth(1e6);
40   io(disk);
41
42   disk->set_readwrite_bandwidth(1e6);
43   sg4::IoPtr act;
44   double cur_time;
45   XBT_INFO("Change bandwidth in the middle of I/O operation");
46   XBT_INFO("Setting read limit to half (.5e6) in the middle of IO. Read should take 1.5s");
47   cur_time = sg4::Engine::get_clock();
48   act      = disk->read_async(1e6);
49   sg4::this_actor::sleep_for(.5);
50   disk->set_read_bandwidth(.5e6);
51   act->wait();
52   XBT_INFO("Read finished. Took: %lf", sg4::Engine::get_clock() - cur_time);
53   disk->set_read_bandwidth(1e6);
54
55   XBT_INFO("Setting write limit to half (.5e6) in the middle of IO. Write should take 1.5s");
56   cur_time = sg4::Engine::get_clock();
57   act      = disk->write_async(1e6);
58   sg4::this_actor::sleep_for(.5);
59   disk->set_write_bandwidth(.5e6);
60   act->wait();
61   XBT_INFO("Write finished. Took: %lf", sg4::Engine::get_clock() - cur_time);
62   disk->set_write_bandwidth(1e6);
63
64   XBT_INFO("Setting readwrite limit to half (.5e6) in the middle of IO. Read and write should take 1.5s");
65   cur_time        = sg4::Engine::get_clock();
66   act             = disk->write_async(1e6 / 2);
67   sg4::IoPtr act2 = disk->read_async(1e6 / 2);
68   sg4::this_actor::sleep_for(.5);
69   disk->set_readwrite_bandwidth(.5e6);
70   act->wait();
71   act2->wait();
72   XBT_INFO("Read and write finished. Took: %lf", sg4::Engine::get_clock() - cur_time);
73 }
74
75 /*************************************************************************************************/
76 int main(int argc, char** argv)
77 {
78   sg4::Engine e(&argc, argv);
79
80   /* simple platform containing 1 host and 2 disk */
81   auto* zone = sg4::create_full_zone("bob_zone");
82   auto* bob  = zone->create_host("bob", 1e6);
83   auto* disk = bob->create_disk("bob_disk", 1e3, 1e3);
84   /* manually setting before seal */
85   disk->set_read_bandwidth(1e6);
86   disk->set_write_bandwidth(1e6);
87   disk->set_readwrite_bandwidth(1e6);
88   zone->seal();
89
90   sg4::Actor::create("", bob, host);
91
92   e.run();
93
94   return 0;
95 }