<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta>
      <journal-title-group>
        <journal-title>Joint Conference (March</journal-title>
      </journal-title-group>
    </journal-meta>
    <article-meta>
      <title-group>
        <article-title>Performance Evaluation of MongoDB and PostgreSQL for spatio-temporal data</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Antonios Makris</string-name>
          <email>amakris@hua.gr</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Giannis Spiliopoulos</string-name>
          <email>giannis.spiliopoulos@marinetrafic.com</email>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Konstantinos Tserpes</string-name>
          <email>tserpes@hua.gr</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Dimosthenis Anagnostopoulos</string-name>
          <email>dimosthe@hua.gr</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Dept. of Informatics and Telematics</institution>
          ,
          <addr-line>Harokopio</addr-line>
          ,
          <institution>University of Athens</institution>
          ,
          <addr-line>Athens</addr-line>
          ,
          <country country="GR">Greece</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>MarineTrafic</institution>
          ,
          <addr-line>London</addr-line>
          ,
          <country country="UK">United Kingdom</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2019</year>
      </pub-date>
      <volume>26</volume>
      <issue>2019</issue>
      <abstract>
        <p>Several modern day problems need to deal with large amounts of spatio-temporal data. As such, in order to meet the application requirements, more and more systems are adapting to the speciifcities of those data. The most prominent case is perhaps the data storage systems, that have developed a large number of functionalities to eficiently support spatio-temporal data operations. This work is motivated by the question of which of those data storage systems is better suited to address the needs of industrial applications. In particular, the work conducted, set to identify the most eficient data store system in terms of response times, comparing two of the most representative of the two categories (NoSQL and relational), i.e. MongoDB and PostgreSQL. The evaluation is based upon real, business scenarios and their subsequent queries as well as their underlying infrastructures, and concludes in confirming the superiority of PostgreSQL. Specifically, PostgreSQL is four times faster in terms of response time in most cases and presents an average speedup around 2 in first query, 4 in second query and 4,2 in third query in a five node cluster. Also, we observe that the average response time is significantly reduced at half with the use of indexes almost in all cases, while the reduction is significantly lower in PostgreSQL.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>INTRODUCTION</title>
      <p>
        The volumes of spatial data that modern-day systems are
generating has met staggering growth during the last few years.
Managing and analyzing these data is becoming increasingly
important, enabling novel applications that may transform science
and society. For example, mysteries are unravelled by harnessing
the 1 TB of data that is generated per day from NASA’s Earth
Observing System [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], or the more than 140 GB of raw science
spatial data every week generated by space Hubble telescope [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ].
At the same time, numerous business applications are emerging
by processing the 285 billion points regarding aircraft movements
per year gathered from the Automatic Dependent Surveillance
Broadcast (ADS-B) system [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] and the 60Mb of AIS and weather
data collected every second by MarineTrafic’s on-line
monitoring service [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] or the 4 millions geotagged tweets daily produced
at Twitter [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ].
      </p>
      <p>
        Distributed database systems have been proven instrumental
in the efort to dealing with this data deluge. These systems are
distinguished by two key-characteristics: a) system scalability:
the underlying database system must be able to manage and
store a huge amount of spatial data and to allow applications to
eficiently retrieve it; and, b) interactive performance: very fast
response times to client requests. Some systems that natively
meet those requirements for spatial data are: Hadoop-GIS [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] and
SpatialHadoop [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ], MD-HBase [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ], GeoMesa [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ], SMASH [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ]
and systems that use spatial resilient distributed datasets (SRDD)
such as SpatialSpark [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ], GeoTrellis [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ] and GeoSpark [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ].
      </p>
      <p>The plethora of available systems and underlying technologies
have left the researchers and practitioners alike puzzled as to
what is the best option to employ in order to solve their big spatial
data problem at hand. The query and data characteristics only
add to the confusion. It is imperative for the research community
to contribute to the clarification of the purposes and highlight
the pros and cons of certain distributed database platforms. This
work aspires to contribute towards this direction by comparing
two suchlike platforms for a particular class of requirements, i.e.
those that the response time in complex spatio-temporal queries
is of high importance.</p>
      <p>
        In particular, we compare the performance in terms of
response time between a scalable document-based NoSQL
datastoreMongoDB [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ] and an open source object-relational database
system (ORDBMS)-PostgreSQL [
        <xref ref-type="bibr" rid="ref15">15</xref>
        ] with the PostGIS extension.
PostGIS is a spatial extender that adds support for geographic
objects. The performance is measured using a set of spatio-temporal
queries that mimic real case scenarios that performed in a dataset
provided by MarineTrafic 1. The evaluation of the systems was
examined in diferent scenarios; in a 5 node cluster setup versus
1 node implementation and with the use of indexes versus not.
Each database system was deployed on EC2 instances on Amazon
Web Services (AWS)2 and for storing/retrieving the data we used
the Amazon S3 bucket.
      </p>
      <p>The results show that PostgreSQL with the PostGIS extension,
outperforms MongoDB in all queries. Specifically, PostgreSQL
is four times faster in terms of response time in most cases and
presents an average speedup around 2 in the first query, 4 in the
second query and 4,2 in a third query in a 5 node cluster. The
5 node cluster setup outperforms the one node implementation
1MarineTrafic is an open, community-based maritime information collection
project, which provides information services and allows tracking the movements
of any ship in the world. It is available at: https://www.marinetrafic.com
2Amazon Web Services, https://aws.amazon.com/
in each system although the reduction is much more noticeable
in PostgreSQL. Finally the results demonstrate that indexing
afects response times in query execution by reducing them at
half almost in all cases while the reduction is significantly lower
with the use of indexes in PostgreSQL.</p>
      <p>The document is structured as follows: Section 2 provides
