Re: [go-nuts] How does golang handles DNS caching

2023-06-09 Thread Slawomir Pryczek
Probably 1. You're using connection pool in gorm 2. Gorm is using golang's connection pool 3. The connection gets cached/reused while domain's IP changes (as the address is same but ip changes and the change can't be easily detected) So the solution would probably be to do a lookup in a

[go-nuts] Multiple modules, single git repo. That makes sense?

2023-06-06 Thread Slawomir Pryczek
Hi Guys, is it reasonable to publish multiple modules inside single github repo, eg. https://github.com/user/tools/a https://github.com/user/tools/b https://github.com/user/tools/c That seems to be working, but could it create any issues in the future (eg. with version control if I import 2

[go-nuts] Non-mutable / readonly slices?

2022-10-20 Thread Slawomir Pryczek
Hi Guys, writing a quick K/V caching system and have a performance related question. Will be operating on []byte, for the system to be thread safe we need to create a copy of data before each SET so we're sure that the slice which gets added to pool can't be modified. This shouldn't be

[go-nuts] Detecting JSON changes

2022-10-10 Thread Slawomir Pryczek
Hi Guys, I have 2 json files, A, B. Now i want to detect changes on the root level. File A: {"a":{"b":1, "c":2}, "x":false, ... } File B: {"a":{"b":1, "c":2}, "x":true, ... } I want to be able to see that x is different between A and B and a stayed the same. What would be the easiest

Re: [go-nuts] Structures / mutex question

2022-10-09 Thread Slawomir Pryczek
UTC+2 bse...@computer.org napisał(a): > On Sun, Oct 9, 2022 at 5:49 AM Slawomir Pryczek > wrote: > >> Hi Guys, >> wanted to see if i making correct assumptions regarding mutexes and >> structures >> >> var globalMutex sync.Mutex{} >> type abc stru

[go-nuts] Structures / mutex question

2022-10-09 Thread Slawomir Pryczek
Hi Guys, wanted to see if i making correct assumptions regarding mutexes and structures var globalMutex sync.Mutex{} type abc struct { a int b int mu sync.Mutex{} } 1. First is self explanatory, array of structures all needs to be protected by mutex x := []abc{} x = append(x,

[go-nuts] Re: Is overwriting contents of pointer field the expected behavior of json.Unmarshal?

2022-08-23 Thread Slawomir Pryczek
>From unmarshal doc: 1. To unmarshal JSON into a pointer, Unmarshal first handles the case of the JSON being the JSON literal null. In that case, Unmarshal sets the pointer to nil. Otherwise, Unmarshal unmarshals the JSON *into the value pointed at by the pointer*. *If the pointer is nil,

Re: [go-nuts] Re: Cannot instantiate T(ype) passed as pointer T?

2022-07-21 Thread Slawomir Pryczek
o > > On Thu, Jul 21, 2022 at 8:10 AM Slawomir Pryczek > wrote: > >> Actually this is better code for the question >> https://gotipplay.golang.org/p/GQlB2tyyj53 >> >> czwartek, 21 lipca 2022 o 08:08:51 UTC+2 Slawomir Pryczek napisał(a): >> >>> htt

[go-nuts] Re: Cannot instantiate T(ype) passed as pointer T?

2022-07-21 Thread Slawomir Pryczek
Actually this is better code for the question https://gotipplay.golang.org/p/GQlB2tyyj53 czwartek, 21 lipca 2022 o 08:08:51 UTC+2 Slawomir Pryczek napisał(a): > https://gotipplay.golang.org/p/ojY3RRJRJgy > > func GenericData[T DATA, T1 any]() { > } > > When DATA is interface o

[go-nuts] Cannot instantiate T(ype) passed as pointer T?

2022-07-21 Thread Slawomir Pryczek
https://gotipplay.golang.org/p/ojY3RRJRJgy func GenericData[T DATA, T1 any]() { } When DATA is interface of pointer type, so methods can modify the underlying structure... // T1 <- any type, so can instantiate but can't increment as there's no interface var tt T1 fmt.Println(tt) var d T

[go-nuts] Re: Best way of implementing generic binary search?

2022-07-20 Thread Slawomir Pryczek
source of those > existing functions is simple, this is left as an exercise for the reader :-) > > https://cs.opensource.google/go/go/+/refs/tags/go1.18.4:src/sort/search.go;l=76-103 > > On Tuesday, 19 July 2022 at 13:53:33 UTC+1 Slawomir Pryczek wrote: > >> Hi Guys, is it pos

Re: [go-nuts] Issues with time.Time

2022-07-19 Thread Slawomir Pryczek
Have you tried starting a simple thread which will update some variable every 100ms (for example), and then just get value of this variable? Using atomic functions. I believe memcached was 'caching' calls to get time this way and it won't probably be very accurate (as we don't have hard

[go-nuts] Best way of implementing generic binary search?

2022-07-19 Thread Slawomir Pryczek
Hi Guys, is it possible to implement generic, efficient binary search using generics or interfaces. So i'll have some index, and data inside single struct and then could just define a comparison function between 2 variables of same type index which will return bool. Will have 20-30 million

