Tag: database

  • MongoDB Replication Pro-tips: Reporting Instances

    MongoDB Replication Pro-tips: Reporting Instances

    Any shop that has a DevOps culture, and that has MongoDB backed applications, uses replica sets… not just for production applications, but for those still in the prototyping phase. Replication is critical for uptime, so your Ops team has been working with your Devs all through the development of your project, and you didn’t defer a replication strategy until after you had a working app.

    Nor did you neglect to plan for your reporting needs. It is a given that beyond running your app, you need to get analytics on user behavior, general use, and other business-specific metrics. You can’t just run reports against your live database, (for reasons I detail below, in case they are not yet obvious to you). In your DevOps shop, developers and admins discussed, at the inception of the project, the plan for sequestering reporting tasks so that they do not interfere with production tasks.

    Keeping Reporting Reads Away From Production

    Limiting reporting queries to dedicated nodes is a canonical example, used all over the MongoDB replication documentation. Reporting does not require writes, and permits eventually consistent data. Daily summaries do not suffer if they are derived from data which is seconds or minutes stale. It does not change the fundamental meaning of user behavior reports if your counts are missing a few actions, and some tallies are slightly misaligned.

    But why is it so important to take advantage of this?

    Aside: The Problem With Mingling Production and Analytics

    Skip this section if this is already a no-brainer for you. If you want some background, read on.

    Consider the working set, the subset of your entire database that MongoDB reads from and writes to over any given time span. Your production environment will have a set of active users, and the documents pertaining to their data will be what the OS attempts to keep in physical memory.

    (Do not let your working set grow larger than RAM! If it’s heading there, you need to shard, so capacity planning is critical. But that’s a separate lesson. Monitor your instances with MongoDB’s free monitoring servicee, and maybe take an upcoming webinar in capacity planning.)

    Even if your database is hundreds or thousands of times the size of your available memory, if you have planned your schema and indices well, MongoDB will run efficiently because the data outside the working set can remain untouched on disk. As users become idle, their documents will fall out of use, and the RAM they occupy will become available to contain documents for new active users.

    Reporting jobs, though, read a wide range of data, do not visit the same data repeatedly, and each reporting task may address completely different data sets. On any database of decent size, this means these jobs require constant ejection of recently used documents from RAM to make room for new documents to be read. If you run these jobs on the same instance that is backing your production work load, your reporting jobs will fight with your production apps for RAM footprint, continuously ejecting your live users’ data, while your app continuously reloads it. Congratulations, you have built a thrashing machine.

    Replica Sets With Dedicated Reporting Instances

    You can build dedicated reporting nodes atop MongoDB replication by taking advantage of hidden replica set members, or tag sets in concert with read preferences. The first method is simpler, the second is more flexible.

    Reviewing MongoDB Replica Sets

    MongoDB Replica Sets create uptime durability by replicating data to all the nodes in a set, and providing seamless fail-over to clients. They contain one primary node that allows writes, while the rest are read-only secondaries. They manage among themselves which is primary, holding elections to determine which node should be primary when conditions require. Replica sets should contain an odd number of members to facilitate rapid elections without ties.

    It is fundamentally not knowable whether unreachable machines are down or if the network has been partitioned, so if a majority of the nodes in a replica set go offline (say, 2 out of a 3-member set), even if a healthy primary remains, it will step down to a read-only secondary. Not doing so could lead to multiple machines declaring themselves primary in the case of a network partition, and horrific data inconsistencies.

    Thus a replica set contains a minimum of 3 members, providing a fault tolerance of one machine failure.

    Reporting Instance, Hidden Member

    Hidden members of a replica set are configured to be priority: 0, to prevent them from ever being elected primary, and to be hidden: true, which prevents clients connected to the replica set from routing reads to it, even if they specify a read preference of secondary.

    To read from this hidden member, you will use a standalone connection, rather than the MongoReplicaSetClient type, and specify slave_ok.

    Hidden Member Setup

    We can use the mongo shell to hide a member of an existing replica set:

    # connect to primary directly
    Kusanagi:~ avery$ mongo --port 29019
    MongoDB shell version: 2.4.3
    connecting to: 127.0.0.1:29019/test
    
    // using my local replica set playground
    PRIMARY> conf = rs.config()
    {
        "_id" : "test",
        "version" : 21,
        "members" : [
            {
                "_id" : 0,
                "host" : "Kusanagi.local:29017",
            },
            {
                "_id" : 1,
                "host" : "Kusanagi.local:29018",
            },
            {
                "_id" : 2,
                "host" : "Kusanagi.local:29019",
            }
        ]
    }
    
    // we'll use members[1], the instance on port 29018
    PRIMARY> conf.members[1].priority = 0
    PRIMARY> conf.members[1].hidden = true
    PRIMARY> conf.version += 1
    PRIMARY> rs.reconfig(conf)
    Tue Apr  1 12:24:34.045 DBClientCursor::init call() failed
    Tue Apr  1 12:24:34.046 trying reconnect to 127.0.0.1:29019
    Tue Apr  1 12:24:34.047 reconnect 127.0.0.1:29019 ok
    reconnected to server after rs command (which is normal)

    Kusanagi.local:29018 is now hidden. It will continue to replicate and vote in elections as usual, but clients connecting to the replica set will never read from it, even if Kusanagi.local:29019 is taken down:

    irb(main):012:0> rs = Mongo::MongoReplicaSetClient.new(["Kusanagi.local:29017", "Kusanagi.local:29018", "Kusanagi.local:29019"])
    => <Mongo::MongoReplicaSetClient:0x3fe06e4fe564 @seeds=[["Kusanagi.local", 29017], ["Kusanagi.local", 29018], ["Kusanagi.local", 29019]] @connected=true>
    irb(main):013:0> rs.primary
    => ["Kusanagi.local", 29017]
    irb(main):014:0> rs.secondaries
    => #<Set: {}>
    # an empty set -- as far as this connection is concerned, there are no secondaries.

    Reporting code would look like this (in Ruby):

    require 'mongo'
    reporting = Mongo::MongoClient.new("Kusanagi.local", "29018", slave_ok: true)
    
    # error checking goes here
    
    reporting['my_application']['users'].aggregate(...)

    Considerations

    Using a hidden member is the simplest way to set up an instance for a dedicated workload such as reporting, however:

    Hidden Members Cannot Be Read From In Case of Emergency

    With 2 ordinary and one hidden member in a replica set, fault tolerance for writing is identical to a regular 3-member set. However, should you lose two nodes, your production application will not be able to gracefully degrade to read-only mode, because your hidden member will not allow replica set client reads. If you just like the simplicity of a hidden member, and cost is not an issue, use a 5-member set (with one member hidden) instead.

    Wrapper Code for Replica Sets Cannot Be Used

    Many teams create application-specific wrappers to add infrastructure knowledge to the clients provided by MongoDB drivers. Since you need to address your reporting instance with a stand-alone connection, you will not be able to reuse this investment, which will make you sad.

    Reporting Instance, Tagged Member

    The more complex, but flexible, method for routing reporting queries to a dedicated node is to use tagging and read preferences.

    As with the hidden member, set one member to priority: 0, but do not set it to be hidden. Instead, assign a tag of use: reporting:

    PRIMARY> conf = rs.config()
    {
        "_id" : "test",
        "version" : 21,
        "members" : [
            {
                "_id" : 0,
                "host" : "Kusanagi.local:29017",
            },
            {
                "_id" : 1,
                "host" : "Kusanagi.local:29018",
            },
            {
                "_id" : 2,
                "host" : "Kusanagi.local:29019",
            }
        ]
    }
    
    // we'll use members[1], the instance on port 29018
    PRIMARY> conf.members[1].priority = 0
    PRIMARY> conf.members[1].tags = { "use": "reporting" }
    PRIMARY> conf.version += 1
    PRIMARY> rs.reconfig(conf)
    [...]

    As before, Kusanagi.local:29018 will never become primary; however, in the case that the other two machines become unreachable, your application will be able to issue reads to the reporting server. It should go without saying that your reporting should be suspended during such an event.

    Your reporting code will look something like this (in Python, this time):

    from pymongo import MongoReplicaSetClient
    from pymongo.read_preferences import ReadPreference
    
    rep_set = MongoReplicaSetClient(
        'Kusanagi.local:29017,Kusanagi.local:29018,Kusanagi.local:29019',
        replicaSet = 'test',
        read_preference = ReadPreference.SECONDARY,
        tag_sets = [{'use':'reporting'}]
    )
    # check to ensure we're not running reporting against the sole remaining secondary
    if rep_set.primary is not None:
        rep_set.my_application.users.aggregate(...)

    The above will only send reporting queries to secondaries tagged use: reporting, and it guards against running at all if there is no available primary. In practice, you should throw exceptions and handle them in your escalation code if you find no primaries! Better still, your monitoring could set runtime-available values so you can branch on, for example, reporting_system.ok().

    Benefits and Considerations

    Using tags and read preferences allows a few degrees of flexibility that are not possible with hidden members.

    Reporting Instances Can Be Easily Added

    Because your connection code is declarative, rather than specific to a particular host, to add more nodes for reporting jobs, just add them and tag them, like so:

    PRIMARY> rs.add({_id:3, host:"Kusanagi.local:29020", priority:0, tags:{'use':'reporting'}})

    Your existing code will make use of the new capacity, and the replica set will continue operating without triggering an election and disconnecting your clients.

    Reporting Instances Can Be Shifted or Dropped

    The reporting tag can be moved, or even removed if you need to offer read bandwidth to other jobs in a pinch. A reconfiguration like this will trigger an election and disconnect all your clients, but this is no worse than any other option. Note: It is an anti-pattern to increase your general capacity by distributing production reads to secondaries. This is only an emergency measure.

    Some Drivers Require Manual Sync

    The Ruby driver (as of 1.9.2), for example, does not refresh its view of the replica set unless the client is initialized explicitly to do so with refresh_mode: :sync. Check your driver documentation.

    Conclusion

    Simple replication setup has been one of my favorite operational aspects of MongoDB since its introduction pre–1.0, when it made MySQL replication look like something out of the stone age. It was a little rough around the edges back then, but has truly come into its own. Whether you use tag sets or hidden members, building a reporting infrastructure atop MongoDB’s replication features simplifies operations, letting you focus on building a great application.

  • MasterCard Israel 85% More Productive in Promoting Changes after Implementing DevOps for Database from DBmaestro

    Mastercard Israel renews contract with DBmaestro to provide its Database Enforced Change Management Solution for a third year 

    Tel Aviv, February 18, 2014  – DBmaestro, the pioneer and leading provider of DevOps for Database solutions has announced that Isracard, Israel’s leading credit card company and member of the worldwide MasterCard group, will be renewing their contract with DBmaestro for a third year. DBmaestro streamlined Isracard’s development process by providing Database Enforced Change Management capabilities (DECM) which enforce best practices and prevent accidental code overwrites.

    In 2011 Isracard was struggling with a number of challenges including failures during production deployments and frequent unintentional code overwrites which forced developers to spend time backtracking and re-implementing changes. Isracard’s problems were a lack of insight into change histories, difficulty undoing changes and rolling back to previous versions, an inability to properly prioritize developers’ work, and a lack of formal documentation of planned and completed changes. The company wanted to enforce consistency and coordination for database development in the same way that its tools and methodologies did for native application code. These issues were draining valuable time and resources from the company.

    After evaluating a number of solutions, Isracard chose DBmaestro and quickly experienced an eightfold increase in its productivity in promoting changes. A deployment script that took as much as two hours to be developed before DBmaestro was now completed in just 15 minutes. DBmaestro also provided a full audit trail of all changes, which made it easier for the change manager to control all projects throughout their lifecycle – from development through pre-production, to production. This drastic improvement was achieved with the help of DBmaestro’s Database Enforced Change Management capabilities (enforcement of version control best practices), which prevent accidental code overwrites and eliminates the rework associated with such errors. Developers at Isracard were now able to see if someone else was already working on the same object, improving communication and minimizing the risk of redundancies and conflicts.

    “Our development processes were inefficient, and we often found ourselves working on versions that were different from production versions,” said Ronen Zaretsky, CIO of Isracard. “DBmaestro changed all that. It has helped us streamline and coordinate our activities across code and database development. Now, we can work smarter and faster, and everything runs smoothly, from start to finish.”

    “We are delighted to continue supporting Isracard for the 3rd year in a row, following an already successful two year partnership,” Said Yaniv Yehuda, CTO of DBmaestro. “This is the perfect demonstration of the value our solution provides our partners. Isracard approached us in 2011 seeking a way to improve development processes, maintain stability and promote changes to production daily instead of monthly. To ensure the availability of production systems, they also needed to ensure separation between development and production environments. After evaluating a number of solutions Isracard chose DBmaestro because it integrated seamlessly with the company’s existing proprietary deployment tool, and helped to rapidly and effectively bridge the gap between code and database development methodologies.”

    To learn more about TeamWork from DBmaestro, visit our blog or Request a Free Evaluation.

    About Isracard

    Isracard is a fully-owned subsidiary of Bank Hapoalim, Israel’s largest banking group. Isracard was founded in 1975 and is Israel’s leading Credit Card Company. Isracard has some 100 thousand merchant agreements and approximately 2 million credit card holders.

    Isracard is continually developing and implementing advanced technologies to widen the variety of its products, and to improve customer service. The company is developing new activities in various areas, including P2P and B2B, which the current partnership is a major basis for its further development.

  • Tokutek Announces Reselling Partnership With SkySQL

    Leading MariaDB Distributor Adds TokuDB as Complementary Tool to Extend Database Performance and Scalability

    With TokuDB and the SkySQL MariaDB, database administrators and DevOps engineers can easily operate on continuously incoming data and incorporate analysis on large volumes of data.

     

    LEXINGTON, MA and LONDON, UNITED KINGDOM and HELSINKI, FINLAND–(Marketwired – Feb 12, 2014) – Tokutek, delivering database performance at scale, today announced that it has entered into a partnership with SkySQL™, a trusted provider of open source database technology, to resell its TokuDB® database storage engine. SkySQL will offer the TokuDB storage engine as a complement to its MariaDB® distribution to increase scalability and performance and to enable real-time management of transactional and analytical data.

    TokuDB enhances the SkySQL MariaDB distribution with its unique ability to handle high rates of incoming data, including updates, while maintaining query performance on large volumes of data. This occurs without requiring expensive hardware build-out and with no operational downtime. With TokuDB and the SkySQL MariaDB, database administrators and DevOps engineers can easily operate on continuously incoming data and incorporate analysis on large volumes of data. Businesses benefit from richer analysis, more up-to-date information, and access to detailed data.

    “Tokutek’s TokuDB storage engine gives the database administrators and DevOps engineers who support MariaDB applications a ready-made tool to improve their database performance and scalability,” said Tom Callway, Director Marketing, SkySQL. “The combination of high data ingestion, compression and Fractal Tree indexing in Tokutek’s TokuDB makes it a great complement to the SkySQL MariaDB for high-performance, real-time analytics.”

    Paybox, the leading provider of electronic payment solutions in Europe, is a current SkySQL MariaDB customer also using TokuDB to manage their database. According to Marc Thomas, chief technical officer at Paybox, “As we continue to grow, so do the demands on our databases. We’ve benefited from SkySQL’s deep knowledge of MariaDB and best-in-class support, and Tokutek’s unparalleled scalability and performance. The increased collaboration between SkySQL and Tokutek ensures that these two industry leading providers will become more tightly coupled on both the technology and the service level, which is a big plus for Paybox.”

    “SkySQL offers both a MariaDB distribution as well as the tools and services necessary to support it,” said John Partridge, CEO of Tokutek. “With our TokuDB storage engine available as a SkySQL download, SkySQL is giving its customers the ability to make MariaDB into a much more performant database.”

    TokuDB is the ideal choice for complex high-volume applications that require fast response time and that must simultaneously store and query large volumes of rapidly arriving data. These include social networking applications, real-time clickstream analysis, logfile analysis, ecommerce personalization, and high-speed webcrawling applications. TokuDB is fully compatible with MySQL and MariaDB.

    To learn more about the SkySQL MariaDB distribution with TokuDB v7.0:

    Download a free trial of the suite,
    Attend a Webinar overview of TokuDB v7.0,
    Read the Tokutek blog for more information on TokuDB.

    About Tokutek Inc.
    Tokutek is a performance database company that delivers Big Data capabilities to leading open source data management platforms. Its breakthrough technology lets customers build a new class of applications that handle unprecedented amounts of incoming data and scale with the data processing needs of tomorrow. Tokutek applies patented Fractal Tree™ indexing to increase MySQL performance and MongoDB performance, decrease database size, and minimize downtime. The company is headquartered in Lexington, MA, and has offices in New York, NY. For more information, visit Tokutek.com or follow us on Twitter@Tokutek.

    About SkySQL
    SkySQL is a trusted provider of open source database solutions for MySQL and MariaDB users on enterprise sites and in the cloud. SkySQL provides deployment and database management solutions to more than 400 client companies, including Canal+, ClubMed, Constant Contact, Deutsche Telekom, La Poste, Virgin Mobile, Western Digital, and XING. With more than 300 accumulated years of experience in the original MySQL solution, SkySQL has a wealth of core competencies in MySQL and counts on the support of the first MySQL creators, as well as those of MariaDB. The company has also developed database management solutions in the cloud, which are easy to use and offer improved productivity. For more information, go to www.skysql.com, and follow our twitter feed:http://www.twitter.com/skysql

    MySQL is a registered trademark of Oracle, and/or its affiliates.
    MariaDB and SkySQL are registered trademarks of SkySQL Corporation Ab. SkySQL and MariaDB are not affiliated with MySQL, or Oracle.
    Other names may be trademarks property of their respective owners