Full text
Escola Tècnica Superior d’Enginyeria Informàtica Universitat Politècnica de València Adapting a noSQL database for autoscaling on a PaaS environment Trabajo Fin de Grado Grado en Ingeniería Informática Autor: Fraseniuc, Bogdan-Alexandru Tutor: Bernabeu Aubán, José Manuel 2015-2016
Adapting a noSQL database for autoscaling on a PaaS environment 2
3 Resumen Este trabajo se afana en crear un servicio que ofrece la funcionalidad de un clúster fragmentado MongoDB y que al mismo tiempo es capaz de auto escalar dentro de una plataforma como servicio. La base de datos utilizada es MongoDB y la plataforma es Kumori PaaS. Esta solución tiene la ventaja de que permite al desarrollador de software centrarse más en la parte de desarrollo del servicio que en la gestión de la base de datos. Para alcanzar este objetivo se realiza un estudio sobre los mecanismos internos de MongoDB, se proporciona una vista general sobre cómo funciona Kumori PaaS y se crean dos aplicaciones de servicio. Estas aplicaciones de servicio tienen topologías distintas: una más simple que no soporta auto escalado pero que se usa para ver si MongoDB podría funcionar sobre esta plataforma, y una más compleja que se parece a la topología de un clúster fragmentado MongoDB y que además ofrece auto escalado. Palabras clave: Computación en la Nube, Bases de datos, NoSQL, autoescalado, PaaS. Abstract This project strives to create a service offering the functionality of a MongoDB sharded cluster while also being able to autoscale on a Platform-as-a-Service. The database used is MongoDB and the platform is the Kumori PaaS. The benefit of this solution is that it allows a software developer to focus more on the development of the service instead of the management of the database. In order to achieve this objective a study of the MongoDB internal mechanisms is done, an overall view of how the Kumori PaaS works is given and two service applications are created. These service applications have different topologies: a simple one which does not support autoscalability but is used to view if MongoDB can work on this platform, and a more complex one which resembles the topology of a MongoDB sharded cluster and also offers autoscalability. Keywords : Cloud Computing, Databases, NoSQL, autoscaling, PaaS.
Adapting a noSQL database for autoscaling on a PaaS environment 4
5 Table of contents 1. Introduction ................................................................................................................. 8 1.1 Scope ........................................................................................................................ 8 1.2 Objectives ................................................................................................................ 8 1.2 Document structure ................................................................................................ 9 2. MongoDB .................................................................................................................. 11 2.1 Introduction .............................................................................................................. 11 2.2 MongoDB Internals ................................................................................................... 11 2.2.1 Replication ............................................................................................................ 13 2.2.2 Sharding ................................................................................................................ 16 2.2.2.1 Sharding – Chunk Splitting .................................................................................. 17 2.2.2.1 Sharding – Chunk Migration ................................................................................ 18 3. Kumori PaaS ............................................................................................................. 22 3.1 Introduction ............................................................................................................. 22 3.2 ECloud service model and components...................................................................... 22 3.4 Service applications ................................................................................................. 24 4. Simple MongoDB Service .......................................................................................... 26 4.1 Introduction ............................................................................................................. 26 4.2 Topology ................................................................................................................. 26 4.3 Legacy servers .......................................................................................................... 27 5. Complex MongoDB Service ....................................................................................... 28 5.1 Topology ................................................................................................................. 28 5.2 Front-End ................................................................................................................ 29 5.3 Config server ........................................................................................................... 29 5.4 Shards ..................................................................................................................... 30 5.4 Query router ............................................................................................................. 31 6. Conclusions and future work ...................................................................................... 34 7. References .................................................................................................................. 37 8. Appendix .................................................................................................................. 38 8.1 Appendix A ............................................................................................................. 38 8.1 Appendix B ............................................................................................................. 40
Adapting a noSQL database for autoscaling on a PaaS environment 6 Table of figures Figure 1: MongoDB Nexus Architecture ....................................................................... 12 Figure 2: MongoDB three member replica set .............................................................. 14 Figure 3: MongoDB metadata ....................................................................................... 17 Figure 4: Chunk Splitting .............................................................................................. 18 Figure 5: Chunk Migration ............................................................................................ 19 Figure 6: Simple MongoDB Service topology .............................................................. 26 Figure 7: Complex MongoDB Service topology ............................................................ 28
7
Adapting a noSQL database for autoscaling on a PaaS environment 8 1. Introduction 1.1 Scope In this day and age, everything seems to be moving to the cloud, and this includes databases. One potential solution for someone wanting to deploy a database on the cloud is using a Platform as a System (PaaS). A PaaS is a category of cloud computing services which allows developers to create and test their applications without having to worry about the underlying infrastructure. This includes not having to worry about the network, the operating system, the storage, runtime environment or the database. The developer wants to spend time writing the code for the actual application or service; not work on the infrastructure, concern himself with backups, scalability or how to recover from crashes. This is what PaaS tries to offer, cover the entire lifecycle of the programmer’s application, allowing him to do what a developer should do, code. The work done in this project was realized during an internship at the Instituto Tecnológico de Informática (ITI) of the Universidad Politécnica de Valencia (UPV), working alongside the team who is currently developing this PaaS. 1.2 Objectives There are three main objectives defined: understand how MongoDB works internally, understand how Kumori PaaS works in order to build components and service applications for it, and create a service application serving a MongoDB sharded cluster which autoscales on the Kumori PaaS. The first objective two objectives are straightforward, before trying to adapt a technology and mold it to some specific needs, a good understanding of that technology is needed. The concepts explained about MongoDB are related to a database administrator’s point of view, since the main concern is how the database works internally and how to manage it, not how to code a user application which uses this database to store its data. The Kumori PaaS, as any other PaaS solution on the market, has to offer a database solution, be it relational (SQL) or non-relational (noSQL). In order to adapt MongoDB to work inside this PaaS and be able to autoscale, it is imperative to understand how components and services are modelled in this platform. The final objective is to build a service application which can offer the MongoDB sharded cluster functionality and more, autoscaling.
9 1.2 Document structure This document is structured in six chapters and the content of each chapter is detailed below. In the first chapter a brief introduction to the project is made and the reader is presented with the scope of this project followed by the objectives which it aims to achieve. The second chapter offers a brief explanation of MongoDB and some of its key elements and concepts, the objective of this chapter is to explain how replication and sharding is achieved. The third chapter offers insight on how the actual platform on which the MongoDB service application will be deployed, works. The fourth chapter describes a first approach to the design and implementation of the service. The fifth chapter presents the topology needed to achieve the objective proposed at the beginning of the project: adapt a noSQL database for autoscaling on a PaaS environment. The sixth chapter goes into detail about the conclusions and future work that still has to be done. There are two appendices: Appendix A: more details about manifests Appendix B: certain parts of the source code used and scripts
Adapting a noSQL database for autoscaling on a PaaS environment 16 2.2.2 Sharding In the previous subsection it has been explained how MongoDB achieves high availability by using replica sets. But what happens when the working set does not fit in the RAM, or the user application generates too many queries/operations. This is when horizontal scalability becomes relevant. In MongoDB, horizontal scalability is achieved by using sharding [8], [9]. The process of sharding is based on a simple idea: divide the data set into parts and put these parts on different servers. In order for sharding to work, another MongoDB core process is needed, apart from mongod and mongo. This third core process is called mongos and its main functionality is to route queries and write operations. It is the bridge that links the user applications to the sharded cluster, it presents users with a single view of the sharded database. By using replication, different members of a replica set have the same documents, the same data. A sharded cluster represents a set of shards, each shard being a replica set. Since the data is distributed among the different shards, this means that at any given point in time a document lives on only one shard. In replica sets, each replica set contains a primary and various secondary members, and all the members share the same data. When using a sharded cluster, each shard (replica set) contains only a part of the data. In order for the user to access the data, the mongos process must be used. This process is hosted on a new component called query router. The main issue now is on which criteria are the documents distributed to different shards, which steps are taken to split a collection and distribute its documents. To achieve this goal, each document in the same collection must have a unique indexed field. This will be the shard key. Each shard will host the documents which belong to a certain range of shard key values. This concept is explained easier by means of an example. Consider a collection made up of documents which all have a common unique field name. This field will be indexed and chosen as the shard key. The resulting chunks and their associated shard key ranges are considered metadata and can be viewed in the Figure 3 below.
17 Figure 3: MongoDB metadata The Figure 3 illustrates a map that describes how the documents are distributed and to which shard they belong; a chunk is represented by a shard key range which is contained in between an inclusive lower boundary, nameL, and an exclusive upper boundary, nameH. All the documents with values of the name field contained in this chunk are physically located on the shard S2. This metadata information is not hosted on the shards and neither on the query router. The query router only keeps a cached copy of this information. The metadata for the cluster is actually located on a component called config server, which runs a mongod process and is deployed as a replica set. Apart from the metadata, the config server also stores other settings for the cluster, such as authentication configuration. If this component loses its primary, the cluster metadata becomes read-only, unless a new primary is elected. If the cluster metadata is read-only the system can still attend read and write operations, but no new chunk migrations and chunk splits can be realized. Without the metadata the cluster can reach an inoperable state. 2.2.2.1 Sharding – Chunk Splitting This operation is initiated by the query router, it is the action which does the actual partition of the data. There is no real change to the data, it is a remapping, so it only affects the metadata. A sharded cluster can have more than one query router, they do not talk to each other and each one tracks writes to the chunks. This process is automatic: 1. When the data written reaches 20% of the defined max chunk size (default size is 64MB) the query router sends the splitVector command to the primary of the shard that owns the chunk. 2. The primary checks if the chunk can be split and calculates a list split points. 3. The primary returns a list of split points, it can be an empty list, to the query router. nameL •Alex •Kevin •Lana •... nameH •Kevin •Lana •Mary •... shard •S2 •S0 •S1 •...
Adapting a noSQL database for autoscaling on a PaaS environment 18 4. If the list is not empty, the query router updates the config server in order for the metadata to reflect the splits. 5. No data changed/moved. 6. If the split points list is empty the query router waits until 40% and it send the splitVector command again. The following Figure 4 represents the chunk splitting process. Manual splitting is also possible. By using the mongo shell, a connection can be established with a query router and the following commands can be used to split chunks manually: splitFind( “database.collection”, { “field”: “value” } ) – splits the chunk containing the first document which fulfills the query into two chunks of the same size. splitAt( “database.collection”, { “field”: “value” } ) – the document which fulfills the query will be the lower bound of the new chunk. These commands are needed in order to deal with so called jumbo chunks; these chunks cannot be split automatically because they exceed the maximum chunk size or the number of documents contained in the chunk exceeds the maximum allowed. 2.2.2.1 Sharding – Chunk Migration This process represents the actual movement of data from one shard to another. Different stages of the chunk migration are coordinated by the query router but the actual work is done by the primaries. The query router checks the config database on the config server and requests a balancing round in order to make sure that it can acquire the necessary locks and start the balancer. After acquiring the lock, the balancer proceeds to identify the imbalance (draining shards have more priority: shards which are being removed from the sharded cluster) and pick the chunk which has to be migrated and the migration procedure starts: Figure 4: Chunk Splitting
19 1. The balancer send the moveChunk command to the source shard. 2. The source shard performs sanity checks: check if the range for the chunk is valid, if the command is valid, if it is not already doing too many deletes from previous migrations. 3. The source shard initiates the transfer with an internal moveChunk command. 4. The destination shard checks if it has all the necessary indexes (if not, it will have to create them). 5. The destination checks for existing documents which belong in this range to avoid unique key violations, duplicate records. 6. After these checks the actual transfer begins. 7. Catch on subsequent operations. During the migration process the chunk still lives on the source shard, so all write operations to this chunk which occur during migration are directed to the source shard. 8. When the destination shard finishes catching up to all the changes which occurred during the migration, the transfer itself finishes. 9. The process now enters the critical section, the source shard connects to the config server in order to update the cluster metadata. 10. Once the metadata is up to date and there are no open cursors on the chunk, the cleanup starts: the source shard deletes the data which has just finished migrating. 11. Subsequent requests to the source shard asking for the migrated chunk will trigger a “stale config exception”. This triggers a refresh of the metadata for the query router which requested the chunk, and after refreshing it proceeds to retry using the updated information. Figure 5: Chunk Migration The Dest. Shard which is represented in Figure 5 is the destination shard which receives the migrating chunks. As mentioned in the chunk migration procedure, the query router is the component which can start a balancing round. These balancing rounds allow the
Adapting a noSQL database for autoscaling on a PaaS environment 20 balancer to redistribute the chunks in order to achieve an even number of chunks for the collection across the shards. The balancer is a MongoDB background process, enabled by default, which only cares about the number of chunks. It does not consider the size of the chunks or the number of documents inside a chunk because the auto-split process takes care of these problems. The balancer activates a migration process based on the migration threshold, which is different depending on the total number of chunks for a sharded collection. These migration thresholds represent the imbalance in number of chunks between the “biggest shard”, highest number of chunks for the collection, and the “smallest shard”, the fewest number of chunks for the same collection. To reduce this imbalance, the chunk with the lowest range is moved from the shard with the highest count of chunks to the shard with the lowest count of chunks. One of the possible problems induced by the automatic chunk migration are empty chunks. For example having a total of ten chunks for a sharded collection, half of them are empty and reside on one shard and the other half are not empty and reside on another shard. From the balancer’s point of view, there is no imbalance, since it only checks the number of chunks. Empty chunks can be the result of a pre-splitting mistake, or the use of a time based shard key: periodically deleting old data. The solution is to merge chunks but with a few conditions: the chunks must be on the same shard, contiguous and at least one of the chunks has to be empty. If a chunk is empty an imbalance is created within the sharded cluster, but if a chunk is too big, this also leads to data imbalance. This can occur because of a poor shard key selection or maybe a pre-splitting error. If a chunk does not receive any traffic, the auto-split will not occur, so the series of actions to take in this situation are: 1. Do manual splits and then wait for the balancer to do its job. 2. Turn of the balancer, do manual splits and then manual migration of the chunks. All the concepts which have been explained throughout chapter 2 give more insight on the mechanics behind MongoDB. This will be useful later on when modelling and creating the MongoDB service for the Kumori PaaS.
21
Adapting a noSQL database for autoscaling on a PaaS environment 22 3. Kumori PaaS 3.1 Introduction After explaining what MongoDB is, going over some of the more relevant features (replication and sharding) and comprehending the key components and processes which make this features possible, there is a need for a better understanding of the system for which MongoDB is adapted. The Kumori PaaS is a Platform-as-a-Service provided by Kumory systems, a startup of the Polytechnic University of Valencia (Spain). From now on the Kumori PaaS will be referred to as simply ECloud. ECloud is designed to manage the life cycle events of services deployed on it. The main objective is to allow the service provider to work on the development of the service instead of dealing with the service management tasks. The current stage of ECloud is ongoing development, some of the functionality might change/evolve; only certain aspects of ECloud will be covered since going into too much detail is beyond the scope of this work. All elements defined as to be disclosed (TBD) are not explained, but they are shown in the example/schemas in order for the reader to get a broader view of the entire system; they are needed for the system to work correctly, but they do not affect directly (at the point in time when the work was done) the design/implementation which the author has presented. Some of these elements are still not well defined and merely informative. 3.2 ECloud service model and components In order for a service application to work on ECloud, it must comply with the architectural patterns known as ECloud service model. According to this service model, a service application is represented by a set of interconnected components. Each of these components has a different role inside the service. The components contain the source code and a description of how to connect them to other components. The service applications contain a description of how its components are connected and also how they can be connected to other service applications. To make possible this model, these elements are available in ECloud: component, role, channel, channel protocol, configuration resources, configuration parameters, types, runtime, service application, channel connector, role instance, service and topology. Some of the elements must have a unique name to identify them, this is achieved by using a uniform resource identifier (URI). The structure of a URI is the following:
23 slap://<domain>/<elementtype>/<name>/<version> The <domain> must be a domain name belonging to the author of the component, the <elementtype> represents the type of element being identified, the <name> is the generic name of the element within its domain and the <version> is used to identify which particular version of the element is being named. The following is an example of how a URI would look like: slap://afraseniuc/components/mongodbsimpleproxylb/0_0_4 To define an element, javascript object notation (json) files referred to as manifests are used. An example of how these manifest are structured: { "spec":"slap://slapdomain/manifests/service/0_0_1", "name":"slap://afraseniuc/services/mongodbsimpleproxylbservice/0_0_4", … } From here on, in order to maintain a clear structure, all the example which are necessary to explain future manifest definitions can be found in the Appendix. The spec refers to the specification version to be found in the manifest and the name is the ID of the element being defined. As it was stated previously, service applications are made up of interconnected components. A component is viewed as an autonomously runnable executable. Even though component instances are isolated one from each other, they sometimes need functionality offered by other components. This is what will be referred to as the dependency set. Whereas the functionality offered by the component itself is referred to as the provided function set. To allow this exchange of functionality between components different types of communication (message based) channels are offered: send: this type of channel can only send messages. receive: this type of channel can only receive messages. request: this type of channel can both send and receive messages. The only messages it can receive are replies to messages it has previously sent. reply: this type of channel can both send and receive messages. The only messages it can send are responses to messages it has previously received. duplex: this type of channel can both send and receive messages without any restrictions. ECloud makes a distinction between provided and required channels. Provided channels are used to access the functionality of the component while the required channels are used to access the functionality of other components. This is related to the distinction which was made earlier between the provided function set which is linked to the provided channels, and the dependency set which is linked to the required channels. An example of how to define the channels in a manifest is given in Appendix A (on page 38).
Adapting a noSQL database for autoscaling on a PaaS environment 24 Apart from channels, a component also needs to be able to declare configuration settings which are used when executing the instance of a component. There is a distinction between configuration resources (for example cpu, cores, memory) and configuration parameters which refer to application data. The configuration parameter types offered by ECloud are: boolean, integer, json, list number, string, vhost. If no type is specified, json is assumed. The developers can also chose to define new types which derive from the ones offered. An example of how to define configuration parameters in a component manifest is given in Appendix A (on page 38) The final element which is needed in order to define a component is the runtime. In order for a component to work correctly, the environment on which the component will be run must have certain characteristics, and this is defined by the runtime. ECloud provides predefined runtimes but it also is possible to define new ones. As a result, the manifest which specifies the definition of a component includes the component’s identifier, the runtime, the configuration and the channels. An example of a complete component manifest is given in Appendix A (on page 38). 3.4 Service applications According to the ECloud service model, in order for the components to be part of a service application they must be interconnected and play a role. The component manifest defines which channels ca be used communicate, but it is the service application which connects these channels in order to allow the different roles to be able to exchange information. This is possible due to channel connectors which are used to link the actual roles by defining a relationship between their channels. There are three types: publishsubscribe (PS), load balancer (LB) and full connector (FC). The PS connector links send and receive channels; messages sent by the send channel are received by all receive channels (broadcast manner). The LB connector relates request and reply channels; when a message is sent by a request channel, the LB picks one of the instances of the roles with reply channel and after the message is processed the same channel is used to deliver the response. The FC connector pairs list of duplex channels; in this case when a message is sent by a duplex channel from the list, the destination must be specified in order to determine which duplex channel from the list receives the message. An example on how connectors are defined in a service application manifest is given in Appendix A (on page 39). The server application manifest is comprised of the roles, the connectors, the configuration and its propagation to the roles. The service application specifies the configuration parameters in a similar manner to the component manifest, but it also has to specify how to propagate this configuration to the roles. An example of a complete server application manifest is given in Appendix A (on page 39).
25
Adapting a noSQL database for autoscaling on a PaaS environment 32 the instances on this list are shards which need to be removed or added (normally there should be only one mongo-config instance). This events are asynchronous, so even if the list of mongo-shards available is updated and ready to be processed, no steps can be taken until the mongo-router connects to the mongo-config first. When the proxy fires an on change event the list of instances provided can be related to the duplex channel belonging to the mongo-config or the mongo-shard. The mongo-router waits until it receives an on change event belonging to the mongo-config, it updates its internal list of available config servers and it tries to connect to it. Even though the proxy list has a config server this does not mean that the given config server is ready to accept connections. This event can be triggered before the instance has finished configuring and starting up. So before attempting to connect to a config server the mongo-router uses the mongo shell to check when the mongo-config instance replica set has a working primary. At first it might get errors regarding that the connection failed because the startup process has not even started on mongo-config instance; secondly the mongo-config might be initializing the replica set and during a period of time it will be in a secondary state so all connections attempts from the mongo-router will fail with an error stating that no primary was detected for the replica set. Once the query router establishes a connection with the config server, new shards can be added to the server. In order to keep track of the shards, an internal list is used. Each time an on change event is triggered, it has to be for the duplex channel related to the mongo-shard, and the connection details provided in this list must not belong to shards which are available in the internal list and are already added to the sharded cluster. If this criteria is met, the mongo-router tries to add the new shard, or shards. The same problem as in the mongo-config case arises. The proxy might inform of new mongo-shard instances long before these instances are ready to actually accept connections. So before being able to add a mongo-shard instance as an actual shard of the sharded cluster, that instance should be up and running with a designed primary for its replica set. Another thing to keep in mind is that when adding new shards to a sharded cluster, the information needed is the replica set name along with the IP and port of the primary for this replica set. The mongo-shard component uses its ID to create the replica set name. The details which the proxy includes in its list of currently available instances is the ID, IP and port of the mongo-shards. This way the ID can be used to obtain the replica set name without the mongo-shard and mongo-router having to do extra communication. The complexity of the whole process resides in the fact that it is asynchronous. Depending on the hardware on which it is being run and delays in the network, defining situations, such as how much time a query router should wait before giving up on trying to add a shard which is too slow in completing its initiation process, is difficult. Part of the source code for this component is given in Appendix B (on page 43, 44, 45 and 46).
33
Adapting a noSQL database for autoscaling on a PaaS environment 34 6. Conclusions and future work Adapting a noSQL database for autoscaling on a PaaS environment is not trivial and it sometimes requires adding extra functionality on behalf of the PaaS system in order for the database to work. For example, if the Kumori PaaS would not provide the proxy-tcp module then any communication between the components of a MongoDB sharded cluster would be impossible, and the service would not even work as a simple replicate set, let alone a sharded cluster. Regarding autoscaling, as it has been show in chapter 5, it is doable and some parts which normally are done by a database administrator can be automated. On the other hand, in order for a collection inside a database to be split among the shards of a cluster, various steps have to be taken: enable sharding on the database, chose an appropriate shard key, use this shard key to split the collection. This is not an impossible task to be automated and there are some solutions: the service could be set up in such a way that all new created databases have sharding enabled; when the user creates a new collection inside his database he should specify the shard key which should be used. Of course this implies that the logic supported by the query router has to be improved, but it can be done. There are also more complex situations. For example if the user already has a populated database and wants to load it directly in the service without providing a shard key (as explained in chapter 2, choosing the right shard key is very important and it greatly affects scalability). This would require more work on behalf of the platform, an analysis of the data available in the database needs to be done in order to attempt to determine a suitable shard key. This also implies that if all this process has to be automated and done by the platform itself, then a built-in service capable of machine learning techniques is needed. This service could also be used then to define patterns depending on which shards would be added or removed accordingly. This also raises another issue, how would the scenario of deleting a shard be handled. Deleting a shard is more complicated than adding one because of the draining process: when a shard is removed from a cluster, all the data residing on that shard has to be migrated to the remaining shards in the cluster. This implies that once a mongoshard instance is given the order to shutdown, the time frame needed by the shard to complete its draining and shut down can vary a lot, depending on factors such as: hardware performance, network latency and data set size. The logic to remove a shard from a cluster should be implemented in the mongoshard component. The mongo-shard is aware of all the available mongo-router instances by means of the proxy. Each time a mongo-router instance is created the mongo-shard would be notified via on change event issued by the proxy. By using a mongo shell to connect to one of the mongo-routers from the list returned by the proxy and issuing the removeShard command, the draining process would start immediately and a message stating that the draining has started would be returned. If the same command is issued again, the message returned would specify that the draining is ongoing. Once the draining is completed, if the command is run again, the message
35 returned indicates that the removeShard completed successfully. At this point in time the instance for this mongo-shard could be terminated without losing any data. As specified in chapter 3, there is the possibility to create runtimes. A runtime could be created that includes the MongoDB binaries. There are also other optimizations which could be applied to the runtime in order for the sharded cluster to operate as optimal as possible in the case of a real life production MongoDB deployment: Transparent huge pages: disable and turn off defrag. Ulimits: the ulimit is used in unix systems to limit resources. A low “soft” ulimit can cause can't create new thread, closing connection errors if the number of connections grows too high. For this reason, it is extremely important to set both ulimit values (soft and hard) to the recommended values. In order for MongoDB to perform correctly, some of the resources controlled by ulimit need certain minimum values. The starting points for large systems are: o file handles (fs.file-max): /proc/sys/fs/file-max, 98000 o kernel pid limit (kernel.pid_max): /proc/sys/kernel/pid_max, 64000 o maximum threads per process (kernel.threads-max): /proc/sys/kernel/threads-max, 64000 Ensure that system has swap space configured. Allocating swap space can avoid issues with memory contention and can prevent the Out of Memory Killer (OOM Killer) on Linux systems from killing mongod in order to free up memory. Given sufficient memory pressure, data may be stored in swap space. TCP keep-alive: In case of socket errors between client-server or between members of a sharded cluster, use a shorter TCP keep alive (order of around 120 seconds) instead of default 7200 seconds (common for Linux systems). File systems: XFS is recommended and atime for the storage volume containing the database files. The atime refers to the file access time. These are just some of the optimizations and future work that can be done. Some of them are easier to implement and some of them are harder, but overall there is still room for improvement.
Adapting a noSQL database for autoscaling on a PaaS environment 36
37 7. References [1] P. Graham. Web 2.0, November 2005. [Online]. Available: http://www.paulgraham.com/web20.html. Retrieved: August 27, 2016. [2] C. Garling. Amazon Goes Back to the Future With ‘NoSQL’ Database, January 2012. [Online]. Available: http://www.wired.com/2012/01/amazon-dynamodb/. Retrieved: August 27, 2016. [3] MongoDB, MongoDB Manual. [Online]. Available: https://docs.mongodb.com/manual/. Retrieved: August 27, 2016. [4] DB-Engines, DB-Engines Ranking, August 2016. [Online]. Available: http://dbengines.com/en/ranking. Retrieved: August 27, 2016. [5] MongoDB White Paper, MongoDB Architecture Guide MongoDb 3.2, June 2016. [Online]. Available: https://webassets.mongodb.com/_com_assets/collateral/MongoDB_Architecture_Gu ide.pdf. Retrieved: August 27, 2016. [6] P. Anderson, Web 2.0 and Beyond: Principles and Technologies, p. 36, CRC Press, Boca Raton, 2012 [7] E. S. Raymond, The Jargon File. [Online]. Available: http://www.catb.org/jargon/html/D/daemon.html. Retrieved: August 27, 2016. [8] P. J. Sadalage; M. Flower, NoSQL Distilled, A brief guide to the emerging world of polyglot persistence, pp. 37-38, Addison-Wesley, Boston, 2012. [9] MongoDB White Paper, Delivering MongoDB-as-a-Service: Top 10 Considerations, August 2016. [Online]. Available: https://s3.amazonaws.com/infomongodb-com/MongoDB_as_a_Service.pdf. Retrieved: August 27, 2016. [10] MongoDB, MongoDB Node.JS Driver. [Online]. Available: http://mongodb.github.io/node-mongodb-native/. Retrieved: August 27, 2016. [11] C. C. Evans, YAML Ain’t Markup Language, [Online]. Available: http://www.yaml.org/. Retrieved: August 27, 2016.
Adapting a noSQL database for autoscaling on a PaaS environment 38 8. Appendix 8.1 Appendix A ECloud component manifest: In the component manifest, the sepdest is a provided channel. Since its purpose is to provide functionality it makes sense that the type of channel used is a reply channel. The other channel defined in the example is req1, a required channel. This is the channel which will allow the component to request functionality from another component, thus the type of this channel is request. The configuration parameter represents a string type configuration parameter.
39 ECloud service application manifest: The above manifest displays how a LB connector links two components, sep and fe. In this case the sep is the component which requires information and fe is the component which supplies it. The dependents and providers classification is related to the components channels and it corresponds to the respective required and provided channels. The components describes the roles which the components will have inside the service application. The configuration represents the configuration parameters. The fe component will receive at execution time the configuration parameters described by proxyTcpFe. The mongodb component will receive at execution time the configuration parameters described by the proxyTcpMongodb.
Adapting a noSQL database for autoscaling on a PaaS environment 40 8.1 Appendix B
41 The two screen captures on the previous page represent the mongo-driver. The initialization of the mongo-config component: The method used to compute the configuration parameters and channels: The method used to grant execute permission to the binaries and script: