A 512MB droplet doesn't require any swap if you configure it correctly. I have 3 running now with no swap all running production websites.
The only reason you would need to add swap is if you are running out of RAM and the only reason you would be running out of RAM would be because you misconfigured something (normally either Apache or MySQL are the common culprits).
I'd revisit your configuration and try and fix the root problem. Relying on swap is a very silly idea.
Really? I dont want to hijack this thread, but since you already kind of did that and your post comes with a hint of condescension, Ill respond.
Actually, I think NOT having a swap partition in place is silly regardless of how much RAM your server has. Independent of how much optimization youve done with Apache, MySQL, etc., you cannot guarantee that some process on your machine will not develop (or already has) a memory leak over time and/or a significant increase in server load wont overload the system regardless of the optimization youve done. Its an insurance policy with no real downside. I have a 1GB droplet that has been up for 223 days and is only using 4672k of a 524284K swap, but its there if it needs it.
Heres an article on Digital Oceans site regarding swap partitions:
https://www.digitalocean.com/community/tutorials/how-to-configure-virtual-memory-swap-file-on-a-vps
And heres a quote from the article:
If you're dealing with any production server, you need to know that if virtual memory is not enabled and your system has no more free memory...then if a program or service - perhaps your web server - needs to allocate more memory, it will fail! Depending on your platform and configuration, this can result in many undesirable or unstable conditions including other applications (i.e. other processes than the one asking for memory) being forced to close to free the needed memory, to it failing and crashing the program - or whole server - entirely.
Because of this, I personally recommend anyone, on nearly any system - be it a droplet, dedicated server, your Windows PC or Mac or even your Android tablet or phone - should have at least a small amount of virtual memory enabled.
I havent found an article yet suggesting you shouldnt add a swap partition. And it makes even more sense on Digital Ocean with its SSD drives making r/w from the hard disk much faster than traditional hard drives.
With regard to MySQL specifically a common issue with LAMP setups on small (memory) servers is that the MySQL process will get killed off once no more memory is available. While further MySQL optimization might be necessary, its a common misdiagnosis thats due to MySQL at all. Its often some other process like Apache spawning too many workers (which can also be addressed via optimization to a point, but Id recommend using Nginx anyway) that will cause the system kill something off, and for whatever reason, MySQL often gets the short straw (maybe due to a relatively large memory footprint that makes it a good candidate to free up the most memory).
In conclusion, dont be silly. Always have a swap partition in place just in case. (<= that has a nice ring to it).