[go-nuts] Keeping self-referencing URLs outside of module's code

2022-07-13 Thread Slawomir Pryczek
m/slawomir-pryczek/HSServer/go/src/handler_socket2 https://github.com/slawomir-pryczek/HSServer/tree/master/go/src/handler_socket2 1. So the first idea was just to put handler_socket2 instead of the path inside go.mod. Everything was working correctly within the module, but it produced issue dur

Re: [go-nuts] Modules... why it has to be so painfull?

2021-04-08 Thread Slawomir Pryczek
Thanks for the help, so i think i get it fully now. @Nick: Sure works great if you're making a project with github modules. Having local modules is possible. But so cumbersome people would be occupied with managing files rather than writing code (if you have >20 of them). @Carla: Actually i

Re: [go-nuts] Modules... why it has to be so painfull?

2021-04-07 Thread Slawomir Pryczek
Thanks for all replies. Actually the docs are good (imo) just these solutions proposed in docs are a horror. Inside root folder of the module... so im unable to share packages between projects and code structure gets horrible, because now instead of nicely organized 2 levels of nesting i have

[go-nuts] Modules... why it has to be so painfull?

2021-04-07 Thread Slawomir Pryczek
Hey Guys, I'm struggling with the new "modules" approach and after checking several help files it seems it's inconvinient beyond belief. Basically i have an app: ...src/ /myapp/main.go package main /pool/pool.go package pool And i can't even include package pool into main without manually

Re: [go-nuts] Writing data without synchronization

2020-04-14 Thread Slawomir Pryczek
Thanks for very insightful posts. That's actually what i was interested in, as i was wondering if x86 is so advanced to invalidate caches on its own, or it's taken care by software/compiler or if that's just pure coincidence that this code actually works :) Actually as i'm doing persistent

[go-nuts] Writing data without synchronization

2020-04-14 Thread Slawomir Pryczek
Hi Guys, was wondering about some things related to multithread code. 1. If data that is accessed or changed - it needs to go into CPU cache first, and AFAIK to caches whole memory block not just this single area of memory on which we're operating. When we're doing writes without

[go-nuts] Re: Suggestions for dynamic per object lock

2020-04-05 Thread Slawomir Pryczek
I think what would work is declaring some number of mutexes, in array like 48. Then you can compute CRC32 of the token, and lock based on modulo. But yes, probably best would be to change underlying code and just partitioning the work by hash. const concurrency = 48 type concurrentChecks

[go-nuts] Re: General thoughts about new proposals

2019-07-05 Thread Slawomir Pryczek
TC+2 użytkownik jessie@rococoglobaltech.com napisał: > > is there a hope for generics like this? > > gen[A]ToStringer > gen[string].ToString() > > > > > > Noong Huwebes, Hulyo 4, 2019 ng 6:02:45 PM UTC+8, si Slawomir Pryczek ay > sumulat: >> >>

Re: [go-nuts] Re: Does the code have any concurrent problem?

2019-07-05 Thread Slawomir Pryczek
On Jul 5, 2019, at 6:42 AM, Slawomir Pryczek > wrote: > > Sure it has a race issue, because in this example you're mixing atomic > operations with mutex, when you want your code to be thread safe you need > to do access to the variable using mutex or using atomic in all cases

[go-nuts] Re: readonly []byte required

2019-07-05 Thread Slawomir Pryczek
Not sure if that's a good idea. Strings are immutable so you can pass string to function by reference, in thread safe manner. So if you pass same string to 2 threads and one of them modify it - you'll really have allocate+copy+modify so you're never touching the original thing so you can't

[go-nuts] Re: Does the code have any concurrent problem?

2019-07-05 Thread Slawomir Pryczek
Sure it has a race issue, because in this example you're mixing atomic operations with mutex, when you want your code to be thread safe you need to do access to the variable using mutex or using atomic in all cases. Because both ways work differently and are not "interchargable" so you can't

Re: [go-nuts] The "leave "if err != nil" alone?" anti-proposal

2019-07-04 Thread Slawomir Pryczek
It seems I'm hearing that a lot. If C++/Java is so great and go is so "primitive"... well what all these people are still doing in here? ;) And i'd take "primitive" if err!=nil over exceptions any time of the day, at least code is streamlined, ordered and easy maintainable this way. Then i can

[go-nuts] General thoughts about new proposals

2019-07-04 Thread Slawomir Pryczek
Following this group for couple years and I think that from some time the community is in some kind of crisis, because it seems that go1 is so good that there's a lack of some feature which will distinct go1 from go2, so everyone's trying to invent some code breaking change which will

[go-nuts] Re: `on err` alternative to `try()` has traction...?

2019-07-04 Thread Slawomir Pryczek
On one side, it's 1000x better than the other error handling specs, at least it isn't going to turn code into unreadable, fragmented mess. On the other, Aston seems to have a point, it's just replacing one-liner... and it's not that great at all because with "if" you know what it's doing

[go-nuts] Re: Interesting public commentary on Go...

