4zhvml8 发表于 2024-8-30 23:35:22

互联网中不可缺失的网络优化:“App与Server的交互依赖于网络”


    <h1 style="color: black; text-align: left; margin-bottom: 10px;">前言</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">互联网时代, App<span style="color: black;">做为</span>于用户交互的端, <span style="color: black;">能够</span>说<span style="color: black;">实质</span>上是一个界面, <span style="color: black;">制品</span>的业务, 服务都<span style="color: black;">是由于</span>Server<span style="color: black;">供给</span>的. 而App与Server的交互依赖于网络, 故而网络优化, <span style="color: black;">亦</span>是<span style="color: black;">咱们</span>的App优化中不可缺少的一个优化项</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">1、网络连接对用户的影响</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">App的网络连接<span style="color: black;">针对</span>用户<span style="color: black;">来讲</span>, 影响<span style="color: black;">非常多</span>, 且<span style="color: black;">都数</span><span style="color: black;">状况</span>下都很直观, 直接影响用户对这个App的<span style="color: black;">运用</span>体验. 其中较为重要的几点:</span></p><span style="color: black;">流量 App的流量消耗对用户<span style="color: black;">来讲</span>是比较<span style="color: black;">敏锐</span>的, 毕竟流量是花钱的<span style="color: black;">吗</span>. <span style="color: black;">此刻</span>大部分人的手机上都有安装流量监控的工具App, 用来监控App的流量<span style="color: black;">运用</span>. <span style="color: black;">倘若</span><span style="color: black;">咱们</span>的App这方面<span style="color: black;">无</span><span style="color: black;">掌控</span>好, 会给用户<span style="color: black;">欠好</span>的<span style="color: black;">运用</span>体验.</span><span style="color: black;">电量 电量相<span style="color: black;">针对</span>用户来说, <span style="color: black;">无</span><span style="color: black;">那样</span><span style="color: black;">显著</span>. <span style="color: black;">通常</span>用户可能不会太<span style="color: black;">重视</span>. <span style="color: black;">然则</span>如前文电量优化中说的那样, 网络连接(radio)是对电量影响很大的一个<span style="color: black;">原因</span>. <span style="color: black;">因此</span><span style="color: black;">咱们</span><span style="color: black;">亦</span>要加以<span style="color: black;">重视</span>.</span><span style="color: black;">用户等待 <span style="color: black;">亦</span><span style="color: black;">便是</span>用户体验, 良好的用户体验, 才是<span style="color: black;">咱们</span>留住用户的<span style="color: black;">第1</span>步. <span style="color: black;">倘若</span>App请求等待时间长, 会给用户网络卡, 应用反应慢的感觉, <span style="color: black;">倘若</span>有对比, 有替代品, <span style="color: black;">咱们</span>的App很可能就会被用户无情抛弃.</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">2、分析网络连接的工具</h1>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">2.1 Network Monitor</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Android Studio内置的Monitor工具中就有一个Network Monitor:</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/8bdd5579827a4b4b9b63483002657e15~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1725618506&amp;x-signature=O9jxw6D5VVxNU6guZ14mrvobWdY%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">其中:</span></p><span style="color: black;">Rx — R(ecive) <span style="color: black;">暗示</span>下行流量, 即下载接收.</span><span style="color: black;">Tx — T(ransmit) <span style="color: black;">暗示</span>上行流量, 即上传发送.</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">2.2 网络代理工具</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">通常</span><span style="color: black;">来讲</span>, 网络代理工<span style="color: black;">拥有</span>两个<span style="color: black;">功效</span>:</span></p><span style="color: black;">截获网络请求响应包, 分析网络请求</span><span style="color: black;">设置代理网络, 移动App<span style="color: black;">研发</span>中<span style="color: black;">通常</span>用来做<span style="color: black;">区别</span>网络环境的测试, 例如Wifi/4G/3G/弱网等.</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">代理工具<span style="color: black;">非常多</span>, 诸如Wireshark, Fiddler, Charles等, <span style="color: black;">这里</span>不一一细说了</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">3, <span style="color: black;">那些</span>方面取优化网络连接</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">简单<span style="color: black;">来讲</span>, 两个方面:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">减少Radio活跃时间</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1-1. <span style="color: black;">亦</span><span style="color: black;">便是</span>减少网络数据获取的频次. 1-2. 这就减少了radio的电量消耗, <span style="color: black;">掌控</span>电量<span style="color: black;">运用</span>.</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">减少获取数据包的<span style="color: black;">体积</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2-1. <span style="color: black;">能够</span>减少流量消耗 2-2. <span style="color: black;">亦</span><span style="color: black;">能够</span>让每次请求更快, 在网络<span style="color: black;">状况</span><span style="color: black;">欠好</span>的<span style="color: black;">状况</span>下<span style="color: black;">亦</span>有良好表现, <span style="color: black;">提高</span>用户体验.</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">那样</span>, <span style="color: black;">详细</span>应该从<span style="color: black;">那些</span>方面着手呢?</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">3.1 接口设计</h1>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">API设计</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">App与Server之间的API设计要<span style="color: black;">思虑</span>网络请求的频次, 资源的状态等. 以便App<span style="color: black;">能够</span>以较少的请求来完成业务<span style="color: black;">需要</span>和界面的展示.</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">例如, 注册登录. 正常会有两个API, 注册和登录, <span style="color: black;">然则</span>设计API时<span style="color: black;">咱们</span>应该给注册接口<span style="color: black;">包括</span>一个隐式的登录. 来避免App在注册后还得请求一次登录接口(有可能失败, 从而<span style="color: black;">引起</span>业务流程失败).</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">再例如, 上文<span style="color: black;">说到</span>的获取repo详情, <span style="color: black;">实质</span>上请求了4个接口, 请求了repo的信息, forks列表, contributors列表, readme, 这是<span style="color: black;">由于</span>github<span style="color: black;">供给</span>的接口是<span style="color: black;">尽可能</span>单一职责的. 然而在<span style="color: black;">咱们</span>的<span style="color: black;">实质</span><span style="color: black;">研发</span>中, <span style="color: black;">咱们</span>的Server除了<span style="color: black;">供给</span>这些单一职责的小接口外, 最好还能组合一个满足客户端业务<span style="color: black;">需要</span>的repo详情接口出来.</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">Gzip压缩</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">运用</span>Gzip来压缩request和response, 减少传输数据量, 从而减少流量消耗.</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">思虑</span><span style="color: black;">运用</span>Protocol Buffer代替JSON</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">从前<span style="color: black;">咱们</span>传输数据<span style="color: black;">运用</span>XML, 后来<span style="color: black;">运用</span>JSON代替了XML, 很大程度上<span style="color: black;">亦</span>是为了可读性和减<span style="color: black;">少许</span>据量(当然还有映射成POJO的方便程度).</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Protocol Buffer是Google推出的一种数据交换格式.</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">倘若</span><span style="color: black;">咱们</span>的接口每次传输的数据量很大的话, <span style="color: black;">能够</span><span style="color: black;">思虑</span>下protobuf, 会比JSON数据量小<span style="color: black;">非常多</span>.</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">当然相比<span style="color: black;">来讲</span>, JSON<span style="color: black;">亦</span>有其<span style="color: black;">优良</span>, 可读性更高.</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">照片</span>的Size</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">上面Network Monitor中看到的22s到27s之间的有多次请求, 且数据量还很大. <span style="color: black;">便是</span>在获取<span style="color: black;">照片</span>资源.</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">照片</span>相<span style="color: black;">针对</span>接口请求<span style="color: black;">来讲</span>, 数据量要大得多. 故而<span style="color: black;">亦</span>是<span style="color: black;">咱们</span>需要优化的一个点.</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">咱们</span><span style="color: black;">能够</span>在获取<span style="color: black;">照片</span>时<span style="color: black;">通知</span>服务器需要的<span style="color: black;">照片</span>的宽高, 以便服务器给出合适的<span style="color: black;">照片</span>, 避免浪费.</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">咱们</span><span style="color: black;">此刻</span><span style="color: black;">非常多</span><span style="color: black;">机构</span>的<span style="color: black;">照片</span>资源都是<span style="color: black;">运用</span>第三方的云存储服务的(七牛, 阿里云存储之类的).</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">以七牛为例, <span style="color: black;">能够</span>在请求<span style="color: black;">照片</span>的url中添加诸如质量, 格式, width, height等path来获取合适的<span style="color: black;">照片</span>资源:</span></p><span style="color: black;">&lt;pre</span> <span style="color: black;">spellcheck="false"</span> <span style="color: black;">class="md-fences</span> <span style="color: black;">md-end-block</span> <span style="color: black;">ty-contain-cm</span> <span style="color: black;">modeLoaded"</span> <span style="color: black;">lang="java"</span> <span style="color: black;">cid="n57"</span> <span style="color: black;">mdtype="fences"</span> <span style="color: black;">style="box-sizing:</span> <span style="color: black;">border-box;</span> <span style="color: black;">overflow:</span> <span style="color: black;">visible;</span> <span style="color: black;">font-family:</span> <span style="color: black;">var(--monospace);</span> <span style="color: black;">font-size:</span> <span style="color: black;">0.</span><span style="color: black;">9em;</span> <span style="color: black;">display:</span> <span style="color: black;">block;</span> <span style="color: black;">break-inside:</span> <span style="color: black;">avoid;</span> <span style="color: black;">text-align:</span> <span style="color: black;">left;</span> <span style="color: black;">white-space:</span> <span style="color: black;">normal;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-image:</span> <span style="color: black;">inherit;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-position:</span> <span style="color: black;">inherit;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-size:</span> <span style="color: black;">inherit;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-repeat:</span> <span style="color: black;">inherit;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-attachment:</span> <span style="color: black;">inherit;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-origin:</span> <span style="color: black;">inherit;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-clip:</span> <span style="color: black;">inherit;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-color:</span> <span style="color: black;">rgb(248,</span> <span style="color: black;">248</span><span style="color: black;">,</span> <span style="color: black;">248</span><span style="color: black;">);</span> <span style="color: black;">position:</span> <span style="color: black;">relative</span> <span style="color: black;">!important</span><span style="color: black;">;</span> <span style="color: black;">border:</span> <span style="color: black;">1px</span> <span style="color: black;">solid</span> <span style="color: black;">rgb(231,</span> <span style="color: black;">234</span><span style="color: black;">,</span> <span style="color: black;">237</span><span style="color: black;">);</span> <span style="color: black;">border-radius:</span> <span style="color: black;">3px;</span> <span style="color: black;">padding:</span> <span style="color: black;">8px</span> <span style="color: black;">4px</span> <span style="color: black;">6px;</span> <span style="color: black;">margin-bottom:</span> <span style="color: black;">15px;</span> <span style="color: black;">margin-top:</span> <span style="color: black;">15px;</span> <span style="color: black;">width:</span> <span style="color: black;">inherit;</span> <span style="color: black;">color:</span> <span style="color: black;">rgb(51,</span> <span style="color: black;">51</span><span style="color: black;">,</span> <span style="color: black;">51</span><span style="color: black;">);</span> <span style="color: black;">font-style:</span> <span style="color: black;">normal;</span> <span style="color: black;">font-variant-ligatures:</span> <span style="color: black;">normal;</span> <span style="color: black;">font-variant-caps:</span> <span style="color: black;">normal;</span> <span style="color: black;">font-weight:</span> <span style="color: black;">400</span><span style="color: black;">;</span> <span style="color: black;">letter-spacing:</span> <span style="color: black;">normal;</span> <span style="color: black;">orphans:</span> <span style="color: black;">2</span><span style="color: black;">;</span> <span style="color: black;">text-indent:</span> <span style="color: black;">0px;</span> <span style="color: black;">text-transform:</span> <span style="color: black;">none;</span> <span style="color: black;">widows:</span> <span style="color: black;">2</span><span style="color: black;">;</span> <span style="color: black;">word-spacing:</span> <span style="color: black;">0px;</span> <span style="color: black;">-webkit-text-stroke-width:</span> <span style="color: black;">0px;</span> <span style="color: black;">text-decoration-style:</span> <span style="color: black;">initial;</span> <span style="color: black;">text-decoration-color:</span> <span style="color: black;">initial;"&gt;imageView2/&lt;mode&gt;/w/&lt;LongEdge&gt;</span>
    <span style="color: black;">/h/&lt;ShortEdge&gt;</span>
    <span style="color: black;">/format/&lt;Format&gt;</span>
    <span style="color: black;">/interlace/&lt;Interlace&gt;</span>
    <span style="color: black;">/q/&lt;Quality&gt;</span>
    <span style="color: black;">/ignore-error/&lt;ignoreError&gt;</span>
    <span style="color: black;">&lt;/pre&gt;</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">3.2 网络缓存</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">适当的缓存, 既<span style="color: black;">能够</span>让<span style="color: black;">咱们</span>的应用看起来更快, <span style="color: black;">亦</span>能避免<span style="color: black;">有些</span>不必要的流量消耗.</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">3.3 打包网络请求</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">当接口设计<span style="color: black;">不可</span>满足<span style="color: black;">咱们</span>的业务<span style="color: black;">需要</span>时. 例如可能一个界面需要请求多个接口, 或是网络良好, <span style="color: black;">处在</span>Wifi状态下时<span style="color: black;">咱们</span>想获取<span style="color: black;">更加多</span>的数据等.</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">此时</span>就<span style="color: black;">能够</span>打包<span style="color: black;">有些</span>网络请求, 例如请求列表的<span style="color: black;">同期</span>, 获取Header点击率较高的的item项的详情数据.</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">可以<span style="color: black;">经过</span><span style="color: black;">有些</span>统计数据来<span style="color: black;">帮忙</span><span style="color: black;">咱们</span>定位用户接下来的操作是高概率的, 提前获取这部分的数据.</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">3.4 监听<span style="color: black;">关联</span>状态</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">经过</span>监听设备的状态:</span></p><span style="color: black;">休眠状态</span><span style="color: black;">充电状态</span><span style="color: black;">网络状态</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">结合JobScheduler来<span style="color: black;">按照</span><span style="color: black;">实质</span><span style="color: black;">状况</span>做网络请求. 比方说Splash闪屏<span style="color: black;">宣传</span><span style="color: black;">照片</span>, <span style="color: black;">咱们</span><span style="color: black;">能够</span>在连接到Wifi时下载缓存到本地; <span style="color: black;">资讯</span>类的App<span style="color: black;">能够</span>在充电, Wifi状态下做离线缓存.</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">3.5 弱网测试&amp;优化</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">除了正常的网络优化, <span style="color: black;">咱们</span>还需<span style="color: black;">思虑</span>到弱网<span style="color: black;">状况</span>下, App的表现.</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">3.5.1 弱网测试</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">有几种方式来模拟弱网进行测试.</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">Android Emulator</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">创建和<span style="color: black;">起步</span>Android模拟器<span style="color: black;">能够</span>设置网络速度和延迟:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">创建时:</span></strong></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/687d9d068b01411c925b3145ed584e38~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1725618506&amp;x-signature=qDUx5CuIQasUITGmXvXoe5%2BOAgA%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">起步</span>时,</span></strong><span style="color: black;"><span style="color: black;">运用</span>emulator命令:</span></p><span style="color: black;">&lt;pre</span> <span style="color: black;">spellcheck="false"</span> <span style="color: black;">class="md-fences</span> <span style="color: black;">md-end-block</span> <span style="color: black;">ty-contain-cm</span> <span style="color: black;">modeLoaded"</span> <span style="color: black;">lang="java"</span> <span style="color: black;">cid="n85"</span> <span style="color: black;">mdtype="fences"</span> <span style="color: black;">style="box-sizing:</span> <span style="color: black;">border-box;</span> <span style="color: black;">overflow:</span> <span style="color: black;">visible;</span> <span style="color: black;">font-family:</span> <span style="color: black;">var(--monospace);</span> <span style="color: black;">font-size:</span> <span style="color: black;">0.</span><span style="color: black;">9em;</span> <span style="color: black;">display:</span> <span style="color: black;">block;</span> <span style="color: black;">break-inside:</span> <span style="color: black;">avoid;</span> <span style="color: black;">text-align:</span> <span style="color: black;">left;</span> <span style="color: black;">white-space:</span> <span style="color: black;">normal;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-image:</span> <span style="color: black;">inherit;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-position:</span> <span style="color: black;">inherit;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-size:</span> <span style="color: black;">inherit;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-repeat:</span> <span style="color: black;">inherit;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-attachment:</span> <span style="color: black;">inherit;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-origin:</span> <span style="color: black;">inherit;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-clip:</span> <span style="color: black;">inherit;</span> <span style="color: black;">bac<span style="color: black;">公斤</span>round-color:</span> <span style="color: black;">rgb(248,</span> <span style="color: black;">248</span><span style="color: black;">,</span> <span style="color: black;">248</span><span style="color: black;">);</span> <span style="color: black;">position:</span> <span style="color: black;">relative</span> <span style="color: black;">!important</span><span style="color: black;">;</span> <span style="color: black;">border:</span> <span style="color: black;">1px</span> <span style="color: black;">solid</span> <span style="color: black;">rgb(231,</span> <span style="color: black;">234</span><span style="color: black;">,</span> <span style="color: black;">237</span><span style="color: black;">);</span> <span style="color: black;">border-radius:</span> <span style="color: black;">3px;</span> <span style="color: black;">padding:</span> <span style="color: black;">8px</span> <span style="color: black;">4px</span> <span style="color: black;">6px;</span> <span style="color: black;">margin-bottom:</span> <span style="color: black;">15px;</span> <span style="color: black;">margin-top:</span> <span style="color: black;">15px;</span> <span style="color: black;">width:</span> <span style="color: black;">inherit;</span> <span style="color: black;">color:</span> <span style="color: black;">rgb(51,</span> <span style="color: black;">51</span><span style="color: black;">,</span> <span style="color: black;">51</span><span style="color: black;">);</span> <span style="color: black;">font-style:</span> <span style="color: black;">normal;</span> <span style="color: black;">font-variant-ligatures:</span> <span style="color: black;">normal;</span> <span style="color: black;">font-variant-caps:</span> <span style="color: black;">normal;</span> <span style="color: black;">font-weight:</span> <span style="color: black;">400</span><span style="color: black;">;</span> <span style="color: black;">letter-spacing:</span> <span style="color: black;">normal;</span> <span style="color: black;">orphans:</span> <span style="color: black;">2</span><span style="color: black;">;</span> <span style="color: black;">text-indent:</span> <span style="color: black;">0px;</span> <span style="color: black;">text-transform:</span> <span style="color: black;">none;</span> <span style="color: black;">widows:</span> <span style="color: black;">2</span><span style="color: black;">;</span> <span style="color: black;">word-spacing:</span> <span style="color: black;">0px;</span> <span style="color: black;">-webkit-text-stroke-width:</span> <span style="color: black;">0px;</span> <span style="color: black;">text-decoration-style:</span> <span style="color: black;">initial;</span> <span style="color: black;">text-decoration-color:</span> <span style="color: black;">initial;"&gt;$emulator</span> <span style="color: black;">-netdelay</span> <span style="color: black;">gprs</span> <span style="color: black;">-netspeed</span> <span style="color: black;">gsm</span> <span style="color: black;">-avd</span> <span style="color: black;">Nexus_5_API_22</span>
    <span style="color: black;">&lt;/pre&gt;</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">运用</span>网络代理工具</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">以</span><strong style="color: blue;"><span style="color: black;">Charles</span></strong><span style="color: black;">为例:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">保持手机和PC<span style="color: black;">处在</span>同一个局域网, 在手机端wifi设置高级设置中设置代理方式为手动, 代理ip填写PC端ip<span style="color: black;">位置</span>, 端口号默认8888.</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/57e69dd7236d4af2b590bbeee843292a~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1725618506&amp;x-signature=rERqpqdoueBPwbFfaDN8gQE7V1w%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">其他模拟弱网方式</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">倘若</span>你恰好<span style="color: black;">亦</span>是iOS的<span style="color: black;">研发</span>者, Apple<span style="color: black;">供给</span>了Network Link Conditioner, 非常好用.</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">能够</span>模拟的网络<span style="color: black;">状况</span>与<span style="color: black;">以上</span>类似:</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/374c0b23430548f09cb704e12a0bdf3e~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1725618506&amp;x-signature=y0Cdv0Btl0XKNEZIcs0F2zMxLZ0%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">倘若</span>你<span style="color: black;">运用</span>Linux环境<span style="color: black;">研发</span>, 还<span style="color: black;">能够</span>试下facebook出的ATC.</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">3.5.2 弱网优化</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">利用<span style="color: black;">以上</span>工具模拟弱网, 在弱网<span style="color: black;">状况</span>下体验<span style="color: black;">咱们</span>的App. <span style="color: black;">通常</span><span style="color: black;">来讲</span>, 网络延迟在60ms内, 是OK的, 超过200ms就比较糟糕了. <span style="color: black;">咱们</span>需要做的是在比较糟糕的网络环境下还能给用户较好的体验.</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">弱网优化, 本质上是在弱网的<span style="color: black;">状况</span>下能让用户流畅的<span style="color: black;">运用</span><span style="color: black;">咱们</span>的App. <span style="color: black;">咱们</span>要做的<span style="color: black;">便是</span>结合<span style="color: black;">以上</span>的优化项:</span></p><span style="color: black;">压缩/减<span style="color: black;">少许</span>据传输量</span><span style="color: black;">利用缓存减少网络传输</span><span style="color: black;">针对弱网(移动网络), 不自动加载<span style="color: black;">照片</span></span><span style="color: black;">界面先反馈, 请求延迟提交</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">例如, 用户点赞操作, <span style="color: black;">能够</span>直接给出界面的点赞成功的反馈, <span style="color: black;">运用</span>JobScheduler在网络<span style="color: black;">状况</span>较好的时候打包请求</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">有需要文中完整代码的<span style="color: black;">朋友</span></span></strong><strong style="color: blue;"><span style="color: black;"><span style="color: black;">能够</span> 私信发送 “底层源码”</span></strong><strong style="color: blue;"><span style="color: black;"><span style="color: black;">就可</span> 免费获取</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">此刻</span>私信还<span style="color: black;">能够</span><span style="color: black;">得到</span> <span style="color: black;">更加多</span>《Android 学习笔记+源码解析+面试视频》</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">最后我想说:</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">针对</span>程序员<span style="color: black;">来讲</span>,要学习的知识内容、技术有太多太多,<span style="color: black;">想要</span>不被环境淘汰就<span style="color: black;">仅有</span><span style="color: black;">持续</span><span style="color: black;">提高</span>自己,从来都是<span style="color: black;">咱们</span>去适应环境,而不是环境来适应<span style="color: black;">咱们</span></span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">技术是无止境的,你需要对自己提交的每一行代码、<span style="color: black;">运用</span>的每一个工具负责,<span style="color: black;">持续</span>挖掘其底层原理,<span style="color: black;">才可</span>使自己的技术升华到更高的层面</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">Android 架构师之路还很漫长,与君共勉</span></strong></p>




星☆雨 发表于 2024-9-10 01:15:28

我完全赞同你的观点,思考很有深度。

4lqedz 发表于 2024-9-26 14:24:35

大势所趋,用于讽刺一些制作目的就是为了跟风玩梗,博取眼球的作品。

7wu1wm0 发表于 2024-10-16 14:15:59

请问、你好、求解、谁知道等。

4zhvml8 发表于 2024-10-20 20:42:48

请问、你好、求解、谁知道等。

qzmjef 发表于 2024-10-24 16:59:38

我深受你的启发,你的话语是我前进的动力。
页: [1]
查看完整版本: 互联网中不可缺失的网络优化:“App与Server的交互依赖于网络”