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

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Beyond Linguistics: Real-Time Domain Event Mapping with WebSocket and Spring Boot
  • Jakarta WebSocket Essentials: A Guide to Full-Duplex Communication in Java
  • Leveling Up My GraphQL Skills: Real-Time Subscriptions
  • Why and How To Integrate Elastic APM in Apache JMeter

Trending

  • Cookies Revisited: A Networking Solution for Third-Party Cookies
  • Failure Handling Mechanisms in Microservices and Their Importance
  • Doris: Unifying SQL Dialects for a Seamless Data Query Ecosystem
  • *You* Can Shape Trend Reports: Join DZone's Software Supply Chain Security Research
  1. DZone
  2. Coding
  3. Languages
  4. 512000 concurrent websockets with Groovy++ and Gretty

512000 concurrent websockets with Groovy++ and Gretty

By 
Alex Tkachman user avatar
Alex Tkachman
·
Jul. 29, 10 · Interview
Likes (0)
Comment
Save
Tweet
Share
56.8K Views

Join the DZone community and get the full member experience.

Join For Free

We are staying in front of new world - all major browsers either support already or plan to support in next major version HTML5 (not in scope of this article) & WebSockets (main subject of the article). In 6 to 9 months we as application developers will have in our hands extremely powerful client side tools to build new generation of the Web. But are we ready on server side? And if not, what the point in having powerful and reliable communication channel between browser and server and non-utilising it.

In this article I will talk about my expirience of handling 512K concurrent websockets using Groovy++ & Gretty.

Why 512K and not 1M?

This is very fair question and my initial goal was to handle exactly 1M concurrent websockets on one machine. It seems that due my lack of knowledge of tuning TCP/IP on Linux I was not able to achieve more. I had enough free CPU power and a lot of free memory but after 524285 open connections (always the same number) the server stopped to accept new connections.

The magical number 524285 is so close to 524288=512*1024 that I can guess (and only guess) that we deal either with some limitation of Linux setup or with something in settings of Amazon network infrastructure (where I run my tests) .

So what was the experiment about? In general it was my way to estimate (or at least to have feeling) how many (virtual) hardware units do we need if we hope to handle A LOT of concurrent users.

The server itself is very simple. It does the following:

  • On HTTP request from a client it responds with text document containing Groovy script to be executed by client.
  • It accepts and keeps websocket connections from clients and respond to every received message (just plain string) with the same string in upper case

The client program (running on separate machine) request the server for a scenario and then compile and execute it.

Why do we need this trick with sending script to client?

Truly speaking we don't. When I started writing the application I had illusion that it will simplify deployment to many clients. In fact, it did not and I had rsync all clients with my development machine after recompilation anyway.

The scenario itself is also very straight forward. Client program opens 64000 concurrent web socket connections and approximately every 25 seconds sends to the server short string (approximately 30 characters). So server need to handle around 20000 requests per second or around 600K/s traffic in and the same amount out.

Someone can argue if such structure of traffic is realistic or not. I don't want to go in to deep dispute here as it simulates very well one of applications under development in my company.

To emulate 512000 concurrent clients I used 8 machines and 1 machine was the server. All machine was of the same "m1.large" Amazon EC2 instances with 7.5GB memory and 2 virtual cores running Fedora 11. 2.5GB memory was used by Java heap (around 5K per connection but of course not including kernel structures) and total CPU utilization was under 30%

The server is written on Groovy++ using Gretty, which is lightweight server based on brilliant Netty framework and developed as part of Groovy++ standard library. More information on both can be found at Groovy++ home

Gretty is extremely lightweight and fully non-blocking event driven web server. Gretty itself is written on Groovy++ and fully utilize concurrency libabry. It is not servlet container or any other relative of JavaEE.

Right now it supports only

  • static files
  • http requests (including modern /param1/param2 REST-like requests)
  • web sockets (including long-polling emulation protocol for old browsers)

Here is essentially the whole server code. Obviously it is statically typed Groovy++ code.

        GrettyServer server = [
webContexts: [
"/" : [
public: {
get("/scenario") {
response.text = """
.............. here is client scenario code ...................
"""
}

websocket("/ws",[
onMessage: { msg ->
socket.send(msg.toUpperCase())
},

onConnect: {
socket.send("Welcome!")
},

onDisconnect: {
}
])
}
]
]
]
server.start()

I don't want to explain more than written in the code above because I really hope the code is self explaiining.

I hope it was interesting. Get Gretty and Groovy++ a try and let us know what do you think.

Till next time.

 

WebSocket Groovy (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Beyond Linguistics: Real-Time Domain Event Mapping with WebSocket and Spring Boot
  • Jakarta WebSocket Essentials: A Guide to Full-Duplex Communication in Java
  • Leveling Up My GraphQL Skills: Real-Time Subscriptions
  • Why and How To Integrate Elastic APM in Apache JMeter

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!