2019-05-28 Thread Slawomir Pryczek
Come on, open your minds a little. Once every 5 years it doesn't hurt to learn some new, better ways of doing things. And if someone wants to write java code untill he dies, then there's a great method of doing that called "stick to java" ;) That same kind of thinking already marginalized

[go-nuts] time.Now.UnixNano() incorrect under windows7?

2019-03-22 Thread Slawomir Pryczek
Hi Guys, so i have this small go program which works fine under linux... but there's some very strange issue with getting microsecond-precision time under windows7. https://play.golang.org/p/N9F7xpx7hEr It won't run properly under playground so let me just paste here so you can see the

[go-nuts] Golang closures, counter-intuitive behaviour

2019-02-11 Thread Slawomir Pryczek
Hi Guys, When looking at this code below, you can see that the function will get LAST value of i which is incremented inside the loop, but t is somehow copied and taken inside a function so closure is created and it is bound to current value of t, so we'll have its current value in function.

[go-nuts] Re: Sort a huge slice of data around 2GB

2017-11-30 Thread Slawomir Pryczek
It should be very simple if you have additional 2G of memory. You divide the data to X parts where X is power of 2 and X needs to be less than number of cores available. Eg. for 2000MB it can be 250x8. Then you sort it in paralell using built-in sorting function and at the end you just

[go-nuts] Re: concurrent write-only to map ok?

2017-10-13 Thread Slawomir Pryczek
I think using standard sync'ed map may be bad idea for this use case (write-only access), especially taking into account that it's optimized for read access and stable keys, so each write will acquire mutex anyway. if nothing is read from that map during the threads run, it should be probably

[go-nuts] Re: Speeding up a concurrent "simple" web server

2017-10-12 Thread Slawomir Pryczek
AB is using HTTP/1.0, so it isn't able to do keepalives and it may be the case that you're really benchmarking your TCP stack, instead of your webserver... as TCP connect is probably the bottleneck here :) Not sure how it works under the hood, but enabling tcp_reuse, and tcp_recycle might

[go-nuts] Re: Implementing a custom TCP client

2017-09-21 Thread Slawomir Pryczek
can't know if message ended and you need to start processing it, or there are link issues and you should return a timeout error and maybe re-try. I have project like this on github. It's golang TCP server and php TCP client https://github.com/slawomir-pryczek/HSServer Writing client is much

[go-nuts] Re: Any ideas about slow io performance on Windows?

2017-01-04 Thread Slawomir Pryczek
Are you sure you have this issue on write, not on previous read? W dniu środa, 4 stycznia 2017 16:24:13 UTC+1 użytkownik lixi...@gmail.com napisał: > > I'm working on a TUN/TAP library on Windows. ( > https://github.com/lixin9311/water) > It's basically completed, but I have encountered IO

[go-nuts] Re: Extending objects / methods

2016-12-02 Thread Slawomir Pryczek
a >> pointer type. The unqualified type name acts as the field name. > > > type xadvanced struct { > *x > } > func(x *xadvanced)increment(){ >x.y ++ >fmt.Println(x.y) > } > > I'd advise you do read the spec at least once, it's short and

[go-nuts] Extending objects / methods

2016-12-02 Thread Slawomir Pryczek
Hi Guys, i want to make something like this type si struct { s *sync_task.Sync_task } func (this *si) Process() { ... some code here ... this.Process(); } Basically i want to extend object in another package... and this works. Now i'd just want to extend it without creating

Re: [go-nuts] Memcached replacement in GO!

2016-11-16 Thread Slawomir Pryczek
ki/ReleaseNotes1431 Basically the memcache*d* extension for PHP was buggy and that's one of the reason for writing my project ... W dniu środa, 16 listopada 2016 22:52:55 UTC+1 użytkownik Jesper Louis Andersen napisał: > > > > On Wed, Nov 16, 2016 at 3:10 PM Slawomir Pryczek

[go-nuts] Re: Memcached replacement in GO!

2016-11-16 Thread Slawomir Pryczek
company projects... > > 2016. november 16., szerda 15:10:30 UTC+1 időpontban Slawomir Pryczek a > következőt írta: >> >> Hi Guys, I wrote memcached like PHP-client and GO-server, with additional >> features, >> > > Why not https://github.com/golang/groupca

[go-nuts] Re: httputil.ReverseProxy adding 100+ ms of latency on localhost - any ideas?

2016-11-16 Thread Slawomir Pryczek
If you're on a beefy machine with recent linux, maybe MTU of loopback interface is set to 65k, setting it to default 1500 would help i think... ifconfig lo mtu 1500 up https://www.cyberciti.biz/faq/centos-rhel-redhat-fedora-debian-linux-mtu-size/ W dniu środa, 16 listopada 2016 06:01:50

[go-nuts] Memcached replacement in GO!

2016-11-16 Thread Slawomir Pryczek
ows and linux, has snapshots and rebalance and doesn't require to install anything for PHP, just the server. https://github.com/slawomir-pryczek/FlatDB/releases Why you should use it? - Much better Garbage Collection mechanism, that isn't skipping items with short TTLs like LRU, so mem