DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • How to Enhance the Performance of .NET Core Applications for Large Responses
  • Automatic 1111: Custom Sketch-to-Image API
  • On-Demand-Schedulers With MuleSoft CloudHub APIs
  • Ultimate Guide to FaceIO

Trending

  • Simpler Data Transfer Objects With Java Records
  • AI Agents: A New Era for Integration Professionals
  • Implementing Explainable AI in CRM Using Stream Processing
  • How to Introduce a New API Quickly Using Micronaut

Determine Payload Size Using Nginx

We wanted to evaluate which protocol is suitable for our micro-service architecture as our payload size was getting increased quite considerably.

By 
Milind Deobhankar user avatar
Milind Deobhankar
·
Jul. 20, 20 · Analysis
Likes (2)
Comment
Save
Tweet
Share
6.5K Views

Join the DZone community and get the full member experience.

Join For Free

Nowadays any application is API based or distributed where one request is not just served by one application but a series of applications either parallel or serial. Application talks to each other using various protocols like REST, RPC, WebSocket, and the payload formats varies from JSON / XML / Binary / propriety. 

Recently we wanted to evaluate which protocol is suitable for our micro-service architecture as our payload size was getting increased quite considerably. To determine that we want to know maximum payload size and minimum, as our payload size is directly proportional to items selected. 

Our tech stack is open source and our deployment is containerized polyglot micro-service architecture using docker swarm. Some of the services are using REST, and some are using gRPC (protobuff) and the payload is JSON, JSON+gzip, and binary. So to determine the payload size, we need a common proxy that will able to serve HTTP request and gRPC request. After looking at all tools, we decided to front our swarm service using Nginx so that we can capture payload size and uniquely logs each service request. 

overlay network

Let’s start how to configure Nginx for the same. The first challenge is to serve all types of the payload so we are going to use stream rather than HTTP. For each service, we are going to dedicate the incoming ports and upstream ports. There will be separate log files for each service as Nginx can only log the upstream IP address. If we combine the logs of all service, it will be difficult to identify based on IP as these will be container IP which can change if we restart or scale.

Nginx configuration:

Plain Text
 




xxxxxxxxxx
1
25


 
1
worker_processes  1;
2
events {
3
    worker_connections  1024;
4
}
5

          
6
stream {
7
    upstream stream_backend_service1 {
8
        server swarm_service1:8080;
9
    }
10
    upstream stream_backend_service2 {
11
        server swarm_service2:9090;
12
    }   
13
    log_format combined '$upstream_addr = Request Payload Size - $upstream_bytes_sent                           Response Payload Size - $upstream_bytes_received';
14
    
15
    server {
16
        listen            127.0.0.1:8090;
17
        proxy_pass        stream_backend_service1;
18
        access_log  logs/payloadsize.log  combined;
19
    }
20
    server {
21
        listen            127.0.0.1:8091;
22
        proxy_pass        stream_backend_service2;
23
    access_log  logs/payloadsize_sever2.log  combined;
24
    }
25
}



If you go to the respective logs following will get printed.

Plain Text
xxxxxxxxxx
1
 
1
payloadsize.log
2
10.0.1.2:8080 = Request Payload Size – 377 Response Payload Size – 180
3
payloadsize_server2.log
4
10.0.1.3:9090 = Request Payload Size – 837 Response Payload Size – 282


Our swarm_service1 is using REST over HTTP and swarm_service2 is using gRPC.
Hope this will help others who want to discover Nginx benefits.

Happy coding.

Payload (computing)

Published at DZone with permission of Milind Deobhankar. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Enhance the Performance of .NET Core Applications for Large Responses
  • Automatic 1111: Custom Sketch-to-Image API
  • On-Demand-Schedulers With MuleSoft CloudHub APIs
  • Ultimate Guide to FaceIO

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!