2

I am looking to run a grpc service on a raspberry pico. This might sound outlandish to some people, specifically those who know what the problem I'm about to introduce is, but I think I could make it work with the right technical help. The problem, as some might know, is that the Pico only has 2mb of flash storage. After micropython is installed, it's only about a meg an a half. GRPC as a python dependency takes up 10 megabytes, and it's certainly not the only dependency I need. I need to cut down the size of GRPC so that only the necessary parts of it for server hosting remain, and possibly even further to only have the parts of server hosting I specifically need.

I tried cutting it down on my own, however that proves to be a harder task than I expect. Mostly it's because there is a lot that seems unnecessary, but I'm not sure if removing it causes issues. Some background on me: I have been developing in Python for 4 years. I am by no means a master, but I am far into the level of "intermediate". I will understand most things you ask, I just need someone with more experience making packages lightweight than I currently have. Normally, I'd make things lightweight by only importing what I need to use, however that is proving harder than it should be. Micropython does not use PyPi like python's pip does. It uses something called micropython-lib. There are many ways I can use that to import a package, but it would require a json package to look at. You can read more on it here: https://docs.micropython.org/en/latest/reference/packages.html So right now what I'm looking for is a way to slice grpc down to the smallest necessary size so I can use it as a dependency, or to find a new way to import it in Micropython so I only import the necessary stuff.

Trey Davis
  • 21
  • 1
  • Hi Trey, I think that you need to define what for you the absolute minimum of the GRPC protocol means. If that is 'All' then forget about whittling down the CPython code. Possibly using the C++ client and porting that may work, but I still expect you'll need to cut out some protocol support. – Jos Verlinde Feb 25 '23 at 22:39
  • I only want to be able to use the grpc.server, the add_insecure_port function, the start() function, and wait for termination function ```python def serve() -> None: # Generic Service Stuff port = '2' server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) login_pb2_grpc.add_LoginCallServicer_to_server(LoginCall(), server) server.add_insecure_port(os.getenv("IP") + ':' + port) server.start() print("Server started, listening on " + port) server.wait_for_termination() ``` Something like this should be all I need – Trey Davis Feb 28 '23 at 00:43
  • Still, you are trying to run threadpool of 10 threads on a hardware architecture that supports 1 or 2. Also gRPC usually requires HTTP/2 for which there is little support on MCU's (yet) Long story short - There seems no easy way to solve this-but there is some progress with protocol buffers , but mostly in c / c++. If you solve this, your work will surely help others – Jos Verlinde Mar 01 '23 at 14:06

1 Answers1

0

gRPC python is wrapped on top of gRPC core, if you want to reduce the size of binary, you should consider using C++. Also, gRPC is developed as a whole library, it does provide many different APIs but under the hood they're depending on the same core functions so there won't be an easy way to only work with 'part of' gRPC python.

Xuan Wang
  • 46
  • 2