details about the related work in spatio-temporal systems and
benchmark analysis; Section 4 describes the technology overview;
Section 4 describes the evaluation of spatio-temporal database
systems used; Section 5 presents the experimental results while
Section 6 presents the final conclusions of this study and future
work.
2</p>
    </sec>
    <sec id="sec-2">
      <title>RELATED WORK</title>
      <p>The volume of spatial data is increasing exponentially on a daily
basis. Geospatial services such as GPS systems, Google Maps
and NASA’s Earth Observing system are producing terabytes of
spatial data every day and in combination with the growing
popularity of location-based services and map-based applications,
there is an increasing demand in the spatial support of databases
systems. There are challenges in managing and querying the
massive scale of spatial data such as the high computation complexity
of spatial queries and the eficient handling the big data nature
of them. There is a need for an interactive performance in terms
of response time and a scalable architecture. Benchmarks play a
crucial role in evaluating the performance and functionality of
spatial databases both for commercial users and developers.</p>
      <p>
        In [
        <xref ref-type="bibr" rid="ref16">16</xref>
        ] are presented some database benchmarks such as
Wisconsin which was developed for the evaluation of relational
database systems [
        <xref ref-type="bibr" rid="ref16">16</xref>
        ], AS3AP that contains a mixed workload of
database transactions, queries and utility functions and SetQuery
that supports more complex queries and designed to evaluate
systems that support decisions making. Above benchmarks
measure the performance of the system in general, but there are also
benchmarks that are explicitly designed to evaluate the
capabilities of spatio-temporal databases such as SEQUOIA 2000 [
        <xref ref-type="bibr" rid="ref17">17</xref>
        ]
and Paradise Geo-Spatial DBMS (PGS-DBMS) [
        <xref ref-type="bibr" rid="ref18">18</xref>
        ]. SEQUOIA
2000 propose a set of 11 queries to evaluate the performance
while PGS-DBMS presents 14 queries (the first nine queries are
the same in both benchmark systems). Although above
benchmarks seems to be adequate to evaluate a spatial database, things
change when the evaluation consists the temporal factor. Only
a few queries from both benchmarks have a temporal
component. The 3-Dimensional spatio-temporal benchmark, expands
the benchmarks into 3 dimensions in order to simulate real life
scenarios. The main diference from the other systems is the
addition of two new features: temporal processing/temporal updates
and three dimensional support.
      </p>
      <p>
        Another benchmark for spatial database evaluation is
presented in [
        <xref ref-type="bibr" rid="ref19">19</xref>
        ]. Although a number of other benchmarks limited
to a specific database or application, Jackpine presents one
important feature, portability in terms that can support any database
(JDBC driver implementation). It supports micro benchmarking
that is a number of spatial queries, analysis and loading
functions with spatial relationships and macro benchmarking with
queries which address real world problems. Also includes all
vector queries from the SEQUOIA 2000 benchmark.
      </p>
      <p>
        In [
        <xref ref-type="bibr" rid="ref20">20</xref>
        ] the authors compare five Spark based spatial
analytics systems (SpatialSpark, GeoSpark, Simba, Magellan,
LocationSpark) using five diferent spatial queries (range query, kNN
query, spatial joins between various geometric datatypes,
distance join, and kNN join) and four diferent datatypes (points,
linestrings, rectangles, and polygons). In order to evaluate these
modern, in-memory spatial systems, real world datasets are used
and the experiments are focusing on major features that are
supported by the systems. The results show the strengths and
weaknesses of the compared systems. In specific, GeoSpark seems
to be the most complete spatial analytic system because of data
types and queries supported.
      </p>
      <p>
        In [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ] are presented and evaluated two distributed database
technologies, GeoMESA which focuses on geotemporal indexes
and Elasticsearch which is a document oriented data store that
can handle arbitrary data which may have a geospatial index. In
general GeoMesa is an open-source, distributed, spatio-temporal
database built on a number of distributed cloud data storage
systems, including Accumulo, HBase, Cassandra, and Kafka. It
can provide spatio-temporal indexing for BigTable and its clones
(HBase, Apache Accumulo) using space filling curves to project
multi-dimensional spatio-temporal data into the single dimension
linear key space imposed by the database. On the other hand
Elasticsearch uses Z-order spatial-prefix-based indexes that work
for all types of vector data (points, lines and polygons) as well as
a Balanced KD-tree which works better for point data. For batch
processing, GeoMESA leverages Apache Spark and for stream
geospatial event processing, Apache Storm and Apache Kafka.
      </p>
      <p>
        A computing system for processing large-scale spatial data
called GeoSpark, is presented in [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ]. Apache Spark is an
inmemory cluster computing system that provides a data
abstraction called Resilient Distributed Datasets (RDDs) which consist
of collections of objects partitioned across a cluster. The main
drawback is that it does not support spatial operation on data.
This gap is filled by GeoSpark which extends the core of Apache
Spark to support spatial data types, spatial indexes and
computations. GeoSpark provides a set of out-of-the-box Spatial Resilient
Distributed Dataset (SRDD) types that provide support for
geometrical and distance operations and spatial data index strategies
which partition the SRDDs using a grid structure and thereafter
assign grids to machines for parallel execution.
      </p>
      <p>
        SMASH [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] is a highly scalable cloud based solution and the
