Utilize MongoDB to store information within a sharding cluster and track the duration of data operations

I am looking to save data on a MonogoDB. For this purpose, I have a setup with one mongos, three configserver, and a sharding configuration consisting of two replicasets (each with primary/secondary/arbiter).

There are two main issues I am facing:

1) What is the most effective method to track the time taken to store all the data?

Currently, I am using the command "time mongo 141.100.55.72:25001/mydb --quiet /data/javascript/insert.js" through the mongos (details of insert.js provided later). I want to measure multiple operations and save each output in a file. I am working on an Ubuntu server.

2) The time taken for the operation is significantly slow - for example, it takes about 5 minutes to store 100,000 data objects. How can I improve the performance?

The javascript script is as follows: (testdata creation with a sharding key for testing purposes could be causing the slow performance)


var amount = 100000/4;
var x=1;
var doc= "";

for (i=0; i<amount; i++)
{
doc = { datetime: '1119528044', att2: '...', key: x,...} //14 attributes
db.mycol.insert(doc);
x=x + 1
}

for (i=0; i<amount; i++)
{
doc = { datetime: '1219268044', att2: '...', key: x,...} //14 attributes
db.mycol.insert(doc);
x=x + 1
}

for (i=0; i<amount; i++)
{

doc ={ datetime: '1355851700', att2: '...', key: x,...} //14 attributes
db.mycol.insert(doc);
x=x + 1

}

for (i=0; i<amount; i++)
{ 
doc = { datetime: '1444851704', att2: '...' key: x,...} //14 attributes
db.mycol.insert(doc);
x=x + 1
}

Additionally, I need guidance on how to verify if the data is present on both replicasets. What would be the most effective approach to perform this check?

Thank you,

Answer №1

When you execute time mongo, you are introducing a significant amount of additional time for the process to initialize, establish a connection, and complete the entire script.

Are you intending to measure this time? Or are you interested in the duration it takes for each insertion to be replicated and stored in a shard?

If you prefer to execute the script within the shell:

function calculateTime() {
 ...
}
> var startTime = new Date(); measure_time(); print('Elapsed time:', Math.abs(startTime-new Date().getTime()).toString(), 'ms');

Then you can determine how long the process takes.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for optimizing AJAX content for Google indexing

As I begin the process of developing a public website that utilizes client-side rendering with AngularJS, I have come across information suggesting that dynamically generated content may not be properly indexed by Google. This raises concerns about the imp ...

Vue warning: You are trying to access a property or method that is not defined on the instance but is being referenced during

The code snippet above was created to manage an event triggered by a button click var MainTable = Vue.extend({ template: "<ul>" + "<li v-for='(set,index) in settings'>" + "{{index}}) " + &qu ...

A step-by-step guide on including an object within an object array with Javascript

In the code snippet below, I have a JavaScript object that I'm trying to add a similar object to using request.rules[0]. request : [ rules: [ { pageFilters: [ { matchType: 'contains', type ...

Retrieve an entire item from a single data point

I am currently developing a ticket system and I am looking to implement a feature that allows users to close a ticket, removing it from their account. In my MongoDB array, the structure of the tickets is as follows: { "tickets": [{ &q ...

The term "this" in the global scope versus within a function in the Node.js environment

console.log(this) // {} function abc(){ console.log(this) } abc() // global The concept of this can vary between the global space and inside a function in Node.js. console.log(this === module.exports) // true function abc(){ ...

Tutorial on creating a loop for a function based on a specific condition

I have created two different div classes named box and box2. The box2 class can be dragged and dropped into any of the three box classes. Each box contains randomly chosen values from an array, while box2 contains its corresponding image for display. When ...

Why is my JavaScript code functioning properly on jsfiddle but failing to work when run locally?

After recently creating JavaScript code that allows for form submission using the <form> tag, I encountered an issue when trying to implement it within an HTML page. Here is a snippet of the code: <script type="text/javascript"> var m ...

What is the best way to eliminate all padding from a bootstrap toast notification?

I'm attempting to display a bootstrap alert message as an overlay toast (so it automatically disappears and appears above other elements). Issue: I am encountering a gap at the bottom of the toast and struggling to remove it: https://jsfiddle.net/der ...

Fixing errors with observables in an Angular 2 project using Rx

var foo = Observable.create(function(observer){ try{ console.log('hey there'); observer.next(22); throw new Error('not good at all'); setTimeout(function(){ observe ...

What are the steps to correctly implement async await in a standard sequence?

When I press the button onPress={() => Login()} First, I need to obtain a token by using the signInWithKakao function. Secondly, right after acquiring the token, if it is available, I want to dispatch the profile using the kakaoprofile function. Howev ...

Sending a JSONP request to a PHP script

For my application submission, I am trying to send a JSON object to a PHP script that will return a JSON response. The challenge here is that the domain does not comply with the same-origin policy, meaning the JSON is being sent from a different domain. Up ...

`How can I activate caching for getServerSideProps in Next.js?`

We have implemented server-side rendering for a few pages and components. In an attempt to optimize performance, we have been experimenting with caching API responses. export async function getServerSideProps(context) { const res = await getRequest(API ...

Ways to determine if your code is written in ES6

After completing a lot of Javascript coding, I just learned about the existence of various JS 'versions' such as ES5 and ES6. My project is now up on Github, and someone advised me to convert my ES6 code to ES5 using Babel. The problem is, I&ap ...

Field cannot be submitted without the required input after an Ajax request

I want to ensure that all my text/email input forms require a submission before you can "Submit" the email. Unfortunately, when using Ajax to prevent the page from refreshing after pressing the button, the required attribute does not function properly. T ...

What is the best approach for writing a concise Select statement that produces a data list?

Currently, I am working on a small web application using Express.js and SQLite for local use. However, I am facing an issue when trying to perform a full select query on a table. All my scripts are written in JScript in 'use-strict' mode. I am a ...

Embedding Facebook data into an HTML document

While I am able to retrieve data from Facebook and display it on the console, I am facing issues when trying to display it on an HTML page. I attempted using: $("#mydiv").text(data); or $("#mydiv").append(data); However, this displays [object Object] ...

Sending information from ngRoute resolve to the controller

I am currently working on an application that utilizes ngRoute to create a Single Page Application. One of the requirements is to ensure that the view is not loaded until the data has been successfully fetched from the database. While I have managed to ach ...

Detecting button clicks in different views using Backbone.js

In my current setup, I have a main parent view called View.A which is responsible for managing two child views - View.B and View.C. Specifically, View.B contains buttons that trigger events on that view. Configuration View.A View.B view.B.template. ...

What is the maximum character limit for the JQuery validation plugin?

Currently, I am utilizing the JQuery validation plugin in my project. My goal is to set a maxlength for one of the fields. Here's an example of how it can be done by defining rules externally: rules: { Message: { required: false, maxLe ...

Unable to display content when the button is triggered

I am facing an issue with hiding a div (class="login-form") and displaying it only after clicking the Login button on my HTML page using jQuery. However, despite clicking the button, the login form does not appear. Can anyone help me understand why this ha ...