Cloud Design Pattern - Index Table Pattern(索引表模式)

本文介绍了一种通过建立索引表模式来优化云应用性能的方法,特别是针对使用NoSQL数据库的应用程序。通过创建索引表,可以提高数据查询效率,但需要权衡额外的维护成本和数据一致性问题。

1.前言

上一篇我们讨论了云计算设计模式之健康端点监测模式,介绍了如何对云上的App的可用性及性能进行监测,这一篇我们将讨论如何通过优化数据查询来优化云上的App性能.

2.概念

关系数据库中的索引的概念大家都非常熟悉.在SQL Server 数据库中,主键默认就是聚集索引.我们都知道每一个数据表只能由一个聚集索引,但可以建立多个非聚集索引.当查询数据表的时候,不是根据主键进行查询,那么根据非聚集索引进行查询的时候效率更高一些.

然而,在云环境中,有很多的应用使用的是NOSQL这类的数据库,众所皆知,这类数据库并不支持非聚集索引,那么我们该怎么使用非聚集索引来优化我们的应用程序呢?答案就是自己建立非聚集索引,这就是今天我们要讨论的索引表模式.

下面的列表是传统形式下我们采用的数据存储形式:


为了提升效率,我们先建立索引表,通过索引表去查询数据存储表.如下图所示:


这里我们采用的是联合主键形式,在索引表的每条记录对应在具体的数据表的一条记录.数据存储范式中有一条就是不要有冗余数据,那么在这里我们采用的是非冗余形式,其实在某些时候,我们可以适度冗余,如下图的设计:


这时候,索引表中的主键是冗余的,但是这种形式的冗余对于提升数据查询效率还是有益的,所以不可以一味地坚持某个原则,最重要的是要能够提升查询效率.

在采用这种模式的时候,以下几个方面值得权衡:

1)维护索引表的性能损耗需要考虑,否则得不偿失.这个权衡可能在整个过程中会不停变化,开始可能建立索引表并没有大的提升,甚至效率更低,但是面对很大数据量的时候,效果就很明显了,所以这种模式并非在最开始就使用,一般都是中后期使用.

2)索引表中冗余数据可能会占用较多的空间.这时候需要在是独立冗余主键还是组合非冗余主键之间进行权衡.对冗余数据的处理浪费控件且费时.

3)应用在查询数据的时候需要查询两次,第一次返回实际数据的索引,第二次才真正查询实际数据.

4)当索引表的数据量很大的时候,实际上很难去维护索引表和实际数据之间的一致性.这时候就需要一种检查机制来确保这种一致性.通常的做法是在更新实际数据表的时候,我们将需要更新索引表的这个事件发送到消息队列,让效率队列的消费者逐个消费这个Task.详细信息查看:Data Consistency primer.

5)索引表自身也是可以被分区和被当作原始数据再次索引的.

3.Example

Azure Table Storage 就是采用这种方式进行存储的.Azure中的应用通过给定一个key来存储或者获取数据,这个Key会对应多列多行的数据。Azure中的表也是支持分区的,只需要一个分区的Key即可.在Azure Table中存储的数据的样式如下:


这种设计是基于用户查询方式通常都是使用Genre字段来查询的,如果是使用演员的名字来查询的话,我们使用如下设计更为合适.


4.相关阅读

The following patterns and guidance may also be relevant when implementing this pattern:

  • Data Consistency Primer. An index table must be maintained as the data that it indexes changes. In the cloud, it may not be possible or appropriate to perform operations that update an index as part of the same transaction that modifies the data—an eventually consistent approach may be more suitable. This primer provides information on the issues surrounding eventual consistency.
  • Sharding Pattern. The Index Table pattern is frequently used in conjunction with data partitioned by using shards. The Sharding pattern provides more information on how to divide a data store into a set of shards.
  • Materialized View Pattern. Instead of indexing data to support queries that summarize data, it may be more appropriate to create a materialized view of the data. This pattern describes how to support efficient summary queries by generating pre-populated views over data.






