Total Bandwidth Usage
时间: 2024-01-09 15:04:45 浏览: 127
Total Bandwidth Usage是指在一定时间内系统中所有网络连接所使用的总带宽。这个指标通常用于衡量一个系统的网络负载和网络性能。高的Total Bandwidth Usage可能意味着系统中有大量的数据传输,可能会影响到系统的响应时间和性能。因此,对于高流量的系统,需要考虑处理大量的网络流量,如使用高带宽的网络链接、使用负载均衡和缓存等技术来优化系统的性能和响应时间。
相关问题
def draw_stats(self, vals, vals1, vals2, vals3, vals4, vals5, vals6): self.ax1 = plt.subplot(self.gs[0, 0]) self.ax1.plot(vals) self.ax1.set_xlim(self.xlim) locs = self.ax1.get_xticks() locs[0] = self.xlim[0] locs[-1] = self.xlim[1] self.ax1.set_xticks(locs) self.ax1.use_sticky_edges = False self.ax1.set_title(f'Connected Clients Ratio') self.ax2 = plt.subplot(self.gs[1, 0]) self.ax2.plot(vals1) self.ax2.set_xlim(self.xlim) self.ax2.set_xticks(locs) self.ax2.yaxis.set_major_formatter(FuncFormatter(format_bps)) self.ax2.use_sticky_edges = False self.ax2.set_title('Total Bandwidth Usage') self.ax3 = plt.subplot(self.gs[2, 0]) self.ax3.plot(vals2) self.ax3.set_xlim(self.xlim) self.ax3.set_xticks(locs) self.ax3.use_sticky_edges = False self.ax3.set_title('Bandwidth Usage Ratio in Slices (Averaged)') self.ax4 = plt.subplot(self.gs[3, 0]) self.ax4.plot(vals3) self.ax4.set_xlim(self.xlim) self.ax4.set_xticks(locs) self.ax4.use_sticky_edges = False self.ax4.set_title('Client Count Ratio per Slice') self.ax5 = plt.subplot(self.gs[0, 1]) self.ax5.plot(vals4) self.ax5.set_xlim(self.xlim) self.ax5.set_xticks(locs) self.ax5.use_sticky_edges = False self.ax5.set_title('Coverage Ratio') self.ax6 = plt.subplot(self.gs[1, 1]) self.ax6.plot(vals5) self.ax6.set_xlim(self.xlim) self.ax6.set_xticks(locs) self.ax6.yaxis.set_major_formatter(FormatStrFormatter('%.3f')) self.ax6.use_sticky_edges = False self.ax6.set_title('Block ratio') self.ax7 = plt.subplot(self.gs[2, 1]) self.ax7.plot(vals6) self.ax7.set_xlim(self.xlim) self.ax7.set_xticks(locs) self.ax7.yaxis.set_major_formatter(FormatStrFormatter('%.3f')) self.ax7.use_sticky_edges = False self.ax7.set_title('Handover ratio')修改为一张张输出图片
好的,你可以将这段代码修改为:
```python
def draw_stats(self, vals, vals1, vals2, vals3, vals4, vals5, vals6, save_path):
fig, axs = plt.subplots(4, 2, figsize=(16, 16))
axs[0, 0].plot(vals)
axs[0, 0].set_xlim(self.xlim)
locs = axs[0, 0].get_xticks()
locs[0] = self.xlim[0]
locs[-1] = self.xlim[1]
axs[0, 0].set_xticks(locs)
axs[0, 0].use_sticky_edges = False
axs[0, 0].set_title(f'Connected Clients Ratio')
axs[1, 0].plot(vals1)
axs[1, 0].set_xlim(self.xlim)
axs[1, 0].set_xticks(locs)
axs[1, 0].yaxis.set_major_formatter(FuncFormatter(format_bps))
axs[1, 0].use_sticky_edges = False
axs[1, 0].set_title('Total Bandwidth Usage')
axs[2, 0].plot(vals2)
axs[2, 0].set_xlim(self.xlim)
axs[2, 0].set_xticks(locs)
axs[2, 0].use_sticky_edges = False
axs[2, 0].set_title('Bandwidth Usage Ratio in Slices (Averaged)')
axs[3, 0].plot(vals3)
axs[3, 0].set_xlim(self.xlim)
axs[3, 0].set_xticks(locs)
axs[3, 0].use_sticky_edges = False
axs[3, 0].set_title('Client Count Ratio per Slice')
axs[0, 1].plot(vals4)
axs[0, 1].set_xlim(self.xlim)
axs[0, 1].set_xticks(locs)
axs[0, 1].use_sticky_edges = False
axs[0, 1].set_title('Coverage Ratio')
axs[1, 1].plot(vals5)
axs[1, 1].set_xlim(self.xlim)
axs[1, 1].set_xticks(locs)
axs[1, 1].yaxis.set_major_formatter(FormatStrFormatter('%.3f'))
axs[1, 1].use_sticky_edges = False
axs[1, 1].set_title('Block ratio')
axs[2, 1].plot(vals6)
axs[2, 1].set_xlim(self.xlim)
axs[2, 1].set_xticks(locs)
axs[2, 1].yaxis.set_major_formatter(FormatStrFormatter('%.3f'))
axs[2, 1].use_sticky_edges = False
axs[2, 1].set_title('Handover ratio')
plt.tight_layout()
plt.savefig(save_path)
plt.show()
```
这样就可以一张张输出图片了,你只需要传入一个保存路径参数 `save_path` 即可。
def connect(self): s = self.get_slice() if self.connected: return # increment connect attempt self.stat_collector.incr_connect_attempt(self) if s.is_avaliable(): s.connected_users += 1 self.connected = True print(f'[{int(self.env.now)}] Client_{self.pk} [{self.x}, {self.y}] connected to slice={self.get_slice()} @ {self.base_station}') return True else: self.assign_closest_base_station(exclude=[self.base_station.pk]) if self.base_station is not None and self.get_slice().is_avaliable(): # handover self.stat_collector.incr_handover_count(self) elif self.base_station is not None: # block self.stat_collector.incr_block_count(self) else: pass # uncovered print(f'[{int(self.env.now)}] Client_{self.pk} [{self.x}, {self.y}] connection refused to slice={self.get_slice()} @ {self.base_station}') return False def disconnect(self): if self.connected == False: print(f'[{int(self.env.now)}] Client_{self.pk} [{self.x}, {self.y}] is already disconnected from slice={self.get_slice()} @ {self.base_station}') else: slice = self.get_slice() slice.connected_users -= 1 self.connected = False print(f'[{int(self.env.now)}] Client_{self.pk} [{self.x}, {self.y}] disconnected from slice={self.get_slice()} @ {self.base_station}') return not self.connected def start_consume(self): s = self.get_slice() amount = min(s.get_consumable_share(), self.usage_remaining) # Allocate resource and consume ongoing usage with given bandwidth s.capacity.get(amount) print(f'[{int(self.env.now)}] Client_{self.pk} [{self.x}, {self.y}] gets {amount} usage.') self.last_usage = amount def release_consume(self): s = self.get_slice() # Put the resource back if self.last_usage > 0: # note: s.capacity.put cannot take 0 s.capacity.put(self.last_usage) print(f'[{int(self.env.now)}] Client_{self.pk} [{self.x}, {self.y}] puts back {self.last_usage} usage.') self.total_consume_time += 1 self.total_usage += self.last_usage self.usage_remaining -= self.last_usage self.last_usage = 0中的资源分配
要将这些函数修改为最小容量的资源分配,需要进行以下更改:
1. 在 `is_avaliable` 函数中,将 `bandwidth_next` 的计算方式修改为 `real_cap / (self.connected_users + 1) >= self.bandwidth_min`,即下一个用户的带宽大于等于最小容量。
2. 在 `start_consume` 函数中,将 `amount` 的计算方式修改为 `min(s.get_consumable_share(), self.usage_remaining, self.bandwidth_min)`,即需要分配的资源量为可用资源、剩余需求和最小容量的最小值。
修改后的代码如下:
```
def connect(self):
s = self.get_slice()
if self.connected:
return
# increment connect attempt
self.stat_collector.incr_connect_attempt(self)
if s.is_avaliable():
s.connected_users += 1
self.connected = True
print(f"[{int(self.env.now)}] Client_{self.pk} [{self.x}, {self.y}] connected to slice={self.get_slice()} @ {self.base_station}")
return True
else:
self.assign_closest_base_station(exclude=[self.base_station.pk])
if self.base_station is not None and self.get_slice().is_avaliable():
# handover
self.stat_collector.incr_handover_count(self)
elif self.base_station is not None:
# block
self.stat_collector.incr_block_count(self)
else:
pass # uncovered
print(f"[{int(self.env.now)}] Client_{self.pk} [{self.x}, {self.y}] connection refused to slice={self.get_slice()} @ {self.base_station}")
return False
def disconnect(self):
if not self.connected:
print(f"[{int(self.env.now)}] Client_{self.pk} [{self.x}, {self.y}] is already disconnected from slice={self.get_slice()} @ {self.base_station}")
else:
slice = self.get_slice()
slice.connected_users -= 1
self.connected = False
print(f"[{int(self.env.now)}] Client_{self.pk} [{self.x}, {self.y}] disconnected from slice={self.get_slice()} @ {self.base_station}")
return not self.connected
def start_consume(self):
s = self.get_slice()
amount = min(s.get_consumable_share(), self.usage_remaining, self.bandwidth_min)
s.capacity.get(amount)
print(f"[{int(self.env.now)}] Client_{self.pk} [{self.x}, {self.y}] gets {amount} usage.")
self.last_usage = amount
def release_consume(self):
s = self.get_slice()
if self.last_usage > 0:
s.capacity.put(self.last_usage)
print(f"[{int(self.env.now)}] Client_{self.pk} [{self.x}, {self.y}] puts back {self.last_usage} usage.")
self.total_consume_time += 1
self.total_usage += self.last_usage
self.usage_remaining -= self.last_usage
self.last_usage = 0
def is_avaliable(self):
real_cap = min(self.init_capacity, self.bandwidth_max)
return real_cap / (self.connected_users + 1) >= self.bandwidth_min
```
阅读全文