Comments (12)
Set workers to 1. If you set it to 0, facilio will roughly start #cpus / 2 or so workers, so you can't share state between workers. I haven't looked too closely at what you're doing but it seems to me that this is the most likely cause.
Zap runs forever, no matter how long you wait between requests.
from zap.
Yeah, you're sharing at least the global allocator. For multiple workers you'd need one allocator per worker process.
from zap.
I've tried one worker and many threads, with the same issue
from zap.
Ok, I am convinced, having many zap servers in production for nearly a year now, some with weeks between requests (bulks), this is an issue with your implementation. The GPA is probably not thread-safe by default, so you have to set its config option .thread_safe = true
. Set workers to 1 or else you cannot share any allocator, thread-safe or not.
from zap.
Is there a way to provide an allocator per thread?
from zap.
You could define a thread llocal optional defaulting to null and setting it if it's null, for example.
I would suggest trying with the gpa set to threadsafe first.
from zap.
I am closing this as it doesn't seem to be caused by zap. You can check out the examples and see that they run forever.
from zap.
Mind you, even if you have one allocator per thread making your allocations and deallocations within-thread, sharing state will not work between workers processes. This has nothing to do with zap or zig. It is basic common sense. If you really know what you're doing, you could use shared memory. An easier option is an external process (like a DB or a messaged hashmap, ..., redis, ...) but all that highly depends on your specific requirements
from zap.
I've set the allocator to be thread safe, set workers and threads to 1, and this issue still happens. Shouldn't this mean there's only 1 process and 1 thread accessing the data at any point in time? And why would this only be a problem after 60 seconds?
Apologies if it's still unrelated to the framework, but I can't find a reason why this would be happening, still.
from zap.
If you (actually) look at the stack trace you get, you can clearly see that the error is occurring in the pg module, which explicitly states that it maintains a connection pool (so it's likely it does some connection management which could explain the 60 seconds idle thing). So why you think the error is located in zap is beyond me.
I had a brief look at pg.zig and based on the error trace, you're getting: on release of the connection, it checks the connection and concludes that it is not idle (which according to the comments is supposed to be an error, likely caused by how you're using it) -> it tries to reconnect. However, in initDatabase(), you destroy the envMap via defer. Hence, your host string pointer is invalid, causing a segfault when the std.net code tries to figure out the TCP address for the new connection. You should dupe() the strings before destroying their underlying memory. You're welcome.
Another thing I've seen the 2nd time now, is: creating an arena for every request. I don't get why people do that. That works against the performance gains you could get from an arena. You potentially even serialize all threads on the allocator that has to create the arena. I would recommend a thread-local arena in your endpoint and reset() it when done.
I am not very amused that you probably didn't check the error trace or else you wouldn't have opened an issue here. I don't like the "it must be your bug because I can't find a reason..." attitude (when not even bothering to read the error trace) and insisting on "you fix my code becaus I can't find the bug". I would prefer if people checked the errors that point them to the source. So I would somehow have understood if you had raised an issue at pg.zig or the zig standard library, based on the stack trace.
Other people's time is valuable, too.
from zap.
Now that I got that off my chest: kudos to you for trying such a project with zig and zap. Both are relatively new and not so widespread. Oh, and unless you have super high loads, don't bother with the whole thread-local thing I like to advocate for until you're comfortable with it. Your code is likely to be fast enough. Might be thrashing memory though. But such optimizations can actually be done later, when you're happy with the overall functionality.
from zap.
I didn't intend to suggest it was solely zap's "fault", I apologize if it came off that way. I saw the error was happening inside the pg.zig library, but thought it may be because of a misunderstanding I had with threads and workers with Zap, after reading an earlier comment of yours.
Thanks for looking into this, and for your suggestions! I'll be working to study and implement what you've mentioned.
from zap.
Related Issues (20)
- Build error HOT 2
- Using zap with BTRFS on Linux 6.5.0 causes a package hash mismatch HOT 6
- Unable to build "run-hello" with current zig master (0.12.0-dev.934+a241cf90d) HOT 2
- build.zig.zon requires path field HOT 3
- zig errors on variables that need to be treated as const instead of var HOT 1
- Failure To Build: panic: unable to find artifact 'facil.io' HOT 2
- Build error using TLS HOT 5
- Re-add the -Dopenssl option to zap build HOT 3
- TLS - Random requests stalling & occasional segfault [raspi aarch64] HOT 19
- Exposé API for fetching MIME type for given extension HOT 4
- Add `std.io.Writer` and `std.io.Reader` support for `zap.SimpleRequest` HOT 4
- Represent request method as enum instead of string HOT 1
- Zap won't compile on Microsoft Windows. HOT 2
- Zig as a starter HOT 13
- Failure to compile facil.io : unable to build C object: clang exited with code 1 HOT 2
- RequestHandler doesn't work with multiple invocations where self is the same type HOT 3
- hot-code reloading or swapping HOT 1
- Add examples/tests for getHeaderCommon
- Maximum number of concurrent requests per Zap process HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zap.