Firebase admin sdk java performance issue

Viewed 157

I'm having slow performance issues with Firebase realtime database while adding the data. Firebase app here is the singleton object. I'm using the above to save data in the Firebase where I'm facing the performance issue. The first request is taking around 14 seconds to save. The following immediate requests are taking milliseconds. Am I experiencing a cold start here? Can someone help me out? I'm new to Firebase.

    @Bean
    public FirebaseApp firebaseApp() {
        FileInputStream serviceAccount;
        try {
            Resource resource = new ClassPathResource("nextlearningplatform-firebase-adminsdk-1o5of-09005f0e08.json");
            File file = resource.getFile();
            serviceAccount = new FileInputStream(file);
            FirebaseOptions  options = new FirebaseOptions.Builder()
                    .setCredentials(GoogleCredentials.fromStream(serviceAccount))
                    .setProjectId("nextlearningplatform")
                    .setStorageBucket("nextlearningplatform.appspot.com")
                    .build();
             FirebaseApp app = FirebaseApp.initializeApp(options);
             return app;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    
 String url = "databaseName";
 String refpath = "referencePath";
 DatabaseReference ref = 
 FirebaseDatabase.getInstance(firebaseApp,"https://"+url+".firebaseio.com)
.getReference(refpath);
 ref.child("streams").setValueAsync(firebaseDTO);

0 Answers
Related