DynamoDB

Jun 07, 2016 pm 04:10 PM
dynamodb thread lightweight process

本来想写写进程、线程、轻量级线程、goroutine还有协程(coroutine),为什么我把goroutine单独列出来是因为它不是协程,所有翻译成协程的都是偷用概念,把比线程轻量的都叫做协程。算了,先不纠结这个,今天想写写DynamoDB,记录下经历。 就如官网描述到的

本来想写写进程、线程、轻量级线程、goroutine还有协程(coroutine),为什么我把goroutine单独列出来是因为它不是协程,所有翻译成协程的都是偷用概念,把比线程轻量的都叫做协程。算了,先不纠结这个,今天想写写DynamoDB,记录下经历。

就如官网描述到的,无限扩展,好吧,具体实现也不得而知,但这个无限扩展的前提是诸多限制。在确认DynamoDB是否适口你的项目使用的时候,记得多分析它的限制,否则迟早会成为项目的瓶颈,或者减缓业务的开发。

首先,DynamoDB统计不友好,想统计它的东西?最好还是放弃这个念头,扫描一遍的代价大得不可思议。在用DynamoDB之前,先弄好你的日志系统。
其次,它不是缓存,虽然是说SSD搞的,但是连这个东西(HTTPS)的代价不是普通缓存所会做的,就它内部查询性能来看,也是几十上百毫秒级别的。
再次,不要以为这个东西很容易用,各种SDK各种坑,拿python boto为例子,两个版本的实现,各自残缺,有些功能SDK根本提供不了,你要做好写RESTful requests的准备。
最后,你要是会看英文且真的想用DynamoDB就别继续往下看了,直接看官网文档各种详尽和指引,以下只是个人心得和坑的摘录。

第一个坑是数据类型,嗯,不完全符合JSON,也就是说,这个要做点格式转换,前不久才出了List和Map的支持,叫文档类型,官方建议可以把JSON压缩成Binary,这...。一条项目(就是一条record,叫item)最大存储容量为400KB(只是英文文档这样写,中文文档还没更新,依然写着64K,这有点小,除此以外,中文文档残缺不全,不值一嗔),这个还可以。读/写流量限制预设(Provisioned Throughput)是一个最大的坑,以流量限定读写速率和容量。单个读单位可在1秒内读1次且4KB以内的内容,40KB就要10个读单位,同样地,单个写单位每秒可写入1次且1KB以内内容。
第二个坑来了,就是这个读/写流量限制预设,全局二级索引是和主表分开预设流量计算。最坑在于,倘若你想写入主表,主表的预设流量是够的而全局二级索引预设流量不够,这样就会插不进,报错,这样使得全局二级索引和新建一张表无异,新建一张表还更灵活。预设流量的另一个坑是,你的hashkey(整个数据库以hashkey作为主键,不知道的请到官网中文版补习)必须hash得均匀才能得到预设流量的最大效用。比如说,你预设了1000个读(预设读容量超过10000还需要递表申请),amazon帮你自动分在20个区存放,那么你每个区只会获得50个读的流量,假如你现在急着要读某一类别的数据,并且这一类别的不小心集中在某一区域,不好意思,你的消费将乘以个几倍几十倍(amazon的服务本身就贵)。如果你要强一致性读(默认是不强一致性读的,不懂的自己脑补),那么将会消耗两倍于脏读的读单位。
第三大坑是索引,上面说到的全局索引是一个坑,还有一种叫二级本地索引也是一个坑,它居然有一条单个hashkey索引内容不超过10G的规定,这个索引内容投影属性*(这个概念请看官网)。这就是说,当你索引加投影单个item有200个字节(200个字节真心不多吧,一个uuid随便都32byte了,当然,你可以选择压缩...),200字节的情况下,该hashkey最多可以包含的条目是5000万条,这个规定直接给人限死了,你不能拿单个hashkey来玩,更别做太多投影。此外,索引是不能添加修改删除的,只能跟随表创建时添加。虽然有10G这个限定,但我觉得它的RangeKey和本地二级索引还是比较独特的,可以解决很大一部分的需求。前提是,最深的索引就是二级,你要做三级四级的索引就要想一下办法了,这个想一下办法也可以再解决一大部分的需求吧。
第四,别考虑太多事务啊原子操作之类,它做不了,简单的自增还是可以的。
最后就是SDK,如果你只是简单的使用,python的SDK boto没什么大问题,但你考虑到并发冲突,部分属性修改兼上是否覆盖写入等等的问题的时候,boto压根就不能解决,这就需要又花费一大块精力去手工Restful了,当然,如果你想用上tonado,没有现成的异步模块可用。

