分层(Laying)

分层(Laying)是软件开发者用来将复杂的软件系统分解的最常用的方法。 

当你使用“层”(Lay)这个术语考虑一个系统时,你可以把软件中的主要子系统的组织方式想象为多层蛋糕,每一层都位于低层之上。在这个方案中,高层使用低层中定义的各种服务,但低层却意识不到高层的存在。更进一步地,每一层通常都会对其低层隐藏在其上的层,因此,层4使用层3提供的服务,而层3使用层2提供的服务,但是层4不知道层2的存在。

将系统分解为不同的层有很多益处:

  • 你可以将单独的一层理解为一个整体,而不用过多的了解其它层的细节。
  • 你可以用实现相同基本服务的替代品来替代这些层。
  • 你可以减少层之间的依赖性。
  • 层可以更好的实现标准化。
  • 一旦你创建了一层,你就可以在许多更高级的服务中使用它。

分层是一项很重要的技术,但是也有不足:

  • 层封装了部分功能,但并不能很好地封装所有功能。因此,你有时必须修改多个层。这个缺点的经典案例就是在一个分层的企业应用程序中加入一个需要在UI上显示的字段,则必须修改数据库,并且修改位于UI和数据库间的每一层。
  • 额外的层会影响性能。在每一层数据通常需要从一层传递到另一层。但是,对于某一功能的封装通常会给你带来更高的效率以弥补损失的性能。我们可以通过优化控制事务的层,而加快事务的处理。

分层架构最难的部分是决定应该拥有哪些层和这些层的职责。

 

 

io-3.35 Starting 8 processes randread: Laying out IO file (1 file / 10240MiB) randread: Laying out IO file (1 file / 10240MiB) randread: Laying out IO file (1 file / 10240MiB) fio: ENOSPC on laying out file, stopping fio: pid=0, err=28/file:filesetup.c:240, func=write, error=No space left on device randread: Laying out IO file (1 file / 10240MiB) fio: pid=0, err=28/file:filesetup.c:174, func=open, error=No space left on device randwrite: Laying out IO file (1 file / 10240MiB) fio: pid=0, err=28/file:filesetup.c:174, func=open, error=No space left on device randwrite: Laying out IO file (1 file / 10240MiB) fio: pid=0, err=28/file:filesetup.c:174, func=open, error=No space left on device randwrite: Laying out IO file (1 file / 10240MiB) fio: pid=0, err=28/file:filesetup.c:174, func=open, error=No space left on device randwrite: Laying out IO file (1 file / 10240MiB) fio: pid=0, err=28/file:filesetup.c:174, func=open, error=No space left on device Jobs: 2 (f=2): [r(2),X(6)][100.0%][r=279KiB/s][r=69 IOPS][eta 00m:00s] randread: (groupid=0, jobs=1): err= 0: pid=4012: Wed Jul 16 22:21:23 2025 read: IOPS=36, BW=144KiB/s (148kB/s)(8668KiB/60032msec) slat (nsec): min=1960, max=423031k, avg=27609589.07, stdev=25336672.45 clat (msec): min=9, max=8015, avg=411.63, stdev=396.00 lat (msec): min=35, max=8015, avg=439.24, stdev=395.86 clat percentiles (msec): | 1.00th=[ 89], 5.00th=[ 262], 10.00th=[ 288], 20.00th=[ 309], | 30.00th=[ 330], 40.00th=[ 347], 50.00th=[ 359], 60.00th=[ 380], | 70.00th=[ 418], 80.00th=[ 468], 90.00th=[ 535], 95.00th=[ 625], | 99.00th=[ 768], 99.50th=[ 1921], 99.90th=[ 7684], 99.95th=[ 7752], | 99.99th=[ 8020] bw ( KiB/s): min= 24, max= 211, per=49.95%, avg=144.88, stdev=31.58, samples=114 iops : min= 6, max= 52, avg=35.96, stdev= 7.92, samples=114 lat (msec) : 10=0.05%, 20=0.14%, 50=0.37%, 100=0.65%, 250=2.86% lat (msec) : 500=81.50%, 750=13.15%, 1000=0.60%, 2000=0.23%, >=2000=0.46% cpu : usr=0.32%, sys=99.26%, ctx=735, majf=0, minf=26 IO depths : 1=0.1%, 2=0.1%, 4=0.2%, 8=0.4%, 16=99.3%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.1%, 32=0.0%, 64=0.0%, >=64=0.0% issued rwts: total=2167,0,0,0 short=0,0,0,0 dropped=0,0,0,0 latency : target=0, window=0, percentile=100.00%, depth=16 randread: (groupid=0, jobs=1): err= 0: pid=4013: Wed Jul 16 22:21:23 2025 read: IOPS=36, BW=144KiB/s (148kB/s)(8680KiB/60180msec) slat (nsec): min=1979, max=438546k, avg=27562216.01, stdev=25336850.71 clat (msec): min=6, max=8611, avg=411.96, stdev=584.57 lat (msec): min=33, max=8632, avg=439.52, stdev=583.69 clat percentiles (msec): | 1.00th=[ 128], 5.00th=[ 236], 10.00th=[ 257], 20.00th=[ 284], | 30.00th=[ 305], 40.00th=[ 321], 50.00th=[ 342], 60.00th=[ 368], | 70.00th=[ 393], 80.00th=[ 435], 90.00th=[ 502], 95.00th=[ 575], | 99.00th=[ 1636], 99.50th=[ 7013], 99.90th=[ 8423], 99.95th=[ 8490], | 99.99th=[ 8658] bw ( KiB/s): min= 32, max= 247, per=49.95%, avg=144.90, stdev=32.09, samples=115 iops : min= 8, max= 61, avg=36.01, stdev= 8.06, samples=115 lat (msec) : 10=0.09%, 20=0.05%, 50=0.37%, 100=0.28%, 250=7.00% lat (msec) : 500=81.94%, 750=8.39%, 1000=0.74%, 2000=0.32%, >=2000=0.83% cpu : usr=0.36%, sys=98.93%, ctx=813, majf=0, minf=27 IO depths : 1=0.1%, 2=0.1%, 4=0.2%, 8=0.4%, 16=99.3%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.1%, 32=0.0%, 64=0.0%, >=64=0.0% issued rwts: total=2170,0,0,0 short=0,0,0,0 dropped=0,0,0,0 latency : target=0, window=0, percentile=100.00%, depth=16 Run status group 0 (all jobs): READ: bw=288KiB/s (295kB/s), 144KiB/s-144KiB/s (148kB/s-148kB/s), io=16.9MiB (17.8MB), run=60032-60180msec Disk stats (read/write): dm-0: ios=4336/6, merge=0/0, ticks=469085/1169, in_queue=470254, util=100.00%, aggrios=4337/5, aggrmerge=0/1, aggrticks=477332/1114, aggrin_queue=478446, aggrutil=79.54% sda: ios=4337/5, merge=0/1, ticks=477332/1114, in_queue=478446, util=79.54%
07-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值