Ansible role for deploying and running a Golang binary as a systemd service
- Copy the files into your playbook and set the service_name and base_path to your application.
- The service uses rsyslog to create error.log and access.log.
- Logrotate config included.
- Handles Beego framework logging.
This is an alternative to native SendMail() function that requires authentication in Golang. The function is part of Go Helpers library available on github.
Cachita is a golang file and memory cache library
- Simple caching with auto type assertion included.
- In memory file cache index to avoid unneeded I/O.
- Msgpack based binary serialization using msgpack library for file caching.
API docs: https://godoc.org/github.com/gadelkareem/cachita.
Examples: https://godoc.org/github.com/gadelkareem/cachita#pkg-examples.
InstallationInstall:
go get -u github.com/gadelkareem/cachita
Recently I came across a big MongoDB database which needed pagination. But it was surprising how getting to page number 2000 ended up in a timeout. A quick research led me to MongoDB documentation:
The cursor.skip() method is often expensive because it requires the server to walk from the beginning of the collection or index to get the offset or skip position before beginning to return results. As the offset (e.g. pageNumber above) increases, cursor.skip() will become slower and more CPU intensive. With larger collections, cursor.skip() may become IO bound.
So “skip” clearly won’t work for a big set which led to the sort and gt solution.
Sorting and $gt:Simply sorting by a created_at field then continuing from the last known created_at date by finding the next set would solve the problem.
ids = db.c.find({}, {_id:1}).map(function(item){ return item._id; });
docs = db.c.find( { _id: { $in: ids.slice(2000,2050) } } );