如果你已经跳过上述的坑,相信离DynamoDB符合你的项目需求已经不远了,当然,性能方面我还没做过多测试,准备上线亿级以上条目的项目了,详情敬请期待。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain what the explorer.exe process is Explain what the explorer.exe process is Feb 18, 2024 pm 12:11 PM

What process is explorer.exe? When we use the Windows operating system, we often hear the term "explorer.exe". So, are you curious about what this process is? In this article, we will explain in detail what process explorer.exe is and its functions and effects. First of all, explorer.exe is a key process of the Windows operating system. It is responsible for managing and controlling Windows Explorer (Window

What kind of process is ccsvchst.exe? What kind of process is ccsvchst.exe? Feb 19, 2024 pm 11:33 PM

ccsvchst.exe is a common process file that is part of the Symantec Endpoint Protection (SEP) software, and SEP is an endpoint protection solution developed by the well-known network security company Symantec. As part of the software, ccsvchst.exe is responsible for managing and monitoring SEP-related processes. First, let’s take a look at SymantecEndpointProtection(

Best lightweight Linux distributions for low-end or older computers Best lightweight Linux distributions for low-end or older computers Mar 06, 2024 am 09:49 AM

Looking for the perfect Linux distribution to breathe new life into your old or low-end computer? If yes, then you have come to the right place. In this article, we'll explore some of our top picks for lightweight Linux distributions that are specifically tailored for older or less powerful hardware. Whether the motivation behind this is to revive an aging device or simply maximize performance on a budget, these lightweight options are sure to fit the bill. Why choose a lightweight Linux distribution? There are several advantages to choosing a lightweight Linux distribution, the first of which is getting the best performance on the least system resources, which makes them ideal for older hardware with limited processing power, RAM, and storage space. Beyond that, with heavier resource intensive

How to properly kill zombie processes in Linux How to properly kill zombie processes in Linux Feb 19, 2024 am 10:40 AM

In Linux systems, zombie processes are special processes that have been terminated but still remain in the system. Although zombie processes do not consume many resources, if there are too many, they may cause system resource exhaustion. This article will introduce how to correctly remove zombie processes to ensure the normal operation of the system. 1Linux zombie process After the child process completes its task, if the parent process does not check the status in time, the child process will become a zombie process. The child process is waiting for confirmation from the parent process, and the system will not recycle it until it is completed. Otherwise, the zombie process will continue to hang in the system. To check whether there are zombie processes in the system, you can run the command top to view all running processes and possible zombie processes. The result of the ‘top’ command can be seen from the figure above in Linux.

Detailed explanation of Linux process priority adjustment method Detailed explanation of Linux process priority adjustment method Mar 15, 2024 am 08:39 AM

Detailed explanation of the Linux process priority adjustment method. In the Linux system, the priority of a process determines its execution order and resource allocation in the system. Reasonably adjusting the priority of the process can improve the performance and efficiency of the system. This article will introduce in detail how to adjust the priority of the process in Linux and provide specific code examples. 1. Overview of process priority In the Linux system, each process has a priority associated with it. The priority range is generally -20 to 19, where -20 represents the highest priority and 19 represents

How to stop Task Manager process updates and kill tasks more easily in Windows 11 How to stop Task Manager process updates and kill tasks more easily in Windows 11 Aug 20, 2023 am 11:05 AM

How to Pause Task Manager Process Updates in Windows 11 and Windows 10 Press CTRL+Window Key+Delete to open Task Manager. By default, Task Manager will open the Processes window. As you can see here, all the apps are endlessly moving around and it can be hard to point them down when you want to select them. So, press CTRL and hold it, this will pause the task manager. You can still select apps and even scroll down, but you must hold down the CTRL button at all times.

Analyze why Golang is suitable for high concurrency processing? Analyze why Golang is suitable for high concurrency processing? Feb 29, 2024 pm 01:12 PM

Golang (Go language) is a programming language developed by Google, aiming to provide an efficient, concise, concurrent and lightweight programming experience. It has built-in concurrency features and provides developers with powerful tools to perform well in high-concurrency situations. This article will delve into the reasons why Golang is suitable for high-concurrency processing and provide specific code examples to illustrate. Golang concurrency model Golang adopts a concurrency model based on goroutine and channel. goro

Why do processes in Linux sleep? Why do processes in Linux sleep? Mar 20, 2024 pm 02:09 PM

Why do processes in Linux sleep? In the Linux operating system, a process can become dormant due to a number of different reasons and conditions. When a process is in a dormant state, it means that the process is temporarily suspended and cannot continue execution until certain conditions are met before it can be awakened to continue execution. Next, we will introduce in detail several common situations when a process enters hibernation in Linux, and illustrate them with specific code examples. Waiting for I/O to complete: When a process initiates an I/O operation (such as reading

See all articles