dist_memcache.py 6.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Copyright 2021 Max Planck Institute for Software Systems, and
# National University of Singapore
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import math
import random
Jonas Kaufmann's avatar
Jonas Kaufmann committed
25

26
import simbricks.nodeconfig as node
Jonas Kaufmann's avatar
Jonas Kaufmann committed
27
import simbricks.simulators as sim
28
from simbricks.simulator_utils import create_multinic_hosts
29

Jonas Kaufmann's avatar
Jonas Kaufmann committed
30
import simbricks.experiments as exp
31
from simbricks import proxy
Jonas Kaufmann's avatar
Jonas Kaufmann committed
32

33
host_types = ['qemu', 'gem5', 'qt']
34
n_nets = [1, 2, 3, 4, 8, 16, 32]
35
n_hosts = [2, 10, 20, 30, 35, 40, 50, 60, 70, 80]
36
experiments = []
37
separate_net = True
38

39
nets_per_host = 1
40

Jonas Kaufmann's avatar
Jonas Kaufmann committed
41

42
43
# pylint: disable=redefined-outer-name
def select_servers(i, racks, n, n_host):
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
    nc = int(n_host / 2)

    if n == 1:
        # only one network, just connect to all servers
        return racks[i][0]

    all_other_servers = []
    for k in range(0, n):
        if k == i:
            continue
        all_other_servers += racks[k][0]

    n_local = math.ceil(nc / 2)
    n_remote = math.floor(nc / 2)

    servers_local = random.sample(racks[i][0], k=n_local)
    servers_other = random.sample(all_other_servers, k=n_remote)
    return servers_local + servers_other

Jonas Kaufmann's avatar
Jonas Kaufmann committed
63

64
for host_type in host_types:
Jonas Kaufmann's avatar
Jonas Kaufmann committed
65
66
67
68
69
    for n in n_nets:
        for n_host in n_hosts:
            random.seed(n + 1000 * n_host)

            nh = math.ceil(n / nets_per_host)
70
            if separate_net:
Jonas Kaufmann's avatar
Jonas Kaufmann committed
71
72
73
74
75
                nh += 1

            e = exp.DistributedExperiment(
                f'dist_memcache-{host_type}-{n}-{n_host}', nh
            )
76

Jonas Kaufmann's avatar
Jonas Kaufmann committed
77
78
            # host
            if host_type == 'qemu':
79
                HostClass = sim.QemuHost
Jonas Kaufmann's avatar
Jonas Kaufmann committed
80
81
82
83
84
85
86
            elif host_type == 'qt':

                def qemu_timing():
                    h = sim.QemuHost()
                    h.sync = True
                    return h

87
                HostClass = qemu_timing
Jonas Kaufmann's avatar
Jonas Kaufmann committed
88
            elif host_type == 'gem5':
89
                HostClass = sim.Gem5Host
Jonas Kaufmann's avatar
Jonas Kaufmann committed
90
91
92
93
94
95
                e.checkpoint = False
            else:
                raise NameError(host_type)

            switch_top = sim.SwitchNet()
            switch_top.name = 'switch_top'
96
            if host_type == 'qemu':
Jonas Kaufmann's avatar
Jonas Kaufmann committed
97
98
99
100
101
102
103
104
105
106
107
                switch_top.sync = False
            e.add_network(switch_top)
            e.assign_sim_host(switch_top, 0)

            racks = []
            for i in range(0, n):
                h_i = int(i / nets_per_host)
                if separate_net:
                    h_i += 1

                switch = sim.SwitchNet()
108
                switch.name = f'switch_{i}'
Jonas Kaufmann's avatar
Jonas Kaufmann committed
109
110
111
112
113
114
115
116
117
118
119
120
                if host_type == 'qemu':
                    switch.sync = False
                e.add_network(switch)
                e.assign_sim_host(switch, h_i)

                switch_top.connect_network(switch)

                # create servers and clients
                m = int(n_host / 2)
                servers = create_multinic_hosts(
                    e,
                    m,
121
                    f'server_{i}',
Jonas Kaufmann's avatar
Jonas Kaufmann committed
122
                    switch,
123
                    HostClass,
Jonas Kaufmann's avatar
Jonas Kaufmann committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
                    node.I40eLinuxNode,
                    node.MemcachedServer,
                    ip_start=i * n_host + 1,
                    ip_prefix=16
                )
                for s in servers:
                    e.assign_sim_host(s, h_i)
                    s_multisubnic = next(
                        pcidev for pcidev in s.pcidevs
                        if isinstance(pcidev, sim.MultiSubNIC)
                    )
                    e.assign_sim_host(s_multisubnic.multinic, h_i)

                clients = create_multinic_hosts(
                    e,
                    m,
140
                    f'client_{i}',
Jonas Kaufmann's avatar
Jonas Kaufmann committed
141
                    switch,
142
                    HostClass,
Jonas Kaufmann's avatar
Jonas Kaufmann committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
                    node.I40eLinuxNode,
                    node.MemcachedClient,
                    ip_start=i * n_host + 1 + m,
                    ip_prefix=16
                )
                for c in clients:
                    c.wait = True
                    e.assign_sim_host(c, h_i)
                    c_multisubnic = next(
                        pcidev for pcidev in c.pcidevs
                        if isinstance(pcidev, sim.MultiSubNIC)
                    )
                    e.assign_sim_host(c_multisubnic.multinic, h_i)

                racks.append((servers, clients))

                if h_i != 0:
                    lp = proxy.SocketsNetProxyListener()
161
                    lp.name = f'listener-{i}'
Jonas Kaufmann's avatar
Jonas Kaufmann committed
162
163
164
165
                    e.add_proxy(lp)
                    e.assign_sim_host(lp, h_i)

                    cp = proxy.SocketsNetProxyConnecter(lp)
166
                    cp.name = f'connecter-{i}'
Jonas Kaufmann's avatar
Jonas Kaufmann committed
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
                    e.add_proxy(cp)
                    e.assign_sim_host(cp, 0)

                    lp.add_n2n(switch_top, switch)

                for c in clients + servers:
                    if host_type == 'qt':
                        c.pcidevs[0].start_tick = 580000000000
                    c.extra_deps.append(switch_top)

            all_servers = []
            all_clients = []
            for (s, c) in racks:
                all_servers += s
                all_clients += c

            # set up client -> server connections
            for i in range(0, n):
                for j in range(0, int(n_host / 2)):
                    c = racks[i][1][j]
187
                    servers = select_servers(i, racks, n, n_host)
Jonas Kaufmann's avatar
Jonas Kaufmann committed
188
189
190
191
192
193
194
195
196
197
198
199
                    server_ips = [s.node_config.ip for s in servers]

                    c.node_config.app.server_ips = server_ips
                    c.node_config.app.threads = len(server_ips)
                    c.node_config.app.concurrency = len(server_ips)
                    c.extra_deps += all_servers

            for h in all_servers + all_clients:
                h.node_config.disk_image = 'memcached'

            # add to experiments
            experiments.append(e)