technologies involved with SMASH architecture are: GeoServer,
GeoMesa, Apache Accumulo, Apache Spark and Apache Hadoop.
SMASH is a collection of software components that work
together in order to create a complete framework which can tackle
issues such as fetching, searching, storing and visualizing the data
directly for the demands of trafic analytics. For spatio-temporal
indexing on geospatial data, GeoMesa and GeoServer are used.
GeoMesa provides spatio-temporal indexing on top of the
Accumulo BigTable DBMS and is able to provide high levels of spatial
querying and data manipulation, leveraging a highly parallel
indexing strategy using a geohashing algorithm (three-dimensional
Z-order curve). GeoServer is used to serve maps and vector data
to geospatial clients and allows users to share, process and edit
geospatial data.
      </p>
      <p>
        Finally in [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] is presented a system called Hadoop-GIS, a
scalable and high performance spatial data warehousing
system which can eficiently perform large scale spatial queries on
Hadoop. It provides spatial data partitioning for task
parallelization through MapReduce, an index-driven spatial query engine
to support various types of spatial queries (point, join,
crossmatching and nearest neighbor), an expressive spatial query
language by extending HiveQL with spatial constructs and boundary
handling to generate correct results. In order to achieve high
performance, the system partitions time consuming spatial query
components into smaller tasks and process them in parallel while
preserving the correct query semantics.
3
      </p>
    </sec>
    <sec id="sec-3">
      <title>TECHNOLOGY OVERVIEW</title>
      <p>In order to evaluate the set of spatio-temporal queries, two
different systems are employed and compared: MongoDB and
PostgreSQL with PostGIS extension.</p>
      <p>
        MongoDB [
        <xref ref-type="bibr" rid="ref21">21</xref>
        ] is an open source document based NoSQL
datastore which is supported commercial by 10gen. Although
MongoDB is non-relational, it implements many features of relational
databases, such as sorting, secondary indexing, range queries and
nested document querying. Operators like create, insert, read,
update and remove as well as manual indexing, indexing on
embedded documents and index location-based data also supported.
In such systems, data are stored in collections called documents
which are entities that provide some structure and encoding on
the managed data. Each document is essentially an associative
array of a scalar value, lists or nested arrays. Every document has
a unique special key "ObjectId", used for explicitly identification
while this key and the corresponding document are conceptually
similar to a key-value pair. MongoDB documents are serialized
naturally as Javascript Object Notation (JSON) objects and stored
internally using a binary encoding of JSON called BSON [
        <xref ref-type="bibr" rid="ref22">22</xref>
        ].
As all NoSQL systems, in MongoDB there are no schema
restrictions and can support semi-structured data and multi-attribute
lookups on records which may have diferent kinds of key-value
pairs [
        <xref ref-type="bibr" rid="ref23">23</xref>
        ]. In general, documents are semi-structured files like
XML, JSON, YALM and CSV. For data storing there are two ways:
a) nesting documents inside each other, an option that can work
for one-to-one or one-to-many relationships and b) reference
to documents, in which the referenced document only retrieved
when the user requests data inside this document. To support
spatial functionality, data are stored in GeoJSON which is a
format for encoding a variety of geographical data structures [
        <xref ref-type="bibr" rid="ref24">24</xref>
        ].
GeoJSON supports: a) Geometry types as Point, LineString,
Polygon, MultiPoint, MultiLineString and MultiPolygon, b) Feature,
which is a geometric object with additional properties and c)
FeatureCollection, which consist a set of features. Each GeoJSON
document is composed of two fields: i) Type, the shape being
represented, which informs a GeoJSON reader how to interpret
the "coordinates" field and ii) Coordinates, an array of points, the
particular arrangement of which is determined by "type" field.
The geographical representation need to follow the GeoJSON
format structure in order to be able to set a geospatial index on the
geographic information. First, MongoDB computes the geohash
values for the coordinate pairs and then indexes these geohash
values. Indexing is an important factor to speed up query
processing. MongoDB provides BTree indexes to support specific
types of data and queries such as: Single Field, Compound Index,
Multikey Index, Text Indexes, Hashed Indexes and Geospatial
Index. To support eficient queries on geospatial coordinate data,
MongoDB provides two special indexes: 2d index that uses planar
geometry when returning results and 2dsphere index that use
spherical geometry to return results. A 2dsphere index supports
queries that calculate geometries on an earth-like sphere and
can handle all geospatial queries: queries for inclusion,
intersection and proximity. It supports four geospatial query operators
for spatio-temporal functionality: $geoIntersects, $geoWithin,
$near and $nearSphere and uses the WGS84 reference system for
geospatial queries on GeoJSON objects.
      </p>
      <p>On the other hand, PostgreSQL is an open source
objectrelational database system (ORDBMS). There is a special
extension available called PostGIS that integrates several
geofunctions and supports geographic objects. PostGIS implementation
is based on "light-weight" geometries and the indexes are
optimized to reduce disk and memory usage. The interface language
of the PostgreSQL database is the standard SQL. PostGIS has
the most comprehensive geofunctionalities with more than one
thousand spatial functions. It supports geometry types for Points,
LineStrings, Polygons, MultiPoints, MultiLineStrings,
MultipPolygons and GeometryCollections. There are several spatial
operators for geospatial measurements like area, distance, length
and perimeter. PostgreSQL supports several types of indexes such
as: BTree, Hash, Generalized Inverted Indexes (GIN) and
Generalized Search Tree (GiST) called R-tree-over-GiST. The default
index type is BTree that can work with all datatypes and can
be used for equality and range queries eficiently. For general
balanced tree structures and high-speed spatial querying,
PostgreSQL uses GiST indexes that can be used to index geometric
data types, as well as full-text search.</p>
      <p>Feature
