Verbindungspools konfigurieren
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Verbindungspools konfigurieren
Weitere Informationen
Eine ausführliche Dokumentation, die dieses Codebeispiel enthält, finden Sie hier:
Codebeispiel
Nächste Schritte
Wenn Sie nach Codebeispielen für andere Google Cloud -Produkte suchen und filtern möchten, können Sie den Google Cloud -Beispielbrowser verwenden.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis content provides code examples in C++, Go, and Java demonstrating how to configure connection pools for Google Cloud Bigtable.\u003c/p\u003e\n"],["\u003cp\u003eConnection pool size can be set to optimize the number of channels used for communication, with a size of 10 being used in the provided examples.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples show how to set the pool size when creating a Bigtable client using each respective language.\u003c/p\u003e\n"],["\u003cp\u003eSetting up Application Default Credentials (ADC) is necessary to authenticate with Bigtable, and instructions to do so are referenced.\u003c/p\u003e\n"],["\u003cp\u003eFor more resources on managing connection pools and installing client libraries, relevant links to the Bigtable documentation and sample browser are provided.\u003c/p\u003e\n"]]],[],null,["Configure connection pools\n\nExplore further\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Configure connection pools](/bigtable/docs/configure-connection-pools)\n\nCode sample \n\nC++\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n namespace cbt = ::google::cloud::bigtable;\n namespace gc = ::google::cloud;\n [](std::string const& project_id, std::string const& instance_id,\n std::string const& table_id) {\n auto constexpr kPoolSize = 10;\n auto options = gc::Options{}.set\u003cgc::GrpcNumChannelsOption\u003e(kPoolSize);\n cbt::Table table(cbt::MakeDataConnection(options),\n cbt::TableResource(project_id, instance_id, table_id));\n std::cout \u003c\u003c \"Connected with channel pool size of \" \u003c\u003c kPoolSize \u003c\u003c \"\\n\";\n }\n\nGo\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \t\"cloud.google.com/go/bigtable\"\n \t\"google.golang.org/api/option\"\n )\n\n func configureConnectionPool(w io.Writer, projectID, instanceID string) error {\n \t// projectID := \"my-project-id\"\n \t// instanceID := \"my-instance-id\"\n \tctx := context.Background()\n\n \t// Set up Bigtable data operations client.\n \tpoolSize := 10\n \tclient, err := bigtable.https://cloud.google.com/go/docs/reference/cloud.google.com/go/bigtable/latest/index.html#cloud_google_com_go_bigtable_Client_NewClient(ctx, projectID, instanceID, option.WithGRPCConnectionPool(poolSize))\n \tdefer client.Close()\n\n \tif err != nil {\n \t\treturn fmt.Errorf(\"bigtable.NewClient: %w\", err)\n \t}\n\n \tfmt.Fprintf(w, \"Connected with pool size of %d\", poolSize)\n\n \treturn nil\n }\n\nJava\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n import com.google.api.gax.grpc.https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.html;\n import com.google.cloud.bigtable.data.v2.https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataClient.html;\n import com.google.cloud.bigtable.data.v2.https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.html;\n import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings;\n import java.io.IOException;\n\n public class ConfigureConnectionPool {\n\n public static void configureConnectionPool(String projectId, String instanceId) {\n // String projectId = \"my-project-id\";\n // String instanceId = \"my-instance-id\";\n\n https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.html.Builder settingsBuilder =\n https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.html.newBuilder().https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder.html#com_google_cloud_bigtable_data_v2_BigtableDataSettings_Builder_setProjectId_java_lang_String_(projectId).https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder.html#com_google_cloud_bigtable_data_v2_BigtableDataSettings_Builder_setInstanceId_java_lang_String_(instanceId);\n\n settingsBuilder\n .https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder.html#com_google_cloud_bigtable_data_v2_BigtableDataSettings_Builder_stubSettings__()\n .setTransportChannelProvider(\n EnhancedBigtableStubSettings.defaultGrpcTransportProviderBuilder()\n .https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.Builder.html#com_google_api_gax_grpc_InstantiatingGrpcChannelProvider_Builder_setPoolSize_int_(10)\n .build());\n\n https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.html settings = settingsBuilder.build();\n try (https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataClient.html dataClient = https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataClient.html.create(settings)) {\n https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.html provider =\n (https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.html)\n settings.https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.html#com_google_cloud_bigtable_data_v2_BigtableDataSettings_getStubSettings__().getTransportChannelProvider();\n\n int poolSize = provider.https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.html#com_google_api_gax_grpc_InstantiatingGrpcChannelProvider_toBuilder__().https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.Builder.html#com_google_api_gax_grpc_InstantiatingGrpcChannelProvider_Builder_getPoolSize__();\n\n System.out.println(String.format(\"Connected with pool size of %d\", poolSize));\n } catch (IOException e) {\n System.out.println(\"Error during ConfigureConnectionPool: \\n\" + e.toString());\n }\n }\n }\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=bigtable)."]]