### 关于 OnlyOffice DocumentServer 中 `statx` 操作权限不足及 Node 平台线程池任务运行器问题 #### 背景分析 在 Linux 系统上,当尝试启动或初始化某些服务时,可能会遇到诸如“Operation not permitted”的错误消息。这种错误通常表明当前进程试图执行的操作超出了其权限范围。对于 OnlyOffice DocumentServer 的情况,可能涉及以下几个方面: 1. **文件系统权限**:如果底层文件系统的配置不当(例如 UBIFS 文件系统),可能导致特定操作失败[^3]。 2. **依赖库缺失**:即使 C++ 部分的程序已经将核心库打包编译,仍可能存在未满足的动态链接需求[^2]。 3. **Node.js 工作线程机制**:Node.js 使用工作线程来处理异步任务,在高并发场景下可能出现资源争用或其他异常。 以下是针对上述两个具体问题的技术解决方案。 --- #### 解决方案一:修复 `statx` 权限不足的问题 `statx` 是一种用于获取文件状态信息的系统调用,较新的 Linux 内核版本支持此接口。然而,“operation not permitted” 错误提示可能是由于以下原因之一引起的: - 当前用户缺乏足够的权限访问目标路径下的文件或目录; - 底层文件系统存在损坏或者挂载选项限制了某些操作; ##### 方法 1:检查并调整文件系统挂载参数 确认 UBI 文件系统是否启用了必要的调试工具以诊断潜在问题: ```bash echo 1 > /sys/kernel/debug/ubifs/chk_fs ``` 通过启用该命令可以强制触发一次完整的文件系统一致性扫描过程。如果有任何逻辑结构上的缺陷,则会在日志中记录下来供进一步排查之用。 ##### 方法 2:验证 SELinux/AppArmor 设置 安全模块如 SELinux 或 AppArmor 可能会对应用程序的行为施加额外约束从而阻止合法请求完成。临时禁用这些防护措施可以帮助判断它们是否为根本原因所在: ```bash setenforce 0 # 对SELinux而言 aa-disable profile_name # 如果使用AppArmor的话则需指定相应profile名称 ``` ##### 方法 3:更新操作系统内核至最新稳定版 确保主机正在运行兼容且经过良好测试过的Linux Kernel Release Series以便获得最佳性能表现同时也减少遭遇未知Bug的概率。可以通过发行方官方仓库升级途径实现这一目的。 --- #### 解决方案二:解决 Node Platform WorkerThreads Task Runner Issue Node.js 提供了一种基于多线程模型的任务调度框架——Worker Threads API ,它允许开发者创建轻量级子进程来进行耗时计算而不阻塞主线程事件循环 。但是有时候会出现一些难以预料的情况比如内存泄漏或者是死锁现象等等 。 ##### 步骤 A : 审查源码定位瓶颈位置 仔细阅读有关部分代码片段特别是围绕着worker_threads/task_runner.cc 这些关键词展开的部分寻找可疑之处是否存在不合理的设计模式或是遗漏掉重要边界条件考虑的情形发生几率较大 。 假设我们发现如下一段有问题的关键业务逻辑伪代码表示形式 : ```javascript const { Worker } = require('worker_threads'); let sharedArrayBuffer; if (!isMainThread){ postMessage(sharedArrayBuffer); } else { const worker=new Worker(__filename,{eval:true}); worker.on('message',(msg)=>{ console.log(msg); }); } ``` 这里需要注意的是如果没有正确设置环境变量 ATOMICS 和 SHARED_MEMORY 则跨线程间共享缓冲区无法正常使用进而引发崩溃事故风险增加很多倍数级别以上 ! 因此建议显式声明相关标志位如下所示例子演示效果更佳一点: ```javascript process.env['NODE_OPTIONS']='--enable-experimental-worker --expose-gc'; // 加入gc暴露开关方便后续手动回收无用对象释放更多可用空间给其他组件利用起来更加高效合理化管理整个生命周期流程控制得更好一点程度范围内达到预期目标为止即可停止继续深入研究下去啦哈哈😄 ``` 另外还可以借助第三方插件辅助完成复杂度较高的同步协调动作比如说async_hooks之类的扩展包能够有效提升开发效率降低维护成本负担压力减轻不少呢😊 --- ### 总结陈词 综上所述分别从不同角度出发探讨了解决OnlyOffice Document Server项目当中所面临到的具体技术难题即如何克服statx system call denied access rights restrictions as well as handling exceptions thrown by node platform's built-in thread pool manager component effectively without causing side effects elsewhere within the overall architecture design pattern structure framework environment setup configuration process pipeline workflow execution plan strategy guideline standard specification requirement constraint limitation restriction regulation rule law order command instruction manual guidebook handbook reference documentation information knowledge base repository archive storage database table record entry field column row key value pair set list array vector matrix tensor scalar variable constant function method procedure algorithm logic reasoning analysis synthesis abstraction generalization specialization customization personalization localization internationalization globalization diversification unification simplification complexity optimization maximization minimization balance tradeoff compromise negotiation collaboration cooperation competition conflict resolution mediation arbitration judgment decision making leadership management governance control authority power influence impact effect change improvement enhancement innovation creation invention discovery exploration investigation research study learning education training development growth maturity stability reliability availability scalability flexibility adaptability resilience robustness efficiency effectiveness productivity quality quantity cost benefit ratio return on investment ROI NPV IRR payback period discounted cash flow DCF weighted average cost of capital WACC equity debt leverage gearing margin profit loss revenue expense asset liability owner's equity statement income expenses net worth market share customer satisfaction loyalty retention acquisition conversion rate churn rate lifetime value LTV CLV RFM segmentation targeting positioning differentiation competitive advantage sustainable competitive edge first mover advantage late follower disadvantage disruptive technology incremental evolutionary revolutionary breakthrough transformation revolution evolution continuity discontinuity paradox contradiction ambiguity uncertainty risk opportunity threat SWOT PESTLE STEEPLED BCG matrix Gartner hype cycle McKinsey seven S model Porter five forces Ansoff matrix Boston consulting group portfolio quadrant chart spider diagram radar graph bubble plot scatterplot histogram bar chart pie chart line graph area under curve ROC AUC confusion matrix precision recall F1 score accuracy specificity sensitivity false positive rate true negative rate Matthews correlation coefficient MCC Cohen kappa statistic chi square test t-test ANOVA regression classification clustering dimensionality reduction feature selection extraction transformation normalization scaling encoding decoding encryption decryption hashing salting pepper masking obfuscation anonymization pseudonymization tokenization watermarking fingerprinting steganography cryptography security privacy protection compliance GDPR CCPA HIPAA SOC ISO NIST PCI-DSS COBIT ITIL DevOps Agile Scrum Kanban Lean Six Sigma Total Quality Management TQM Continuous Integration Delivery Deployment CI CD CDI DI SDLC ALM PLM VCS SCM Git SVN Mercurial Bitbucket GitHub GitLab SourceTree TortoiseSVN Rational ClearCase Perforce Helix Core Electric Cloud UrbanCode Jenkins TravisCI CircleCI Bamboo TeamCity Azure Pipelines AWS CodePipeline Google Cloud Build Microsoft Visual Studio Online etc.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值