Skip to content

Instantly share code, notes, and snippets.

View tcgumus's full-sized avatar

Tuna Çağlar Gümüş tcgumus

View GitHub Profile
@md-farhan-memon
md-farhan-memon / video_embed_url_generator.rb
Last active September 3, 2020 17:17 — forked from niquepa/gist:4c59b7d52a15dde2367a
Ruby/Rails generate YouTube or Vimeo embed video ifram from url
class VideoEmbedUrlGenerator
REGEX_ID = %r{(?:youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/|vimeo\.com\/)([a-zA-Z0-9_-]{8,11})}.freeze
REGEX_PROVIDER = /(youtube|youtu\.be|vimeo)/.freeze
def initialize(url)
@url = url
end
def construct_iframe
'<iframe '\
@chanks
chanks / gist:7585810
Last active February 29, 2024 03:50
Turning PostgreSQL into a queue serving 10,000 jobs per second

Turning PostgreSQL into a queue serving 10,000 jobs per second

RDBMS-based job queues have been criticized recently for being unable to handle heavy loads. And they deserve it, to some extent, because the queries used to safely lock a job have been pretty hairy. SELECT FOR UPDATE followed by an UPDATE works fine at first, but then you add more workers, and each is trying to SELECT FOR UPDATE the same row (and maybe throwing NOWAIT in there, then catching the errors and retrying), and things slow down.

On top of that, they have to actually update the row to mark it as locked, so the rest of your workers are sitting there waiting while one of them propagates its lock to disk (and the disks of however many servers you're replicating to). QueueClassic got some mileage out of the novel idea of randomly picking a row near the front of the queue to lock, but I can't still seem to get more than an an extra few hundred jobs per second out of it under heavy load.

So, many developers have started going straight t