Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate translate = TranslateOptions.newBuilder().setApiKey(MY_API_KEY).build().getService(); Sometimes Takes Very Long time #603

Closed
grantespo opened this issue Apr 8, 2017 · 10 comments

Comments

@grantespo
Copy link

grantespo commented Apr 8, 2017

In my Main Activity, I initialize the Translate variable. If you look at the logs: I track when the initialization starts and when it finishes. Most of the time it initializes quick. But 1/5 times it takes up to 30 seconds to 3 minutes (UNACCEPTABLE).

    AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {

        @Override
        public void onPostExecute (Void aVoid) {

            Log.i("APP", "finished");

        }

        @Override
        protected Void doInBackground(Void... voids) {
            Log.i("APP", "start");
          Translate  translate = TranslateOptions.newBuilder().setApiKey("XXXXX-ZZZZZ").build().getService();
            return null;
        }

    };
    asyncTask.execute();

I also have the latest versions in gradle:

   compile ('com.google.cloud:google-cloud-translate:0.11.0-alpha')
  compile ('com.google.apis:google-api-services-translate:v2-rev49-1.22.0')
@grantespo grantespo changed the title translate2 = TranslateOptions.newBuilder().setApiKey(MY_API_KEY).build().getService(); Sometimes Takes Very Long time Translate translate = TranslateOptions.newBuilder().setApiKey(MY_API_KEY).build().getService(); Sometimes Takes Very Long time Apr 8, 2017
@lesv
Copy link
Contributor

lesv commented Apr 22, 2017

Totally agree with you. 3 minutes is unacceptable. Shouldn't you create the Translate object only once at startup?

Where are you running this?

I'll try to get you an answer, but this really should be a question for StackOverflow

NOTE - You might wish to invalidate your ApiKey, and just change to xxxx when posting in the future.

@lesv
Copy link
Contributor

lesv commented Apr 22, 2017

Ah, found your SO Question and that your running on Android, so my comment is moot, though you might still wish to run a cloud service that initializates Translate and just request from that.

@lesv
Copy link
Contributor

lesv commented Apr 22, 2017

I'm sorry to say that if you look at the bottom of google-cloud-java, you note that "Android is not supported" for these libraries currently.

@lesv
Copy link
Contributor

lesv commented Apr 22, 2017

You might wish to use the REST interface instead.

@lesv lesv closed this as completed Apr 22, 2017
@grantespo
Copy link
Author

How is it not supported on Android? I am using it in my production app right now and it translates messages good. It just takes a long time to initialize sometimes.

I am initializing it in my Application class.

@lesv
Copy link
Contributor

lesv commented Apr 22, 2017

The engineering team hasn't had a chance to validate or optimize the library on Android so they asked that a warning be posted. I'm a bit surprised that it works at all -- there are files you might wish to change for Android such as excluding netty-borring-ssl-native and following the suggestion for TLS on Android.

You might also wish to look at these examples. But as I said, we aren't testing on Android currently, so you are on your own. My apologies.

That said, you will likely find that implementing with REST will produce a much smaller app and a much faster one.

@GoogleCloudPlatform/gcloud FYI

@grantespo
Copy link
Author

Will the team resume work? Is this library likely to stop working soon? Is it critical for me to transfer to REST API because I am actually happy with the performance right now.

@lesv
Copy link
Contributor

lesv commented Apr 22, 2017

There aren't any plans to break things. (and you can stay on a working version anyway) It's just surprising that it works on Android at all.

REST might be the way to fix your 20% startup issues. (but I don't know the root cause). That's why I suggested it. Otherwise, it's really up to you.

@grantespo
Copy link
Author

I appreciate your replies.

My issue is never present the first time somebody opens my app. However, whenever somebody exits my app by pushing the back button, I call System.exit(0); then, after I immediately open the app again 50% of the time Translation API Initialization either delays or starts up immediately. I think the System.exit(0); plays a factor.

@lesv
Copy link
Contributor

lesv commented Apr 23, 2017

Ah - it sounds like the shutdown threads are left in a strange state. Take a look at this which suggests System.exit() isn't the best solution.

I haven't written an Android app in several years, so I'm probably not thinking through everything. In the past, I've found this book to be invaluable.

this.finish() may be a better choice. Again, the library hasn't been tested on Android, so you are on your own here. -- hope this helps.

minherz pushed a commit that referenced this issue Nov 9, 2022
minherz pushed a commit that referenced this issue Nov 10, 2022
minherz pushed a commit that referenced this issue Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants