A faster Handy script upload endpoint

Hello fellow handy devs.
Long post ahead, TL;DR at the bottom.

While I’ve been working on setting up a server for Tugbud for some upcoming features. I took the opportunity to try a little experiment in the hopes of speeding up the funscript upload process.

Currently, The Handy official API (or unofficially?) provides an endpoint to upload funscript files and have them converted to a csv, returning a url that you can pass to the setup endpoint to be played by The Handy. This is the endpoint I’ve been using for my all applications.

Said unofficial endpoint
https://www.handyfeeling.com/api/sync/upload

Now, my issue with this endpoint and what has been itching me for a while, is that this endpoint is a bit slow. Not TOO slow, but just enough to make me itch a tiny bit. And after releasing TugBud, which uses this endpoint often, and having to wait just a little bit too long before getting a response from the server every time you want to send a new pattern. The itch became too big for me to scratch on my own.

This is why, with my newly acquired server, I set out the create THE fastest temporary script upload endpoint. And ladies en gentlemen, I have succeeded.

Let me tell you how I achieved this.

First, There is no trick of just using faster hardware, or a faster network. The secret lies in eliminating the disk I/O completely. By never storing the uploaded scripts on disk, we can greatly increase the speed at which the files are served.

This is done internally using Redis, an in-memory data store. This means that all the uploaded scripts are stored in the server ram, never touching the pesky slow storage drives. Now, normally, this is a very bad idea as you risk filling up the ram and have a bad time, but script files are so small that it’s no issue for this precious limited resource. Redis will happily swallow thousands of scripts without even batting an eye. And since scripts uploaded to this endpoint are usually only a way to temporary store them to be sent to the Handy, we can automatically remove them after a pre-determined amount of time, never having to worry about running out of our precious ram.

The results, a much faster API for uploading and downloading scripts to be sent to the Handy.

Now, I hear you screaming, “Where are the stats!”, “prove it!”. fear not as I have some benchmark for you my friends.

Benchmarks

Upload


Benchmark was done querying each apis 57 times

TugBud endpoint: https://tugbud.kaffesoft.com/cache
HandyFeeling endpoint: https://www.handyfeeling.com/api/sync/upload

Average Tugbud api response time: 0.1401958182 Seconds
Average HandyFeeling response time: 0.3604115536 Seconds

Download


Benchmark was done querying each apis 57 times

TugBud endpoint: https://tugbud.kaffesoft.com/cache/d32aac84-078c-4d18-b764-9c05757663e9
HandyFeeling endpoint: https://scripts01.handyfeeling.com/api/script/v0/temp/download/01G9DW29PGQDGKWJD5T7NHN5AF

Average Tugbud api response time: 0.1338017636 Seconds
Average HandyFeeling response time: 0.3544465357 Seconds

As you can see from these results, The TugBud API is consistently twice as fast as the HandyFeeling API for uploading and downloading script files.

How to use the Tugbud API

Now I know you must be aching to switch over all your applications to use this new api. And I’ve designed to be as painless as possible, for tugbud, I simply changed the endpoint and everything worked!

Endpoint: [POST] https://tugbud.kaffesoft.com/cache

enctype=multipart/form-data

example curl

curl -F file=@test.csv https://tugbud.kaffesoft.com/cache
#> {"url":"https://tugbud.kaffesoft.com/cache/610e4155-5af9-4fdc-ac23-fae454384a63"}
# The response is a json containing the download link to the file you uploaded

The Api also supports automatic conversion of funscript files to csv, just like the Handyfeeling endpoint.

Limitations and Specifications

The api is free to use for anyone, I do not keep logs, and do not store your files longer than needed. Files are automatically deleted 2 minutes after being uploaded. The maxmium size of files you can upload is 2MB.

TL;DR

I’m releasing a drop in replacement for the https://www.handyfeeling.com/api/sync/upload api. It’s twice as fast, you can use it by posting your script to this endpoint [POST] https://tugbud.kaffesoft.com/cache. it automatically converts your funscripts to csv.


if you like my work, consider joining the kaffesoft discord, Buying TugBud, or becoming a patreon

tugbud_app_icon2
Get Tugbud
What is TugBud?

discord_button patreon_button

8 Likes

Very generous of you to open this up - thank you! :smiley:

1 Like