ship_id
latitude, longitude
status
speed
course
heading
timestamp</p>
      <p>Description
Unique identifier for each ship
Geographical location in digital
degrees
Current position status
Speed over ground in knots
Course over ground in degrees
with 0 corresponding to north
Ship’s heading in degrees with
0 corresponding to north</p>
      <p>Full UTC timestamp
(1) Find coordinates of diferent amount of vessels from 1/May/
2016 - 31/July/2016 (entire time window) within the whole
bounded area, Q1</p>
      <p>Specifically, Q1 fetches coordinates for an increased amount
of vessels as shown in Table 2. The query is performed for all
unique vessels in the dataset, for half of them, for 1/4 and finally
for 1/8 of them, in order to examine the scalability of the
database systems. Q2 fetches coordinates of vessels for diferent time
windows; 1 day, 10 days, 1 month and 2 months as shown in
Table 3. Q3 fetches coordinates for diferent geographical polygons
as shown in Table 4. The polygons (polygon1.F, polygon2.F,
polygon1.S, polygon2.S) are bounding boxes within Mediterranean
Sea. Figure 1 shows a graphical representation of these polygons
with the trajectories of the vessels inside. We used QGIS 3, a tool
that visualize, analyses and publish geospatial information.
4.3</p>
    </sec>
    <sec id="sec-4">
      <title>System Architecture</title>
      <p>We have deployed a MongoDB cluster that contains a master
node server (primary) and four replication slaves (secondaries)
in Replica Set mode. One way to achieve replication in MongoDB
3QGIS: A Free and Open Source Geographic Information System,
https://qgis.org/en/site/
Polygons
polygon2.S
polygon1.S
polygon2.F
polygon1.F
is by using replica set. While MongoDB ofers standard
primarysecondary replication, it is more common to use MongoDB’s
replica sets. A replica set is a group of multiple coordinated
instances that host the same dataset and work together to ensure
superior availability. In a replica set, only one node acts as
primary that receives all write operations while the other instances
called secondaries and apply operations from the primary. All
data are replicated from the primary to secondary nodes. If the
primary node ever fails or becomes unavailable or maintained,
one of the replicas will automatically be elected through a
consortium as the replacement. After the recovery of failed node, it
joins the replica set again and works this time as a secondary
node.</p>
      <p>
        The problem with replica set configuration is the selection
of a member to perform a query in case of read requests. The
question is which node to choose, the primary or a secondary
and if a request queries a secondary, which one should be used. In
MongoDB it is possible to control this choice with read preferences
solution. When an application queries a replica set, there is the
opportunity to trade of consistency, availability, latency and
throughput for each kind of query. This is the problem that read
preferences solve: how to specify the read preferences among
above trade ofs, so the request falls to the best member of the
replica set for each query. For the distribution of queries, the
read preference provides the solution. The categories of read
preferences are: i) PRIMARY: Read from the primary, ii) PRIMARY
PREFERRED: Read from the primary if available, otherwise read
from a secondary, iii) SECONDARY: Read from a secondary, iv)
SECONDARY PREFERRED: Read from a secondary if available,
otherwise from the primary and finally v) NEAREST: Read from
any available member. Because our goal is to achieve maximum
throughput and an evenly distribution of load across the members
of the set we used NEAREST preference and we set the value
secondary_acceptable_latency_ms very high in 500ms. This value
is used in MongoDB to track each member’s ping time and queries
only the "nearest" member, or any random member that is no
more than the default value of 15ms "farther" than it. In general,
load balancing and query distribution consist one of the most
important factors in distributed systems. An even distribution of
load within the nodes of the system reduces the probability that a
node turns to a hotspot and his property also acts as a safeguard
to the system reliability [
        <xref ref-type="bibr" rid="ref25">25</xref>
        ].
      </p>
      <p>Additionally, we have deployed a PostgreSQL cluster that
contains a master server and four slaves in Streaming Replication
mode. Slaves keep an exact copy of master’s data, apply the
stream to their data and staying in a "Hot Standby" mode, ready
to be promoted as master in case of failure. Streaming
replication is a good tactic for data redundancy between nodes but for
load balancing a mechanism is required that splits the requests
between the copies of data. For this reason we use Pgpool-24, a
4Pgpool-2, http://www.pgpool.net/mediawiki/index.php/Main_Page
middleware that works between PostgreSQL servers and a
PostgreSQL database client. Pgpool-2 examines each query and if
the query is read only, it is forwarded to one of the slave nodes
otherwise in case of write it is forwarded to the master server.
With this congfiuration the read load splits between the slave
nodes of the cluster, achieving thus an improved system
performance. Pgpool-2 provides the following features, Connection
Pooling: connections are saved and reused whenever a new
connection with the same properties arrives, thus reducing
connection overhead and improving system throughput, Replication:
replication creates a real time backup on physical disks, so that
the service can continue without stopping servers in case of a
disk failure, Load Balancing: the load on each server is reduced
by distributing SELECT queries among multiple servers, thus
improving system’s overall throughput and Limiting Exceeding
Connections: connections are rejected after a limit on the
maximum number of concurrent connections.
4.4</p>
    </sec>
    <sec id="sec-5">
      <title>Data Ingestion</title>
      <p>The dataset used for the experiments was initially in CSV format.
As we mentioned above, in MongoDB the geographical
representation needs to follow the GeoJSON format structure in order
to be able to set a geospatial index on the geographic
information, thus the first step was the conversion of the data into the
appropriate format. For data ingestion we used the mongoimport
tool to import data into MongoDB database. The total size the
dataset occupied in the collection in MongoDB is 116 GB and
each record has a size of about 275 bytes.</p>
      <p>
        In PostgreSQL there is a copy mechanism for bulk loading
data that can achieve a good throughput. The data must be in
CSV format and the command can accept a number of delimiters.
The next step after data loading into database, is the conversion
of latitude and longitude columns to PostGIS POINT geometry.
These columns must be converted into geometry data which
subsequently can be spatially queried. We created a column called
the_geom using a defined PostGIS function, which in essence
contains the POINT geometry created from latitude and longitude
of each record. The spatial reference ID (SRID) of the geometry
instance (latitude, longitude) is 4326 (WGS84). The World
Geodetic System (WGS) is the defined geographic coordinate system
(three-dimensional) for GeoJSON used by GPS to express
locations on the earth. The latest revision is WGS 84 (also known as
WGS 1984, EPSG:4326) [
        <xref ref-type="bibr" rid="ref26">26</xref>
        ]. The total size the dataset occupied
in PostgreSQL db is 32 GB and each row’s size is about 96 bytes
while in MongoDB is almost 4 times larger.
      </p>
      <p>The reason for this behavior is that the data stored in
MongoDB are in GeoJson format and each record consist of many
extra characters and a unique auto created id called ObjectId.
Thus, each record is significant bigger in size than it was in its
original CSV format. On the other hand, in PostgreSQL the data
ingested in database as CSV, with the addition of the_geom
column that contains the POINT geometries of each latitude and
longitude.
4.5</p>
    </sec>
    <sec id="sec-6">
      <title>Cluster Setup - AWS</title>
      <p>To benchmark MongoDB and PostgreSQL we deployed each
database system on Amazon Web Services (AWS) EC2 instances.
For storing the dataset, we used the S3 bucket provided also by
AWS. The configuration used is described below:</p>
      <p>MongoDB. The MongoDB cluster consists of 5 x r4.xlarge
instances within a Virtual Private Cloud (Amazon VPC). One
node is the primary and the other played the role of the replicas.
We installed MongoDB 3.6.5 version in Replica Set mode. Each
instance operates on Amazon Linux 2 AMI OS and consist of 4
CPUs x 2.30 GHz, 30.5 GB DDR4 RAM, 500 GB of general purpose
SSD storage type EBS, up to 10 Gigabit network performance
and IPv6 support. Amazon Elastic Block Store (Amazon EBS)
provides persistent block storage volumes for use with Amazon EC2
instances in the AWS Cloud. Each EBS volume is automatically
replicated within its Availability Zone to protect from
component failures, thus ofering high availability and durability. Also
the instances are EBS-optimized which means that they provide
additional throughput for EBS I/O and as a result an improved
performance.</p>
      <p>PostgreSQL. Exactly the same configuration is used in
PostgreSQL. We installed PostgreSQL 9.5.13 and PostGIS 2.2.1 in
streaming replication mode. One node is the master while the
others play the role of slaves. Also an extra instance for Pgpool-2
was deployed.
5</p>
    </sec>
    <sec id="sec-7">
      <title>EXPERIMENTS</title>
      <p>This section contains a detailed experimental evaluation that
examines the run time performance of the spatio-temporal queries Q1,
Q2 and Q3 in MongoDB and PostgreSQL through seven
experiments. Five consecutive separate calls are conducted, in order to
gather the experimental results and collect the average values
concerning response time of above queries in diferent case
scenarios. We compare the response time in a 5-node cluster versus
a 1-node implementation. We also test the settings when indices
are used against the case that they are not.</p>
      <p>For Q1 a regular BTree index is created in MongoDB and
PostgreSQL for attribute "ship_id". The size of index varies between
the diferent database systems. In MongoDB the index size is
about 6 GB while in PostgreSQL the size is 3,1 GB. For Q2 we
implemented also a BTree index of size 6 GB in both DBMSs for
attribute "timestamp". Finally, for Q3 we implemented an index
in field "$geometry" in MongoDB with size 6 GB. As mentioned
above the data are stored in MongoDB as GeoJSON and the
"$geometry" field that is created contains the coordinates values,
latitude and longitude. Because these data are geographical, we
create a 2dsphere index type which supports geospatial queries.
In PostgreSQL we created an index of type GiST in field the_geom
which contains the POINT geometry created from latitude and
longitude of each record with size 8,2 GB. For high-speed
spatial querying, PostgreSQL uses GiST indexes that can be used to
index geometric data types. The index size varies between the
two database systems even for the same attribute that performed.
The two systems store data diferently and the concept of "index"
is diferent too.</p>
      <p>Figure 2 illustrates the average response time concerning the
set of queries Q1, Q2 and Q3 in 5 node cluster between MongoDB
and PotgreSQL. It’s quite clear that PostgreSQL outperforms
MongoDB by a large extent in all queries. The response time is
almost 4 times faster in some cases (Q2, Q3) comparing to
MongoDB. Only in Q1 the response time presents smaller fluctuations
between the DBMSs. Exactly the same behavior is observed in
the 1 node implementation as shown in Figure 3. The response
time is significant lower in case of PostgreSQL.</p>
      <p>Subsequently, we compared the average response time in the
