Firebase: First write is slow










0















Currently developing a hybrid mobile app using ionic. When the app starts up, and a user writes to the Realtime Database for the first time, it's always delayed by around 10 or more seconds. But any subsequent writes are almost instantaneous (less than 1 second).



My calculation of delay is based on watching the database in the Firebase console.



Is this a known issue, or maybe I am doing something wrong. Please share your views.



EDIT:



The write is happening via Firebase Cloud Function.



This is the call to the Firebase Cloud function



this.http.post(url+"/favouritesAndNotes", obj, this.httpOptions)
.subscribe((data) =>
console.log(data);
,(error)=>
console.log(error);
);


This is the actual function



 app.post('/favouritesAndNotes', (request, response) => 
var db = admin.database().ref("users/" + request.body.uid);
var favourites = request.body.favourites;
var notes = request.body.notes;
if(favourites!==undefined)
db.child("favourites/").set(favourites);

if(notes!==undefined)
db.child("notes/").set(notes);

console.log("Write successfull");
response.status(200).end();
);









share|improve this question



















  • 1





    Is your user authenticate when you open the app or only at the same time you do the first call ?

    – Christophe Gudlake
    Nov 15 '18 at 18:18












  • @ChristopheGudlake The user has already logged in.

    – LukeWarm2897
    Nov 15 '18 at 18:19











  • they probably close the dyno and reopen it once activity begin.

    – Christophe Gudlake
    Nov 15 '18 at 18:33











  • @ChristopheGudlake: the question you linked is about the time it takes to start Cloud Functions, while this question is about the Realtime Database. While both are part of Firebase, they're quite different. For example: Firebase Database instances are not "spun down", and I doubt caching would cause this difference.

    – Frank van Puffelen
    Nov 15 '18 at 18:40






  • 1





    Please update your question to include the minimal, complete code that reproduces the problem.

    – Frank van Puffelen
    Nov 15 '18 at 18:46















0















Currently developing a hybrid mobile app using ionic. When the app starts up, and a user writes to the Realtime Database for the first time, it's always delayed by around 10 or more seconds. But any subsequent writes are almost instantaneous (less than 1 second).



My calculation of delay is based on watching the database in the Firebase console.



Is this a known issue, or maybe I am doing something wrong. Please share your views.



EDIT:



The write is happening via Firebase Cloud Function.



This is the call to the Firebase Cloud function



this.http.post(url+"/favouritesAndNotes", obj, this.httpOptions)
.subscribe((data) =>
console.log(data);
,(error)=>
console.log(error);
);


This is the actual function



 app.post('/favouritesAndNotes', (request, response) => 
var db = admin.database().ref("users/" + request.body.uid);
var favourites = request.body.favourites;
var notes = request.body.notes;
if(favourites!==undefined)
db.child("favourites/").set(favourites);

if(notes!==undefined)
db.child("notes/").set(notes);

console.log("Write successfull");
response.status(200).end();
);









share|improve this question



















  • 1





    Is your user authenticate when you open the app or only at the same time you do the first call ?

    – Christophe Gudlake
    Nov 15 '18 at 18:18












  • @ChristopheGudlake The user has already logged in.

    – LukeWarm2897
    Nov 15 '18 at 18:19











  • they probably close the dyno and reopen it once activity begin.

    – Christophe Gudlake
    Nov 15 '18 at 18:33











  • @ChristopheGudlake: the question you linked is about the time it takes to start Cloud Functions, while this question is about the Realtime Database. While both are part of Firebase, they're quite different. For example: Firebase Database instances are not "spun down", and I doubt caching would cause this difference.

    – Frank van Puffelen
    Nov 15 '18 at 18:40






  • 1





    Please update your question to include the minimal, complete code that reproduces the problem.

    – Frank van Puffelen
    Nov 15 '18 at 18:46













0












0








0








Currently developing a hybrid mobile app using ionic. When the app starts up, and a user writes to the Realtime Database for the first time, it's always delayed by around 10 or more seconds. But any subsequent writes are almost instantaneous (less than 1 second).



My calculation of delay is based on watching the database in the Firebase console.



Is this a known issue, or maybe I am doing something wrong. Please share your views.



EDIT:



The write is happening via Firebase Cloud Function.



This is the call to the Firebase Cloud function



this.http.post(url+"/favouritesAndNotes", obj, this.httpOptions)
.subscribe((data) =>
console.log(data);
,(error)=>
console.log(error);
);


This is the actual function



 app.post('/favouritesAndNotes', (request, response) => 
var db = admin.database().ref("users/" + request.body.uid);
var favourites = request.body.favourites;
var notes = request.body.notes;
if(favourites!==undefined)
db.child("favourites/").set(favourites);

if(notes!==undefined)
db.child("notes/").set(notes);

console.log("Write successfull");
response.status(200).end();
);









share|improve this question
















Currently developing a hybrid mobile app using ionic. When the app starts up, and a user writes to the Realtime Database for the first time, it's always delayed by around 10 or more seconds. But any subsequent writes are almost instantaneous (less than 1 second).



My calculation of delay is based on watching the database in the Firebase console.



Is this a known issue, or maybe I am doing something wrong. Please share your views.



EDIT:



The write is happening via Firebase Cloud Function.



This is the call to the Firebase Cloud function



this.http.post(url+"/favouritesAndNotes", obj, this.httpOptions)
.subscribe((data) =>
console.log(data);
,(error)=>
console.log(error);
);


This is the actual function



 app.post('/favouritesAndNotes', (request, response) => 
var db = admin.database().ref("users/" + request.body.uid);
var favourites = request.body.favourites;
var notes = request.body.notes;
if(favourites!==undefined)
db.child("favourites/").set(favourites);

if(notes!==undefined)
db.child("notes/").set(notes);

console.log("Write successfull");
response.status(200).end();
);






firebase firebase-realtime-database google-cloud-functions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 18:54







LukeWarm2897

















asked Nov 15 '18 at 18:16









LukeWarm2897LukeWarm2897

2718




2718







  • 1





    Is your user authenticate when you open the app or only at the same time you do the first call ?

    – Christophe Gudlake
    Nov 15 '18 at 18:18












  • @ChristopheGudlake The user has already logged in.

    – LukeWarm2897
    Nov 15 '18 at 18:19











  • they probably close the dyno and reopen it once activity begin.

    – Christophe Gudlake
    Nov 15 '18 at 18:33











  • @ChristopheGudlake: the question you linked is about the time it takes to start Cloud Functions, while this question is about the Realtime Database. While both are part of Firebase, they're quite different. For example: Firebase Database instances are not "spun down", and I doubt caching would cause this difference.

    – Frank van Puffelen
    Nov 15 '18 at 18:40






  • 1





    Please update your question to include the minimal, complete code that reproduces the problem.

    – Frank van Puffelen
    Nov 15 '18 at 18:46












  • 1





    Is your user authenticate when you open the app or only at the same time you do the first call ?

    – Christophe Gudlake
    Nov 15 '18 at 18:18












  • @ChristopheGudlake The user has already logged in.

    – LukeWarm2897
    Nov 15 '18 at 18:19











  • they probably close the dyno and reopen it once activity begin.

    – Christophe Gudlake
    Nov 15 '18 at 18:33











  • @ChristopheGudlake: the question you linked is about the time it takes to start Cloud Functions, while this question is about the Realtime Database. While both are part of Firebase, they're quite different. For example: Firebase Database instances are not "spun down", and I doubt caching would cause this difference.

    – Frank van Puffelen
    Nov 15 '18 at 18:40






  • 1





    Please update your question to include the minimal, complete code that reproduces the problem.

    – Frank van Puffelen
    Nov 15 '18 at 18:46







1




1





Is your user authenticate when you open the app or only at the same time you do the first call ?

– Christophe Gudlake
Nov 15 '18 at 18:18






Is your user authenticate when you open the app or only at the same time you do the first call ?

– Christophe Gudlake
Nov 15 '18 at 18:18














@ChristopheGudlake The user has already logged in.

– LukeWarm2897
Nov 15 '18 at 18:19





@ChristopheGudlake The user has already logged in.

– LukeWarm2897
Nov 15 '18 at 18:19













they probably close the dyno and reopen it once activity begin.

– Christophe Gudlake
Nov 15 '18 at 18:33





they probably close the dyno and reopen it once activity begin.

– Christophe Gudlake
Nov 15 '18 at 18:33













@ChristopheGudlake: the question you linked is about the time it takes to start Cloud Functions, while this question is about the Realtime Database. While both are part of Firebase, they're quite different. For example: Firebase Database instances are not "spun down", and I doubt caching would cause this difference.

– Frank van Puffelen
Nov 15 '18 at 18:40





@ChristopheGudlake: the question you linked is about the time it takes to start Cloud Functions, while this question is about the Realtime Database. While both are part of Firebase, they're quite different. For example: Firebase Database instances are not "spun down", and I doubt caching would cause this difference.

– Frank van Puffelen
Nov 15 '18 at 18:40




1




1





Please update your question to include the minimal, complete code that reproduces the problem.

– Frank van Puffelen
Nov 15 '18 at 18:46





Please update your question to include the minimal, complete code that reproduces the problem.

– Frank van Puffelen
Nov 15 '18 at 18:46












1 Answer
1






active

oldest

votes


















4














The first time you interact with the Firebase Database in a client instance, the client/SDK has to do quite some things:



  1. If you're using authentication, it needs to check if the token that it has is still valid, and if not refresh it.

  2. It needs to find the server that the database is currently hosted on.

  3. It needs to establish a web socket connection.

Each of these may take multiple round trips, so even if you're a few hundred ms from the servers, it adds up.



Subsequent operations from the same client don't have to perform these steps, so are going to be much faster.



If you want to see what's actually happening, I recommend checking the Network tab of your browser. For the realtime database specifically, I recommend checking the WS/Web Socket panel of the Network tab, where you can see the actual data frames.






share|improve this answer























  • As a not skilled web developer could see benefits on watching a short video example of how doing it

    – cutiko
    Nov 19 '18 at 15:42











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325602%2ffirebase-first-write-is-slow%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














The first time you interact with the Firebase Database in a client instance, the client/SDK has to do quite some things:



  1. If you're using authentication, it needs to check if the token that it has is still valid, and if not refresh it.

  2. It needs to find the server that the database is currently hosted on.

  3. It needs to establish a web socket connection.

Each of these may take multiple round trips, so even if you're a few hundred ms from the servers, it adds up.



Subsequent operations from the same client don't have to perform these steps, so are going to be much faster.



If you want to see what's actually happening, I recommend checking the Network tab of your browser. For the realtime database specifically, I recommend checking the WS/Web Socket panel of the Network tab, where you can see the actual data frames.






share|improve this answer























  • As a not skilled web developer could see benefits on watching a short video example of how doing it

    – cutiko
    Nov 19 '18 at 15:42
















4














The first time you interact with the Firebase Database in a client instance, the client/SDK has to do quite some things:



  1. If you're using authentication, it needs to check if the token that it has is still valid, and if not refresh it.

  2. It needs to find the server that the database is currently hosted on.

  3. It needs to establish a web socket connection.

Each of these may take multiple round trips, so even if you're a few hundred ms from the servers, it adds up.



Subsequent operations from the same client don't have to perform these steps, so are going to be much faster.



If you want to see what's actually happening, I recommend checking the Network tab of your browser. For the realtime database specifically, I recommend checking the WS/Web Socket panel of the Network tab, where you can see the actual data frames.






share|improve this answer























  • As a not skilled web developer could see benefits on watching a short video example of how doing it

    – cutiko
    Nov 19 '18 at 15:42














4












4








4







The first time you interact with the Firebase Database in a client instance, the client/SDK has to do quite some things:



  1. If you're using authentication, it needs to check if the token that it has is still valid, and if not refresh it.

  2. It needs to find the server that the database is currently hosted on.

  3. It needs to establish a web socket connection.

Each of these may take multiple round trips, so even if you're a few hundred ms from the servers, it adds up.



Subsequent operations from the same client don't have to perform these steps, so are going to be much faster.



If you want to see what's actually happening, I recommend checking the Network tab of your browser. For the realtime database specifically, I recommend checking the WS/Web Socket panel of the Network tab, where you can see the actual data frames.






share|improve this answer













The first time you interact with the Firebase Database in a client instance, the client/SDK has to do quite some things:



  1. If you're using authentication, it needs to check if the token that it has is still valid, and if not refresh it.

  2. It needs to find the server that the database is currently hosted on.

  3. It needs to establish a web socket connection.

Each of these may take multiple round trips, so even if you're a few hundred ms from the servers, it adds up.



Subsequent operations from the same client don't have to perform these steps, so are going to be much faster.



If you want to see what's actually happening, I recommend checking the Network tab of your browser. For the realtime database specifically, I recommend checking the WS/Web Socket panel of the Network tab, where you can see the actual data frames.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 18:44









Frank van PuffelenFrank van Puffelen

239k29382409




239k29382409












  • As a not skilled web developer could see benefits on watching a short video example of how doing it

    – cutiko
    Nov 19 '18 at 15:42


















  • As a not skilled web developer could see benefits on watching a short video example of how doing it

    – cutiko
    Nov 19 '18 at 15:42

















As a not skilled web developer could see benefits on watching a short video example of how doing it

– cutiko
Nov 19 '18 at 15:42






As a not skilled web developer could see benefits on watching a short video example of how doing it

– cutiko
Nov 19 '18 at 15:42




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325602%2ffirebase-first-write-is-slow%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党