{"id":18350300,"url":"https://github.com/ollls/zio-quartz-h2","last_synced_at":"2025-04-06T10:32:11.139Z","repository":{"id":65509050,"uuid":"581927505","full_name":"ollls/zio-quartz-h2","owner":"ollls","description":"ZIO2 native, asynchronous Java NIO based implementation of http/2 packet streaming server with TLS encryption implemented as scala ZIO2 effect. Direct native translation of ZIO ZStream chunks into http2 packets (inbound and outbound).","archived":false,"fork":false,"pushed_at":"2025-04-06T03:17:15.000Z","size":8339,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T03:23:25.403Z","etag":null,"topics":["http","http-server","http2","http2-server","httpclient","scala","zio","zio-http","zio-streams","zio2"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ollls.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-24T22:39:45.000Z","updated_at":"2025-04-06T03:17:18.000Z","dependencies_parsed_at":"2023-02-10T13:01:21.264Z","dependency_job_id":"622ecf22-7707-4848-81f6-f190aba5d555","html_url":"https://github.com/ollls/zio-quartz-h2","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollls%2Fzio-quartz-h2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollls%2Fzio-quartz-h2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollls%2Fzio-quartz-h2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollls%2Fzio-quartz-h2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ollls","download_url":"https://codeload.github.com/ollls/zio-quartz-h2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247470221,"owners_count":20944143,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","http-server","http2","http2-server","httpclient","scala","zio","zio-http","zio-streams","zio2"],"created_at":"2024-11-05T21:26:00.682Z","updated_at":"2025-04-06T10:32:11.132Z","avatar_url":"https://github.com/ollls.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"quartz-h2.jpeg\" width=\"84\" title=\"quartz-h2\"/\u003e\n\n[![Generic badge](https://img.shields.io/badge/zio--quartz--h2-0.7-blue)](https://repo1.maven.org/maven2/io/github/ollls/zio-quartz-h2_3/0.7)\n\nhttps://ollls.github.io/zio-quartz-h2-doc/\n\n# Asynchronous HTTP/2 TLS packet streaming server/client with multiple I/O options\nIt now supports HTTP/1.1 and IO-Uring on Linux platforms\n\nZIO2 native, asynchronous implementation of HTTP/2 packet streaming server with TLS encryption implemented as scala ZIO2 effect with ALPN h2 tag. Direct native translation of ZIO ZStream chunks into HTTP/2 packets (inbound and outbound). Tested and optimized to produce highest possible TPS. Server supports HTTP multipart with ZStream interface along with automatic file saving for file based multipart uploads.\n\n## I/O Implementation Options\n\n- **Java NIO**: Cross-platform compatibility with high performance\n- **Linux IO-Uring**: Native Linux kernel I/O for maximum performance (new in v0.6.0)\n- **Synchronous Mode**: Traditional blocking Java sockets for specific use cases\n\n``` \nlibraryDependencies += \"io.github.ollls\" %% \"zio-quartz-h2\" % \"0.7\"\n```\n\nto run example from zio-quartz-h2 code base directly\n\n```\nsbt IO/run\n```\n\n## Using IO-Uring on Linux\n\nTo utilize the new IO-Uring implementation on Linux platforms:\n\n```scala\n// Configure the number of IO-Uring instances\nval NUMBER_OF_RING_INSTANCES = 1\n\n// Recommended ZIO Runtime configuration for IO-Uring\noverride val bootstrap = zio.Runtime.removeDefaultLoggers ++ SLF4J.slf4j ++ zio.Runtime.setExecutor(\n  zio.Executor.fromJavaExecutor(Executors.newWorkStealingPool(Runtime.getRuntime().availableProcessors() - NUMBER_OF_RING_INSTANCES))\n) ++ zio.Runtime.setBlockingExecutor(zio.Executor.fromJavaExecutor(Executors.newCachedThreadPool()))\n\n// Start server with IO-Uring\nexitCode \u003c- new QuartzH2Server(\n  \"localhost\",\n  8443,\n  16000,\n  ctx,\n  onConnect = onConnect,\n  onDisconnect = onDisconnect\n).startIO_linuxOnly(NUMBER_OF_RING_INSTANCES, R, filter)\n```\n\nFor a complete working example of IO-Uring implementation, refer to the [examples/IOU/src/main/scala/Run.scala](https://github.com/ollls/zio-quartz-h2/blob/master/examples/IOU/src/main/scala/Run.scala) file in the repository.\n\nFor a complete working example of Java NIO implementation, refer to the [examples/IO/src/main/scala/Run.scala](https://github.com/ollls/zio-quartz-h2/blob/master/examples/IO/src/main/scala/Run.scala) file in the repository.\n\n\n### Logging.\n\nUse .../src/main/resources/logback-test.xml to tailor to your specific requirements.\n\nAlso you may use options to control logging level.\n```\nsbt \"run --debug\"\nsbt \"run --error\"\nsbt \"run --off\"\n```\n\n## Version Information\n\n- **Current Version**: 0.6.0\n- **Major Changes**: Added Linux IO-Uring support, upgraded to Scala 3.3, updated logback-classic to 1.5.17\n\n### Template Examples\n* Template project with use cases, `sbt run`:\u003cbr\u003ehttps://github.com/ollls/zio-qh2-examples\n* Use cases:\u003cbr\u003e https://github.com/ollls/zio-quartz-h2/blob/master/examples/IO/src/main/scala/Run.scala, to run: `sbt IO/run`\n* To debug: switch to \"debug\" or 'trace\" in logback-test.xml, **use \"off\" or \"error\" for performace tests with wrk and h2load**. \n* You may look at the quartz-h2 CATS port https://github.com/ollls/quartz-h2\n\u003cbr\u003e\n\n## Features\n\n- HTTP/2 with TLS encryption and ALPN h2 tag\n- HTTP/1.1 support, chunked encoding only\n- Multiple I/O implementations (Java NIO and Linux IO-Uring)\n- ZIO2 native implementation\n- High-performance packet streaming\n- HTTP multipart support with ZStream interface\n- Automatic file saving for multipart uploads\n- Web filter support\n- Configurable logging\n- **Reactive Flow Control**: Advanced backpressure mechanisms that integrate with ZStream\n- **End-to-End Backpressure**: Complete backpressure chain from network socket to application logic\n- **Threshold-Based Window Updates**: Optimized HTTP/2 flow control with intelligent window management\n\n### Standard support for ZIO Environment.\n\n```scala\n\ndef run =\n    val env = ZLayer.fromZIO( ZIO.succeed( \"Hello ZIO World!\") )\n    (for {\n      ctx \u003c- QuartzH2Server.buildSSLContext(\"TLS\", \"keystore.jks\", \"password\")\n      exitCode \u003c- new QuartzH2Server(\"localhost\", 8443, 16000, ctx).startIO(R, filter, sync = false)\n\n    } yield (exitCode)).provideSomeLayer( env )\n\n```\n\n### Webfilter support with Either[Response, Request]. Provide filter as a parameter QuartzH2Server()\n\n```scala\n\nval filter: WebFilter = (request: Request) =\u003e\n  ZIO.attempt(\n    Either.cond(\n     !request.uri.getPath().startsWith(\"/private\"),\n     request.hdr(\"test_tid\" -\u003e \"ABC123Z9292827\"),\n     Response.Error(StatusCode.Forbidden).asText(\"Denied: \" + request.uri.getPath())\n    )\n )    \n```\n\n```scala\n\nexitCode \u003c- new QuartzH2Server(\"localhost\", 8443, 16000, ctx).startIO(R, filter, sync = false)\n\n```\n\n### File retrieval.\n\n```scala \n\ncase GET -\u003e Root / StringVar(file) =\u003e\n      val FOLDER_PATH = \"/Users/user000/web_root/\"\n      val FILE = s\"$file\"\n      val BLOCK_SIZE = 16000\n      for {\n        jpath \u003c- ZIO.attempt(new java.io.File(FOLDER_PATH + FILE))\n        present \u003c- ZIO.attempt(jpath.exists())\n        _ \u003c- ZIO.fail(new java.io.FileNotFoundException).when(present == false)\n\n      } yield (Response\n        .Ok()\n        .asStream(ZStream.fromFile( jpath, BLOCK_SIZE ))\n        .contentType(ContentType.contentTypeFromFileName(FILE)))\n\n```\n\n### File upload ( smart http2 flow control implemented if disk saving speed cannot keep up with inbound network data.) \n\n```scala \n\n case req @ POST -\u003e Root / \"upload\" / StringVar(file) =\u003e\n      val FOLDER_PATH = \"/Users/user000/web_root/\"\n      val FILE = s\"$file\"\n      for {\n        jpath \u003c- ZIO.attempt(new java.io.File(FOLDER_PATH + FILE))\n        u \u003c- req.stream.run(ZSink.fromFile(jpath))\n      } yield (Response.Ok().asText(\"OK\"))\n        \n```        \n### HTTP Multipart file upload.\n\n```scala\n\n case req @ POST -\u003e Root / \"mpart\" =\u003e\n      MultiPart.writeAll(req, \"/Users/user000/tmp1/\" ) *\u003e ZIO.succeed(Response.Ok())\n\n```\n\n### How to send data in separate H2 packets of various size\n\n```scala \n\n    case GET -\u003e Root / \"example\" =\u003e\n      val ts = ZStream.fromChunks(Chunk.fromArray(\"Block1\\n\".getBytes()), Chunk.fromArray(\"Block22\\n\".getBytes()))\n      ZIO.attempt(Response.Ok().asStream(ts))\n      \n````      \n\n### How to run h2spec.\n\n1. Start server with \"sbt IO/run\"\u003cbr\u003e\n2. ./h2spec http2 -h localhost -p 8443 -t -k\u003cbr\u003e\n\nYou should get:\n```\nFinished in 2.1959 seconds\n94 tests, 94 passed, 0 skipped, 0 failed\u003cbr\u003e\n```\n### Performance test with h2load.\n\n```\nh2load -D10 -c68 -m30 -t2 https://localhost:8443/test\n\n...\n\nfinished in 10.01s, 65292.20 req/s, 637.89KB/s\nrequests: 652922 total, 654452 started, 652922 done, 652922 succeeded, 0 failed, 0 errored, 0 timeout\nstatus codes: 652922 2xx, 0 3xx, 0 4xx, 0 5xx\ntraffic: 6.23MB (6531974) total, 637.62KB (652922) headers (space savings 90.00%), 0B (0) data\n                     min         max         mean         sd        +/- sd\ntime for request:      231us    144.82ms     19.31ms     10.02ms    73.06%\ntime for connect:     7.39ms    860.22ms    385.69ms    278.36ms    54.90%\ntime to 1st byte:     9.10ms    875.77ms    398.01ms    282.96ms    54.90%\nreq/s           :       0.00     1489.99      959.99      563.28    75.00%\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Follls%2Fzio-quartz-h2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Follls%2Fzio-quartz-h2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Follls%2Fzio-quartz-h2/lists"}