set of queries for the 5-nodes cluster versus the 1-node
implementation for the two database systems as shown in Figure 4 and
Figure 5 respectively. The results show that the average response
5481
10822
21644
43288
1 day
MongoDB PostgreSQL
MongoDB PostgreSQL
MongoDB PostgreSQL
3,000
) 2,500
sce
(e 2,000
m
i
T
sen 1,500
sop
eR1,000
500
0
3,000
) 2,500
sce
(e 2,000
m
i
T
sen 1,500
sop
eR1,000
500
0
3,000
) 2,500
sce
(e 2,000
m
i
T
sen 1,500
sop
eR1,000
500
0
1,000
)ce 800
(se
iTm 600
seon
sep 400
R
200
0
(a)
(a)
(a)
(a)</p>
      <p>MongoDB 1 node MongoDB 5 nodes
5481
10822
21644
43288
1 day
3,000
2,000
1,000
0
(b)
1,200
1,000
800
600
400
200
0
MongoDB_NoIndex MongoDB_BTree
MongoDB_NoIndex MongoDB_2D_sphere
1 day
4.6
4.4
4.2
4
3.8
3.6
3.4
3.2 1 day
5481
10822
21644</p>
      <p>43288
time presents a small reduction when the experiments are
performed in a 5-node MongoDB cluster versus the 1-node
implementation. The reduction is much more noticeable in the case of
PostgreSQL. The reason is that in the MongoDB replica set, the
client requests are distributed using the read preference-Nearest
option that can achieve a maximum throughput and an evenly
distribution of load across the members of the set. In case of
PostgreSQL, with the use of Pgpool-2 the load of read requests
is distributed between the nodes of the cluster in a much more
efective way, thus improving system’s overall throughput.</p>
      <p>In the next set of experiments we examined how indexes afect
the response time in queries execution. As shown in Figure 6 the
reduction is significantly lower, almost at half with the use of
indexes in PostgreSQL. An index allows the database server to
ifnd and retrieve specific rows much faster than without an index.
In Figure 7 concerning MongoDB we excluded Q1 because the
response time was extremely high in case of no index (&gt; 4 hours).
In the remaining queries, also the response time is significantly
reduced. Eficient query execution in MongoDB is supported using
indexing. MongoDB can use indices to limit the number of
documents it must inspect otherwise a scan operation is performed in
every document in a collection, to select those documents that
match the query statement (collection scan). Figure 8 presents
the average speedups of PostgreSQL comparing to MongoDB in
5 node cluster with the use of indexes. As it shown the average
speedup concerning Q1 is almost 2, 4 in case of Q2 and 4,2 in Q3.</p>
    </sec>
    <sec id="sec-8">
      <title>6 CONCLUSIONS</title>
      <p>In this paper, we analyzed and compared the performance in
terms of response time between two diferent database systems,
a document-based NoSQL datastore, MongoDB, and an
opensource object-relational database system, PostgreSQL with
PostGIS extension. Each database system was deployed on Amazon
Web Services (AWS) EC2 cluster instances. We employed a replica
set and a streaming replication cluster setup for MongoDB and
PostgreSQL system respectively. For the evaluation between the
two systems, we employed a set of spatio-temporal queries that
mimic real world scenarios and present spatial and temporal
predicates, with the use of a dataset which was provided to us
by the community based AIS vessel tracking system (VTS) of
MarineTrafic.
300
200
100
0</p>
      <p>The performance is measured in terms of response time in
diferent case scenarios; in a 5 node cluster versus 1 node
implementation and with the use of indexes versus not. The results
are show that PostgreSQL outperforms MongoDB in all cases
and queries and presents an average speedup around 2 in first
query, 4 in second query and 4,2 in third query in a five node
cluster. Also, the replica set mode implementation of 5 nodes
in MongoDB as well as the streaming replication of 5 nodes in
PostgreSQL outperforms the one node implementation in each
system respectively. Subsequently, as demonstrated by the
experimental results, the average response time is significantly reduced
at half, almost in all cases with the use of indexes while again
the reduction is significantly lower in PostgreSQL. Finally, the
dataset size occupied in the system db, reduced 4x in case of
PostgreSQL, since it stores data in a more efective way.</p>
      <p>Our future plan include the extension of our system
architecture to what it is called Shared Cluster. A Shared Cluster consists
of shards which in turn contain a subset of the sharded data.
Sharding is a method for distributing data across multiple
machines. Every machine contains only a portion of the shared data
and each machine replicated to secondaries nodes for data
redundancy and for fault tolerance reasons. We plan to evaluate and
compare the two types of cluster and draw conclusions of which
system is best for diferent cases.</p>
    </sec>
    <sec id="sec-9">
      <title>ACKNOWLEDGMENTS</title>
      <p>The research work was supported by the Hellenic Foundation
for Research and Innovation (HFRI) and the General Secretariat
for Research and Technology (GSRT), under the HFRI PhD
Fellowship grant (GA. no. 2158).</p>
      <p>This work has been developed in the frame of the MASTER
project, which has received funding from the European Union’s
Horizon 2020 research and innovation programme under the
Marie Skłodowska-Curie grant agreement No 777695.</p>
      <p>This work was supported in part by MarineTrafic which
provided data access for research purposes.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>G</given-names>
            <surname>Leptoukh</surname>
          </string-name>
          .
          <article-title>Nasa remote sensing data in earth sciences: Processing, archiving, distribution, applications at the ges disc</article-title>
          .
          <source>In Proc. of the 31st Intl Symposium of Remote Sensing of Environment</source>
          ,
          <year>2005</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          <article-title>[2] Telescope hubble site</article-title>
          . http://hubble.stsci.edu/the_telescope/hubble_essentials/ quick_facts.php.
          <source>Accessed: 2018-7-15.</source>
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          <article-title>[3] Automatic dependent surveillance-broadcast (ads-b)</article-title>
          . https://www.faa.gov/ nextgen/programs/adsb/.
          <source>Accessed: 2018-7-15.</source>
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>Iraklis</given-names>
            <surname>Varlamis</surname>
          </string-name>
          , Konstantinos Tserpes, and
          <string-name>
            <given-names>Christos</given-names>
            <surname>Sardianos</surname>
          </string-name>
          .
          <article-title>Detecting search and rescue missions from ais data</article-title>
          .
          <source>In 2018 IEEE 34th International Conference on Data Engineering Workshops (ICDEW)</source>
          . IEEE,
          <year>2018</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>Luke</given-names>
            <surname>Sloan</surname>
          </string-name>
          and Jefrey Morgan.
          <article-title>Who tweets with their location? understanding the relationship between demographic characteristics and the use of geoservices and geotagging on twitter</article-title>
          .
          <source>PloS one</source>
          ,
          <volume>10</volume>
          (
          <issue>11</issue>
          ):
          <fpage>e0142209</fpage>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>Ablimit</given-names>
            <surname>Aji</surname>
          </string-name>
          , Fusheng Wang, Hoang Vo,
          <string-name>
            <given-names>Rubao</given-names>
            <surname>Lee</surname>
          </string-name>
          , Qiaoling Liu, Xiaodong Zhang, and
          <string-name>
            <given-names>Joel</given-names>
            <surname>Saltz</surname>
          </string-name>
          .
          <article-title>Hadoop gis: a high performance spatial data warehousing system over mapreduce</article-title>
          .
          <source>Proceedings of the VLDB Endowment</source>
          ,
          <volume>6</volume>
          (
          <issue>11</issue>
          ):
          <fpage>1009</fpage>
          -
          <lpage>1020</lpage>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>Ahmed</given-names>
            <surname>Eldawy and Mohamed F Mokbel. Spatialhadoop</surname>
          </string-name>
          :
          <article-title>A mapreduce framework for spatial data</article-title>
          .
          <source>In Data Engineering (ICDE)</source>
          ,
          <year>2015</year>
          IEEE 31st International Conference on, pages
          <fpage>1352</fpage>
          -
          <lpage>1363</lpage>
          . IEEE,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>Shoji</given-names>
            <surname>Nishimura</surname>
          </string-name>
          ,
          <string-name>
            <surname>Sudipto Das</surname>
          </string-name>
          ,
          <string-name>
            <surname>Divyakant Agrawal</surname>
          </string-name>
          , and Amr El Abbadi.
          <article-title>Mdhbase: design and implementation of an elastic data infrastructure for cloudscale location services</article-title>
          .
          <source>Distributed and Parallel Databases</source>
          ,
          <volume>31</volume>
          (
          <issue>2</issue>
          ):
          <fpage>289</fpage>
          -
          <lpage>319</lpage>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>Andrew</given-names>
            <surname>Hulbert</surname>
          </string-name>
          , Thomas Kunicki, James N Hughes,
          <string-name>
            <surname>Anthony D Fox</surname>
          </string-name>
          , and
          <string-name>
            <surname>Christopher N Eichelberger</surname>
          </string-name>
          .
          <article-title>An experimental study of big spatial data systems</article-title>
          .
          <source>In Big Data (Big Data)</source>
          ,
          <source>2016 IEEE International Conference on</source>
          , pages
          <fpage>2664</fpage>
          -
          <lpage>2671</lpage>
          . IEEE,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <surname>Yikai</surname>
            <given-names>Gong</given-names>
          </string-name>
          , Luca Morandini, and Richard O Sinnott.
          <article-title>The design and benchmarking of a cloud-based platform for processing and visualization of trafic data</article-title>
          .
          <source>In Big Data and Smart Computing (BigComp)</source>
          ,
          <source>2017 IEEE International Conference on</source>
          , pages
          <fpage>13</fpage>
          -
          <lpage>20</lpage>
          . IEEE,
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <surname>Simin</surname>
            <given-names>You</given-names>
          </string-name>
          , Jianting Zhang, and
          <string-name>
            <given-names>Le</given-names>
            <surname>Gruenwald</surname>
          </string-name>
          .
          <article-title>Large-scale spatial join query processing in cloud</article-title>
          .
          <source>In 2015 31st IEEE International Conference on Data Engineering Workshops (ICDEW)</source>
          , pages
          <fpage>34</fpage>
          -
          <lpage>41</lpage>
          . IEEE,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>Ameet</given-names>
            <surname>Kini</surname>
          </string-name>
          and
          <string-name>
            <given-names>Rob</given-names>
            <surname>Emanuele</surname>
          </string-name>
          . Geotrellis:
          <article-title>Adding geospatial capabilities to spark</article-title>
          .
          <source>Spark Summit</source>
          ,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <surname>Jia</surname>
            <given-names>Yu</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Jinxuan Wu</surname>
            , and
            <given-names>Mohamed</given-names>
          </string-name>
          <string-name>
            <surname>Sarwat</surname>
          </string-name>
          .
          <article-title>Geospark: A cluster computing framework for processing large-scale spatial data</article-title>
          .
          <source>In Proceedings of the 23rd SIGSPATIAL International Conference on Advances in Geographic Information Systems, page 70. ACM</source>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <given-names>Peter</given-names>
            <surname>Membrey</surname>
          </string-name>
          , Eelco Plugge, Tim Hawkins, and
          <string-name>
            <given-names>DUPTim</given-names>
            <surname>Hawkins</surname>
          </string-name>
          .
          <article-title>The deifnitive guide to MongoDB: the noSQL database for cloud and desktop computing</article-title>
          . Springer,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <given-names>Neil</given-names>
            <surname>Matthew</surname>
          </string-name>
          and Richard Stones.
          <article-title>Beginning Databases with PostgreSQL</article-title>
          .
          <source>Apress</source>
          ,
          <year>2005</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          [16]
          <string-name>
            <surname>David J DeWitt.</surname>
          </string-name>
          <article-title>The wisconsin benchmark: Past, present, and future</article-title>
          .,
          <year>1993</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          [17]
          <string-name>
            <given-names>Michael</given-names>
            <surname>Stonebraker</surname>
          </string-name>
          , Jim Frew, Kenn Gardels, and
          <string-name>
            <given-names>Jef</given-names>
            <surname>Meredith</surname>
          </string-name>
          .
          <article-title>The sequoia 2000 storage benchmark</article-title>
          .
          <source>In ACM SIGMOD Record</source>
          , volume
          <volume>22</volume>
          , pages
          <fpage>2</fpage>
          -
          <lpage>11</lpage>
          . ACM,
          <year>1993</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          [18]
          <string-name>
            <surname>Jignesh</surname>
            <given-names>Patel</given-names>
          </string-name>
          , JieBing Yu, Navin Kabra, Kristin Tufte, Biswadeep Nag, Josef Burger, Nancy Hall, Karthikeyan Ramasamy, Roger Lueder,
          <string-name>
            <given-names>Curt</given-names>
            <surname>Ellmann</surname>
          </string-name>
          , et al.
          <article-title>Building a scaleable geo-spatial dbms: technology, implementation, and evaluation</article-title>
          .
          <source>In ACM SIGMOD Record</source>
          , volume
          <volume>26</volume>
          , pages
          <fpage>336</fpage>
          -
          <lpage>347</lpage>
          . ACM,
          <year>1997</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          [19]
          <string-name>
            <surname>Suprio</surname>
            <given-names>Ray</given-names>
          </string-name>
          , Bogdan Simion, and Angela Demke Brown. Jackpine:
          <article-title>A benchmark to evaluate spatial database performance</article-title>
          .
          <source>In Data Engineering (ICDE)</source>
          ,
          <year>2011</year>
          IEEE 27th International Conference on, pages
          <fpage>1139</fpage>
          -
          <lpage>1150</lpage>
          . IEEE,
          <year>2011</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          [20]
          <string-name>
            <surname>Varun</surname>
            <given-names>Pandey</given-names>
          </string-name>
          , Andreas Kipf, Thomas Neumann, and
          <string-name>
            <given-names>Alfons</given-names>
            <surname>Kemper</surname>
          </string-name>
          .
          <article-title>How good are modern spatial analytics systems?</article-title>
          <source>Proceedings of the VLDB Endowment</source>
          ,
          <volume>11</volume>
          (
          <issue>11</issue>
          ):
          <fpage>1661</fpage>
          -
          <lpage>1673</lpage>
          ,
          <year>2018</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref21">
        <mixed-citation>
          [21]
          <string-name>
            <surname>Mongodb</surname>
          </string-name>
          . https://www.mongodb.com/.
          <source>Accessed: 2018-7-15.</source>
        </mixed-citation>
      </ref>
      <ref id="ref22">
        <mixed-citation>
          [22]
          <article-title>Binary json</article-title>
          . http://bsonspec.org/.
          <source>Accessed: 2018-7-15.</source>
        </mixed-citation>
      </ref>
      <ref id="ref23">
        <mixed-citation>
          [23]
          <string-name>
            <surname>Antonios</surname>
            <given-names>Makris</given-names>
          </string-name>
          , Konstantinos Tserpes, Vassiliki Andronikou, and
          <string-name>
            <given-names>Dimosthenis</given-names>
            <surname>Anagnostopoulos</surname>
          </string-name>
          .
          <article-title>A classification of nosql data stores based on key design characteristics</article-title>
          .
          <source>Procedia Computer Science</source>
          ,
          <volume>97</volume>
          :
          <fpage>94</fpage>
          -
          <lpage>103</lpage>
          ,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref24">
        <mixed-citation>
          [24]
          <article-title>The geojson format specification</article-title>
          . http://geojson.org/geojson-spec.
          <source>html. Accessed: 2018-7-15.</source>
        </mixed-citation>
      </ref>
      <ref id="ref25">
        <mixed-citation>
          [25]
          <string-name>
            <surname>Antonios</surname>
            <given-names>Makris</given-names>
          </string-name>
          , Konstantinos Tserpes, and
          <string-name>
            <given-names>Dimosthenis</given-names>
            <surname>Anagnostopoulos</surname>
          </string-name>
          .
          <article-title>A novel object placement protocol for minimizing the average response time of get operations in distributed key-value stores</article-title>
          .
          <source>In Big Data (Big Data)</source>
          ,
          <source>2017 IEEE International Conference on</source>
          , pages
          <fpage>3196</fpage>
          -
          <lpage>3205</lpage>
          . IEEE,
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref26">
        <mixed-citation>
          [26]
          <string-name>
            <given-names>B LOUIS</given-names>
            <surname>Decker</surname>
          </string-name>
          .
          <source>World geodetic system 1984</source>
          .
          <source>Technical report, Defense Mapping Agency Aerospace Center St Louis Afs Mo</source>
          ,
          <year>1986</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>