Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/ansys/fluent/core/session.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Module containing class encapsulating Fluent connection."""

import atexit
from ctypes import c_int, sizeof
import itertools
import os
import threading
Expand Down Expand Up @@ -90,6 +91,17 @@ def run(self) -> None:
cb()


def _get_max_c_int_limit() -> int:
"""Get the maximum limit of a C int.

Returns
-------
int
The maximum limit of a C int
"""
return 2 ** (sizeof(c_int) * 8 - 1) - 1


class Session:
"""Encapsulates a Fluent connection.

Expand Down Expand Up @@ -176,7 +188,15 @@ def __init__(
raise ValueError(
"The port to connect to Fluent session is not provided."
)
self._channel = grpc.insecure_channel(f"{ip}:{port}")
# Same maximum message length is used in the server
max_message_length = _get_max_c_int_limit()
self._channel = grpc.insecure_channel(
f"{ip}:{port}",
options=[
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a way to set this after the channel is created. So will need to document for when the channel instance is passed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkundu1 Is there a performance penalty for setting a high value here?

Copy link
Contributor Author

@mkundu1 mkundu1 Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h-krishnan I think ideally we should replace GetStaticInfo with a streaming rpc. gRPC official website doesn't seem to have any best practice guideline regarding the message size (this is the closest thing I could find, probably the default message size is the best practice). Various thridparty blogs (like this) suggests against changing the message limit or making it too large.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkundu1 A streaming API will be difficult with a hierarchical structure. We need to figure out a way to flatten the tree. Maybe return root, its immediate children, immediate children of the children in sequence etc.

Copy link
Collaborator

@dnwillia-work dnwillia-work Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a pretty big number, what is it if you don't explicitly set the values? What's the reason to even change it? Was there an issue someone encountered?

Copy link
Contributor Author

@mkundu1 mkundu1 Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h-krishnan Could we use the SerializeToString/ParseFromString methods for protobuf messages and then split and stream as strings?

@dnwillia-work This is for the issue reported by Gitesh (in Solver API teams channel) as the latest version of Fluent's solver API is failing due to message size limit. I have here replicated the C++ code for workspace clients added for the same issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I must have missed that.

("grpc.max_send_message_length", max_message_length),
("grpc.max_receive_message_length", max_message_length),
],
)
self._metadata: List[Tuple[str, str]] = (
[("password", password)] if password else []
)
Expand Down