Topics

Ansible Golang Service

Ansible Golang Service

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.

Golang send mail without authentication using localhost sendmail or postfix

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

Cachita

Cachita is a golang file and memory cache library

Build Status
GoDoc

  • 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.

Installation

Install:

go get -u github.com/gadelkareem/cachita

Workaround for the slow pagination using skip in MongoDB

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) } } );

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close