TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Persisting state between AWS EC2 spot instances

109 pointsby p8donaldover 7 years ago

19 comments

manigandhamover 7 years ago
Persistent storage remains a complicated problem. Attaching volumes on the fly with docker volume abstraction works well enough for most cloud workloads, whether on-demand or spot, but it&#x27;s still easy to run into problems.<p>This is leading to rapid progress in clustered&#x2F;distributed filesystems and it&#x27;s even built into the Linux kernel now with OrangeFS [1]. There are also commercial companies like Avere [2] who make filers that run on object storage with sophisticated caching to provide a fast networked but durable filesystem.<p>Kubernetes is also changing the game with container-native storage. This seems to be the most promising model for the future as K8S can take care of orchestrating all the complexities of replicas and stateful containers while storage is just another container-based service using whatever volumes are available to the nodes underneath. Portworx [3] is the great commercial option today with Rook and OpenEBS [4] catching up quickly.<p>1. <a href="http:&#x2F;&#x2F;www.orangefs.org" rel="nofollow">http:&#x2F;&#x2F;www.orangefs.org</a><p>2. <a href="http:&#x2F;&#x2F;www.averesystems.com&#x2F;products&#x2F;products-overview" rel="nofollow">http:&#x2F;&#x2F;www.averesystems.com&#x2F;products&#x2F;products-overview</a><p>3. <a href="https:&#x2F;&#x2F;portworx.com" rel="nofollow">https:&#x2F;&#x2F;portworx.com</a><p>4. <a href="https:&#x2F;&#x2F;github.com&#x2F;openebs&#x2F;openebs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;openebs&#x2F;openebs</a>
评论 #15429306 未加载
评论 #15431312 未加载
solaticover 7 years ago
OP is offering some very dangerous advice.<p>Twenty years ago, software was hosted on fragile single-node servers with fragile, physical hard disks. Programmers would read and write files directly from and to the disk, and learn the hard way that this left their systems susceptible to corruption in case things crashed in the middle of a write. So behold! People began to use relational databases which offered ACID guarantees and were designed from the ground up to solve that problem.<p>Now we have a resource (spot instances) whose unreliability is a <i>featured design constraint</i> and OP&#x27;s advice is to just mount the block storage over the network and everything will be fine?<p>Here&#x27;s hoping OP is taking frequent snapshots of their volumes because it sure sounds like data corruption is practically a statistical guarantee if you take OP&#x27;s advice without considering exactly how state is being saved on that EBS volume.
评论 #15429382 未加载
评论 #15429208 未加载
评论 #15429139 未加载
bdcravensover 7 years ago
Spot instances can now &quot;stop&quot; instead of &quot;terminate&quot; when you get priced out, persisting the attached EBS volumes:<p><a href="https:&#x2F;&#x2F;aws.amazon.com&#x2F;about-aws&#x2F;whats-new&#x2F;2017&#x2F;09&#x2F;amazon-ec2-spot-can-now-stop-and-start-your-spot-instances&#x2F;" rel="nofollow">https:&#x2F;&#x2F;aws.amazon.com&#x2F;about-aws&#x2F;whats-new&#x2F;2017&#x2F;09&#x2F;amazon-ec...</a>
评论 #15429986 未加载
otterleyover 7 years ago
Even if you don&#x27;t use spot instances, the technique of using separate EBS volumes to hold state is useful (and well-known). Ordinary on-demand instances can also be terminated prematurely due to hardware failure or other issues, so storing state on a non-root volume should be considered a best current practice for any instance type.
fulafelover 7 years ago
There&#x27;s a mechanism exactly for this purpouse in Linux: pivot_root. It&#x27;s used in the standard boot process to switch from the initrd (initial ramdisk) environment to the real system root.<p>ec2-spotter classic uses this, but you can also make a pivoting AMI of your favourite Linux distribution.<p>One thing to watch out for is how to keep the OS automatic kernel updates working. AMIs are rarely updated and you&#x27;re going to have a &quot;damn vulnerable linux&quot; if you don&#x27;t get the updates just after booting a new image.
js4allover 7 years ago
When you are using Kubernetes, you won&#x27;t have to deal with this yourself. The Cluster will move pods from nodes that are stopped because the spot price is exceeded. Ideally place nodes at different bids. So there will be a performance hit but no outage. With the new AWS start&#x2F;stop feature [1] nodes will come up again when the spot price sinks.<p>1) <a href="https:&#x2F;&#x2F;aws.amazon.com&#x2F;about-aws&#x2F;whats-new&#x2F;2017&#x2F;09&#x2F;amazon-ec2-spot-can-now-stop-and-start-your-spot-instances&#x2F;" rel="nofollow">https:&#x2F;&#x2F;aws.amazon.com&#x2F;about-aws&#x2F;whats-new&#x2F;2017&#x2F;09&#x2F;amazon-ec...</a>
yjftsjthsd-hover 7 years ago
TLDR: Attach EBS volume and use that to store Docker containers.<p>I suppose it&#x27;s a decent solution if you don&#x27;t want to deal with prefixes.
Pirate-of-SVover 7 years ago
To make this even more streamlined you&#x27;d tag the volumes and discover the volumes with `aws ec2 describe-volumes` and filter unattached volumes with the magic tag.
评论 #15428417 未加载
stonewhiteover 7 years ago
We normally utilize spots with Spotinst + Elasticbeanstalk. Our billing looked great ever since.<p>This solution looks good, yet only applies to single instance scenarios. I presume this kind of thinking might move forward with EFS + chroot for an actual scalable solution that cannot be ran on Elasticbeanstalk.
archgoonover 7 years ago
So I was pleasantly surprised to discover that for the last several years, spot instances have provided a mechanism that give you 2 minutes notice prior to shutdown:<p><a href="http:&#x2F;&#x2F;docs.aws.amazon.com&#x2F;AWSEC2&#x2F;latest&#x2F;UserGuide&#x2F;spot-interruptions.html" rel="nofollow">http:&#x2F;&#x2F;docs.aws.amazon.com&#x2F;AWSEC2&#x2F;latest&#x2F;UserGuide&#x2F;spot-inte...</a><p>Learn something new everyday. :)<p><a href="https:&#x2F;&#x2F;aws.amazon.com&#x2F;blogs&#x2F;aws&#x2F;new-ec2-spot-instance-termination-notices&#x2F;" rel="nofollow">https:&#x2F;&#x2F;aws.amazon.com&#x2F;blogs&#x2F;aws&#x2F;new-ec2-spot-instance-termi...</a>
评论 #15431631 未加载
sciurusover 7 years ago
The author goes to great lengths to come up with a way for the software that was running on a terminated spot instance to be relaunched using the same root filesystem on a new spot instance, but they never explain <i>why</i> they need to do <i>exactly</i> this. Maybe they already ran everything in Docker containers on CoreOS, so their solution isn&#x27;t a big shift, but I strongly suspect they could find a simpler way to save and restore state if they got over this obsession with preserving the root filesystem their software sees.
olegkikinover 7 years ago
If you don&#x27;t care about reliability, why not just get a cheap and powerful VPS? Paying $90&#x2F;month for that machine is madness. I pay $6&#x2F;month for 6GB RAM, 4 cores, 50GB disk.
评论 #15428362 未加载
评论 #15428196 未加载
评论 #15428214 未加载
评论 #15428213 未加载
ramananover 7 years ago
Well, one easy way when using Ubuntu-like distributions is to simply place your `&#x2F;home` folder on a separate (persistent) EBS volume [1].<p>With a few on-boot scripts to attach-volumes &#x2F; start-containers, it should be fairly easy to get going as well.<p>[1] <a href="https:&#x2F;&#x2F;engineering.semantics3.com&#x2F;the-instance-is-dead-long-live-the-instance-8b159f25f70a" rel="nofollow">https:&#x2F;&#x2F;engineering.semantics3.com&#x2F;the-instance-is-dead-long...</a>
评论 #15429767 未加载
likelynewover 7 years ago
I don&#x27;t know why all the comments are saying this is bad idea. For me, one of thing for I use EC2 is deep learning. I just use spot GPU instance, attach overlayroot volume and launch jupyter notebook in it. Other things like google dataflow is not useful to me due to the price and the process of installing packages. I can also think of many other use cases for using some persistence volume for some manual task.
amqover 7 years ago
Wouldn&#x27;t it be simpler to have the smallest possible instance run an NFS server? This would also have an additional bonus of scalability.<p>Edit: or use AWS EFS
评论 #15428410 未加载
评论 #15428318 未加载
评论 #15428440 未加载
raverbashingover 7 years ago
Is it just me or to me spot instances should deal with work and not storage, and hence your (stateful) units of work should be in a Queue&#x2F;DB? (in a non-spot instance)<p>Attaching and detaching volumes is a good idea but I wouldn&#x27;t use that to keep state
tuananhover 7 years ago
we use k8s at work. i just have to create PVC and when spot instance terminated along with the container; new container will be created and mount the PVC again automatically.
jdchernofskyover 7 years ago
Or you could just use Spotinst: <a href="https:&#x2F;&#x2F;spotinst.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;spotinst.com&#x2F;</a>
alex_dufover 7 years ago
It sounds wrong to try to keep the state across two ec2 instances. If you find yourself in that situation, try pushing your state outside the ec2 instance a bit harder. (dynamodb, s3 etc...)<p>You will get a <i>lot</i> of benefit out of it, but may lose in performance, which is fine in 99% of the cases.